我想这应该是相当简单的,因为我是一个新的Xcode,Objective-C和SQLite,我只是想获得一个简单的教程工作。SQLite的“文件被加密或不是数据库”
我复制了 “sampled.sql” 文件的目录,这是连接代码:
-(NSMutableArray *) authorList {
theauthors = [[NSMutableArray alloc] initWithCapacity:10];
@try {
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSString *dbPath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:@"sampledb.sql"];
BOOL success = [fileMgr fileExistsAtPath:dbPath];
if(!success)
{
NSLog(@"Cannot locate database file '%@'.", dbPath);
}
if(!(sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK))
{
NSLog(@"An error has occured: %s", sqlite3_errmsg(db));
}
const char *sql = "SELECT * FROM verb";
sqlite3_stmt *sqlStatement;
if(sqlite3_prepare(db, sql, -1, &sqlStatement, NULL) != SQLITE_OK)
{
NSLog(@"Problem with prepare statement 1: %s", sqlite3_errmsg(db));
} else {
while (sqlite3_step(sqlStatement)==SQLITE_ROW) {
Author * author = [[Author alloc] init];
author.verb_nutid = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement,1)];
//author.title = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement,2)];
[theauthors addObject:author];
}
}
sqlite3_finalize(sqlStatement);
}
@catch (NSException *exception) {
NSLog(@"Problem with prepare statement 2: %s", sqlite3_errmsg(db));
}
@finally {
sqlite3_close(db);
return theauthors;
}
}
数据库文件:
BEGIN TRANSACTION
CREATE TABLE“动词“('ID'INTEGER PRIMARY KEY AUTOINCREMENT,'verba'TEXT,'verbb'TEXT); INSERT INTO“动词”价值......
等等......
但我得到的错误:
问题的准备语句1:文件加密或不是一个数据库
帮助将非常感谢! ( - :
给我你的mail-id我发送的是u代码@ user4030788 – sanjeet 2014-09-11 11:58:27
你不能在应用程序中写入文件,mainBundle resourcePath在应用程序中 – zaph 2014-09-11 12:02:38
好的,谢谢你的回复!我会试试Erzékiels先生某种程度上的建议...( - : – user4030788 2014-09-11 20:46:31