else
{if([dbopen])
{
NSLog(@"数据库创建成功并打开");
FMResultSet* set = [executeQuery:[NSStringstringWithFormat:@"select count(*) from sqlite_master where type ='table' and name = '%@'"kUserTableName]];
[setnext];
NSIntegercount = [setintForColumnIndex:0];
BOOLexistTable = count;
if(existTable)
{
(@"数据表已存在,请重新添加表" return;}
else
*createtable=@"CREATE TABLE user (uid INTEGER PRIMARY KEY AUTOINCREMENTNOT NULL,name text,interest text)";
[executeUpdate:createtable];}
}
//插入数据
void)insertdata:(NSArray*)arguments
[executeUpdate:@"INSERT INTO user(name,interest) VALUES(?,?) "withArgumentsInArray:arguments];
}
}
//查询所有数据
-(NSMutableArray*)selectall
NSMutableArray*array=[[NSMutableArrayalloc]initWithCapacity:100
*sql=@"select * from user where name=? or interest=?" FMResultSet*qureyresult=[executeQuery:sql,@"333",27)">@"111"];
while([qureyresultnext])
{
NSIntegeruid=[qureyresultintForColumn:@"uid"];
NSString*name=[qureyresultstringForColumn:@"name"];
NSString*inserest=[qureyresult@H_161_404@@"interest"];
NSMutableDictionary*dic=[[NSMutableDictionaryinit
[dicsetValue:[stringWithFormat:@"%d",uid]forKey:@"keyuid"];
@H_301_455@setValue:name@"keyname"];
@H_301_455@setValue:inserest@"keyinserest"];
[arrayaddObject:dic];
}
returnarray;
//修改数据
void)mergerwithname:(NSString*)name withinterest:(NSString*)interestanduid:(NSNumber*)uid
:@"UPDATE user SET name=?,interest=? WHERE uid=? " //删除数据
void)deletedata
:@"deletefrom user where name=?":@"%@" 数据库基本就是更新和查询
除了select,dbexecuteQuery:;其他都是更新executeUpdate:传参数时可用dbexecuteUpdate:withArgumentsInArray: