1. Brief introduction of the caseThe SQLite operation is simply encapsulated, the operation of the data table will be transformed into the manipulation of the object, and through the UI interface completes the user table to add, delete, change, check, the execution interface for example, as seen in a
2. Projects project folder
The Usermodel class is the user object model. The corresponding Basedb class for field one by one in the database table is a simple encapsulation of sqlite, abstracting out three methods for database operations. Read more about http://blog.csdn.net/whzhaochao/article/details/38865535 Bowen UserDB inherited from Basedb. Mainly finished Usermodel object of the increase, deletion, change, check, its contents such as the following UserDB.h
userdb.h// sqlitedemo//// Created by Carrie on 14-8-27.// Copyright (c) 2014 Carrie. All rights reserved.//#import "BaseDB.h" #import "UserModel.h" @interface userdb:basedb{ }//single case + (ID) shareuserdb;// Create user table-(void) Creattablewithdatabasename: (nsstring*) dbname;//Add a usermodel-(BOOL) AddUser: (usermodel*) Usermodel DbName: (nsstring*) dbname;//change a usermodel-(BOOL) UpdateUser: (usermodel*) Usermodel dbName: (nsstring*) dbname;// Query All-(nsarray*) Findalluser: (nsstring*) dbname;//Delete an Object-(BOOL) DeleteUser: (usermodel*) Usermodel dbName: (nsstring*) DbName; @end
Userdb.m
userdb.m//sqlitedemo////Created by Carrie on 14-8-27.//Copyright (c) 2014 Carrie. All rights reserved.//#import "UserDB.h" @implementation userdbstatic UserDB * db;+ (ID) shareuserdb{if (Db==nil) { db= [[UserDB alloc] init]; } return DB;} -(void) Creattablewithdatabasename: (nsstring*) dbname{nsstring *[email protected] "CREATE table User (UserName text prim ary Key,password text, useremail text) "; [Self createtable:sql databasename:dbname]; }-(BOOL) DeleteUser: (usermodel*) Usermodel dbName: (nsstring*) dbname{nsstring *[email protected] "Delete from user wh ere userName =? "; Nsarray *[email protected][Usermodel.username]; return [self execsql:sql parmas:params databasename:dbname];} -(BOOL) AddUser: (Usermodel *) Usermodel dbName: (NSString *) dbname{nsstring *[email protected] "insert into user (UserName , Password,useremail) VALUES (?,?,?) "; Nsarray *[email protected][usermodel.username,usermodel.password,usermodel.useremail]; return [self execsql:sql parmas:params databasename:dbname];} -(nsarray*) Findalluser: (NSString *) dbname{nsstring *[email protected] "select Username,password,useremail from User "; Nsarray *result= [self selectsql:sql parmas:nil databasename:dbname]; Nsmutablearray *users=[nsmutablearray Array]; For (nsdictionary *dic in result) {Usermodel *user=[[usermodel alloc] init]; User.username=[dic objectforkey:@ "UserName"]; User.password=[dic objectforkey:@ "PassWord"]; User.useremail=[dic objectforkey:@ "UserEmail"]; [Users Addobject:user]; } return users; }-(BOOL) UpdateUser: (Usermodel *) Usermodel dbName: (NSString *) dbname{nsstring *[email protected] "Update user set Username=?
, password=?,useremail=? where username=? "; Nsarray *[email Protected][usermodel.username,usermodel.password,usermodel.useremail,usermodel.username]; return [self execsql:sql parmas:params databasename:dbname]; } @end
Mainviewcontroller is the display full project code download for users to display the full list of users addviewcontroller for adding and changing the user interface http://download.csdn.net/detail/whzhaochao/7829829
IOS SQLite user Interface Additions and deletions change case