首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

sqlite的容易示例

2012-07-28 
sqlite的简单示例首先,需要将PlausibleDatabase.framework以及libsqlite3.0.dylib加入到项目中。?头文件:?#

sqlite的简单示例

首先,需要将PlausibleDatabase.framework以及libsqlite3.0.dylib加入到项目中。

?

头文件:

?

#import <UIKit/UIKit.h>@class PLSqliteDatabase;@interface sqliteViewController : UIViewController {PLSqliteDatabase *db;}@property (nonatomic, retain) PLSqliteDatabase *db;- (NSArray *)getBooks;@end

?

实现文件:

?

#import "sqliteViewController.h"#import <PlausibleDatabase/PlausibleDatabase.h>@implementation sqliteViewController@synthesize db;- (id)init{if (self = [super init]) {NSString *path = [[NSBundle mainBundle] pathForResource:@"CaseDatabase" ofType:@"sqlite"];PLSqliteDatabase *_db = [[PLSqliteDatabase alloc] initWithPath:path];self.db = _db;[_db release];if (![db open])NSLog(@"Could not open database");}return self;}- (NSArray *)getBooks{NSMutableArray *books = [[NSMutableArray alloc] initWithCapacity:0];id<PLResultSet> results = [db executeQuery:@"SELECT `ID`,`TITLE`,`COVER`,`DOCTOR` FROM `BOOKS` ORDER BY`UPDATE_TIME` DESC"];while ([results next]) {NSDictionary *row = [[NSDictionary alloc] initWithObjectsAndKeys: [NSNumber numberWithInt:[results intForColumn: @"ID"]], @"ID",  [results stringForColumn:@"TITLE"], @"TITLE",   [results stringForColumn:@"COVER"], @"COVER",  [results stringForColumn:@"DOCTOR"], @"DOCTOR", nil];[books addObject:row];NSLog(@"%@", books);[row release];}[results close];return books;}- (void)viewDidLoad {    [super viewDidLoad];[self init];[self getBooks];}- (void)dealloc {    [super dealloc];}@end

热点排行