ghi*_*boz 2 sqlite database-connection objective-c ios
我有一个奇怪的问题,我希望解决:
这是我的代码:
-(Shot*) getShot:(int)shot {
NSString *sqlStr = [NSString stringWithFormat:@"SELECT * FROM tbShots where nShot = %d ", shot];
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *documentFolderPath = [searchPaths objectAtIndex:0];
NSString *dbFilePath = [documentFolderPath stringByAppendingPathComponent:DATABASE_NAME_EXT];
if (dbFilePath == NULL) {
NSLog(@"dbFilePath is NULL");
}
sqlite3 *dbHandle;
if (sqlite3_open([dbFilePath UTF8String], &dbHandle)) {
NSLog(@"sqlite3_open: failed");
}
sqlite3_stmt *preparedStatement;
const char* queryStatement = [sqlStr UTF8String];
sqlite3_prepare_v2(dbHandle, queryStatement, -1, &preparedStatement, NULL);
Shot *s = nil;
NSString * note = @"";
while( sqlite3_step(preparedStatement) == SQLITE_ROW)
{
s = [[[Shot alloc] initWithShot:shot] autorelease];
}
sqlite3_finalize(preparedStatement);
sqlite3_close(dbHandle);
return s;
}
Run Code Online (Sandbox Code Playgroud)
现在似乎工作正常:但我有一个问题:
我多次调用此函数,当我第 50 次调用它时,sqlite3_open 函数失败(我看到日志错误“sqlite3_open: failed”...
我犯了一些错误?提前致谢
| 归档时间: |
|
| 查看次数: |
1493 次 |
| 最近记录: |