這裏是我的代碼從sqlite3_prepare_v2失敗。錯誤是:內存不足
- (void) SaveImagesToSql: (NSData*) imgData {
// NSLog(@"\n*****Save image to SQLite*****\n");
sqlite3 *sqlite3DatabaseObject;
sqlite3_stmt* sqlite3Statement;
NSString *databasePath = [self.documentsDirectory stringByAppendingPathComponent:self.databaseFilename];
const char* sqlite3Query = "INSERT INTO ABCD (image) VALUES (?)";
BOOL openDatabaseResult = sqlite3_open_v2([databasePath UTF8String], &sqlite3DatabaseObject, -1, sqlite3Query);
if (openDatabaseResult == SQLITE_OK) {
sqlite3_stmt* sqlite3Statement;
BOOL sqlite3Prepare = sqlite3_prepare_v2(sqlite3DatabaseObject, sqlite3Query, -1, &sqlite3Statement, NULL);
if(sqlite3Prepare == SQLITE_OK) {
sqlite3_bind_blob(sqlite3Statement, 1, [imgData bytes], [imgData length], SQLITE_TRANSIENT);
sqlite3_step(sqlite3Statement);
}
}
else NSLog(@"SaveBody: Failed from sqlite3_prepare_v2. Error is: %s", sqlite3_errmsg(sqlite3DatabaseObject));
sqlite3_finalize(sqlite3Statement);
}
及其引發錯誤爲:
SaveBody:從sqlite3_prepare_v2失敗。錯誤是:內存不足
任何人都可以請幫助我這個。
在此先感謝。
編輯:
現在,我已經解決了sqlite3_open_v2
問題和一些低於所指出的其他問題,我現在收到一個不同的錯誤信息:
SaveBody:準備失敗:沒有這樣的表:ABCD
這是我修改後的代碼:
- (void) SaveImagesToSql: (NSData*) imgData {
// NSLog(@"\n*****Save image to SQLite*****\n");
sqlite3 *sqlite3DatabaseObject;
sqlite3_stmt* sqlite3Statement;
NSString *databasePath = [self.documentsDirectory stringByAppendingPathComponent:@"picdb.sqlite"];
const char* sqlite3Query = "INSERT INTO ABCD (image) VALUES (?)";
int openDatabaseResult = sqlite3_open_v2([databasePath UTF8String], &sqlite3DatabaseObject, SQLITE_OPEN_READWRITE , NULL);
// int openDatabaseResult = sqlite3_open_v2([databasePath UTF8String], &sqlite3DatabaseObject, -1, sqlite3Query);
if (openDatabaseResult == SQLITE_OK) {
sqlite3_stmt* sqlite3Statement;
int sqlite3Prepare = sqlite3_prepare_v2(sqlite3DatabaseObject, sqlite3Query, -1, &sqlite3Statement, NULL);
if(sqlite3Prepare == SQLITE_OK) {
sqlite3_step(sqlite3Statement);
sqlite3_bind_blob(sqlite3Statement, 1, [imgData bytes], [imgData length], SQLITE_TRANSIENT);
}
else
{
NSLog(@"Prepare failure: %s", sqlite3_errmsg(sqlite3DatabaseObject));
}
}
else NSLog(@"SaveBody: Failed from sqlite3_prepare_v2. Error is: %s", sqlite3_errmsg(sqlite3DatabaseObject));
sqlite3_finalize(sqlite3Statement);
}
不要改變問題,使現有答案失效。 –
是的,堆棧溢出的整個想法是有一個可搜索的問題和答案庫,如果你實質上改變了這個問題,未來的讀者會被一個與修訂後的問題無關的答案迷惑。如果我們回答您的原始問題,[接受下面的答案](http://stackoverflow.com/help/someone-answers)。如果您還有其他問題,請在Stack Overflow中搜索相關問題(因爲此前已被回答過),並且只有當您找不到答案時,發佈_new_問題,才能顯示您在新問題上所做的研究。 – Rob
好吧,對不起,我沒有意識到這一點,我是StackOverflow的新手。以後要小心。 –