0
このコードを使用してSignatureViewのBLOBデータを挿入しようとしていますが、実際にデータベースを参照するとデータの代わりにnullがあります。 私の署名テーブルのスキーマを以下に示します。iOS SQLite BlobデータがNULLを保存しています
create table sign(ID整数主キーAUTOINCREMENT、イメージblob、invoiceid整数)。
-(void)storeImageData:(NSData *)imageData withInvoiceID:(NSInteger)invoiceID{
NSString *dbPath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:@"database.sqlite3"];
const char *dbpath = [dbPath UTF8String];
sqlite3 *contactDB;
sqlite3_stmt *statement;
NSLog(@"%@",dbPath);
if (sqlite3_open(dbpath, &contactDB) == SQLITE_OK)
{
int invoiceIDINT = (int)invoiceID;
//
NSString *insertSQL = [NSString stringWithFormat: @"INSERT INTO sign (image,invoiceid) VALUES (?,%d)", invoiceIDINT];
const char *insert_stmt = [insertSQL UTF8String];
sqlite3_prepare_v2(contactDB, insert_stmt, -1, &statement, NULL);
if (sqlite3_step(statement) == SQLITE_DONE)
{
sqlite3_bind_blob(statement, 2, [imageData bytes], [imageData length], SQLITE_TRANSIENT);
sqlite3_step(statement);
} else {
const char *Error = sqlite3_errmsg(database);
NSString *error = [[NSString alloc]initWithUTF8String:Error];
UIAlertView *view = [[UIAlertView alloc]initWithTitle:@"Error2" message:[NSString stringWithFormat:@"Last inserted ID: %@",error] delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
[view show];
}
sqlite3_finalize(statement);
sqlite3_close(contactDB);
}
}
'sqlite3_finalize()' NULL文で呼ばれるように許可されています。 –
@CL。しかし、なぜ?開いているデータベースを閉じるだけで済みます。あなたは、準備されたステートメントを完成する必要があります。 – rmaddy
無条件に 'sqlite3_finalize'を呼び出す方が簡単な場合があります。 –