// // CCSqlite3.m // CCFC // // Created by xichen on 11-12-18. // Copyright 2011 ccteam. All rights reserved. // #import "CCSqlite3.h" @implementation CCSqlite3 @synthesize delegate = _delegate; @synthesize statement = _statement; - (id)initWithSqliteDBFullPath:(NSString *)dbFullPath { self = [super init]; int ret; if(self) { ret = sqlite3_open([dbFullPath UTF8String], &_db); if(ret != SQLITE_OK) return nil; } return self; } - (void)dealloc { [_sql release]; sqlite3_close(_db); [super dealloc]; } - (void)setSql:(NSString *)sql { if(_sql != sql) { [_sql release]; _sql = [sql copy]; } } - (BOOL)prepare { return (sqlite3_prepare_v2(_db, [_sql UTF8String], -1, &_statement, NULL) == SQLITE_OK); } - (void)getData { while (sqlite3_step(_statement) == SQLITE_ROW) { ++_row; [_delegate onCCSqlite3AnotherRowOK:self withRow:_row]; } } - (void)end { sqlite3_finalize(_statement); } // set so, we can get the random results - (void)setRandomReturns:(int)n { NSString *temp = [NSString stringWithFormat:@" order by random() limit %d", n]; NSString *final = [_sql stringByAppendingString:temp]; [self setSql:final]; } // if set so, the sqlite will returns the rowCount row data, which starts from argument start. - (void)setNRowsFrom:(int)start withRowCount:(int)rowCount { NSString *temp = [NSString stringWithFormat:@" limit %d,%d", start, rowCount]; NSString *final = [_sql stringByAppendingString:temp]; [self setSql:final]; } @end可能有更新:
googlecode链接地址: http://code.google.com/p/iphone-common-codes-ccteam/source/browse/trunk/CCFC/files/CCSqlite3.m
googlecode链接地址: http://code.google.com/p/iphone-common-codes-ccteam/source/browse/trunk/CCFC/files/CCSqlite3.m
github地址: https://github.com/cxsjabc/iphone-common-codes-ccteam/tree/master/CCFC/files/CCSqlite3.m
本文介绍了一个名为CCSqlite3的Objective-C类,该类实现了对SQLite数据库的基本操作,包括打开数据库、设置SQL语句、准备执行语句、获取数据、结束查询等。此外还提供了设置随机返回结果及指定行数返回的功能。
914

被折叠的 条评论
为什么被折叠?



