I use FMDB to save some data,but always can't save success,these are my method,
-(void)viewWillAppear:(BOOL)animated{
NSString *doc=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *fileName=[doc stringByAppendingPathComponent:@"tvShow.sqlite"];
FMDatabase *db=[FMDatabase databaseWithPath:fileName];
if ([db open]) {
BOOL result=[db executeUpdate:@"CREATE TABLE IF NOT EXISTS t_show (id integer PRIMARY KEY AUTOINCREMENT, name text NOT NULL, introduction text NOT NULL, lastDate text NOT NULL, allDate text NOT NULL);"];
if (result) {
NSLog(@"Succeed");
[self.db executeUpdate:@"INSERT INTO t_show (name,introduction,lastDate,allDate) VALUES (%@,%@,%@,%@,)",@"1111",@"1111",@"",@""];
FMResultSet *resultSet = [self.db executeQuery:@"SELECT * FROM t_show"];
while ([resultSet next]) {
int ID = [resultSet intForColumn:@"id"];
NSString *name = [resultSet stringForColumn:@"name"];
NSString *introduction = [resultSet stringForColumn:@"introduction"];
NSString *lastDate = [resultSet stringForColumn:@"lastDate"];
NSLog(@"%d %@ %@ %@", ID, name, introduction,lastDate);
[self.nameArray addObject:name];
}
}else
{
NSLog(@"Faild");
}
}
[self query];
self.db=db;
}
the Xcode show me like these enter image description here
PS:『创表成功』means create list succeed
Thank you very much.
Aucun commentaire:
Enregistrer un commentaire