常见的几种数据库
什么是数据库
SQL语句
+ (NSArray *)searchAllNovel
{
sqlite3 *dbPoint = [DB openDB];
//第二步,获得数据库指针的替身
sqlite3_stmt *stmt = nil;
//第三步:sql语句
NSString *sqlStr = @"select novel_id,novel_name,novel_author,novel_date,novel_paice from novel";
//检查数据库语句是否正确,并将替身中填写查找的内容
int result = sqlite3_prepare_v2(dbPoint, [sqlStr UTF8String], -1, &stmt, nil);
NSMutableArray *array = [[[NSMutableArray alloc] init] autorelease];
if (result == SQLITE_OK) {
//获得每一条查找到的数据的内容
while (sqlite3_step(stmt) == SQLITE_ROW) {
int nid = sqlite3_column_int(stmt, 0);
const unsigned char *name = sqlite3_column_text(stmt, 1);
const unsigned char *author = sqlite3_column_text(stmt, 2);
const unsigned char *date = sqlite3_column_text(stmt, 3);
double price = sqlite3_column_double(stmt, 4);
NSString *novelName = [NSString stringWithUTF8String:(const char *)name];
NSString *novelauther = [NSString stringWithUTF8String:(const char *)author];
NSString *novelDate = [NSString stringWithUTF8String:(const char *)date];
NovelModel *model = [NovelModel novelModelWithNovel_id:nid name:novelName auther:novelauther date:novelDate price:price];
[array addObject:model];
}
}
sqlite3_finalize(stmt);
return array;
}