if ([self.db open]) { NSString *sqlCreateTable = @"CREATE TABLE IF NOT EXISTS Question (UUID TEXT PRIMARY KEY, type TEXT, bigQuetionIndex INTEGER, smallQuetionIndex INTEGER, state TEXT, time INTEGER, elapsedTime INTEGER, studentAnswer TEXT, answer TEXT, studentGrade INTEGER, grade INTEGER, content TEXT, examPaperUUID TEXT)"; BOOL res = [self.db executeStatements:sqlCreateTable]; if (!res) { CFLog(@"error when creating db table"); } else { CFLog(@"success to creating db table"); } [self.db close]; }
增加数据
1 2 3 4 5 6 7 8 9 10 11 12
if ([self.db open]) { NSString *sql = @"INSERT INTO t_entity (UUID, title) VALUES (?, ?)"; BOOL res = [self.db executeUpdate:sql, entity.UUID, entity.title]; if (!res) { CFLog(@"error when insert db table"); } else { CFLog(@"success to insert db table"); } [self.db close]; }
删除数据
1 2 3 4 5 6 7 8 9 10 11
if ([self.db open]) { NSString *sql = @"DELETE FROM t_entity WHERE UUID = ?"; BOOL res = [self.db executeUpdate:sql, UUID]; if (!res) { CFLog(@"error when DELETE db table"); } else { CFLog(@"success to DELETE db table"); } [self.db close]; }
更新数据
1 2 3 4 5 6 7 8 9 10 11 12
if ([self.db open]) { NSString *sql = @"UPDATE t_entity SET title = ?"; BOOL res = [self.db executeUpdate:sql, examPaper.title, examPaper.UUID]; if (!res) { CFLog(@"error when UPDATE db table"); } else { CFLog(@"success to UPDATE db table"); } [self.db close]; }