1. Case briefA simple encapsulation of the sqlite operation, the operation of the data table operation into the object, and through the UI interface to complete the user table to add, delete, change, check, run the interface as shown in a
2. Project Engineering Catalogue
Usermodel class for the user object model, and the database table field one by one corresponds to the Basedb class for the simple encapsulation of SQLite, abstract the database operation of three methods, the specific content see http://blog.csdn.net/whzhaochao/article/ details/38865535 Bowen UserDB inherited in Basedb, mainly to complete the Usermodel object of the increase, deletion, change, check, and its contents are as follows 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;//Modify 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 primary Key,password text, useremail text) "; [Self createtable:sql databasename:dbname]; }-(BOOL) DeleteUser: (usermodel*) Usermodel dbName: (nsstring*) dbname{nsstring *[email protected] "Delete from us er where 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 (US Ername,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 a display full item code download for users to display all user lists Addviewcontroller for adding and modifying the user interface http://download.csdn.net/detail/whzhaochao/7829829
IOS SQLite user Interface Additions and deletions change case