Objective-C (最新の xcode) を使用して sqlite データベースに文字列を挿入しようとしていますが、何らかの奇妙な理由で、stackoverflow やインターネットで一般的に見つけたすべての例がうまくいかないようです。
私はSDKを使用していないので、単純な目的cです.
実際に機能し、取得可能なデータベースにデータを挿入するサンプルコードを持っている人はいますか?
ありがとう
sqlite3 *database;
if(sqlite3_open(___database file path__, &database) == SQLITE_OK)
{
NSString * str = [[NSString alloc] initWithFormat:@"INSERT INTO %@ VALUES %@",___table name___,___value___];
const char * sqlStatement = [str UTF8String];
}
else
{
//ERROR
return;
}
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK)
{
while(sqlite3_step(compiledStatement) == SQLITE_ROW)
{
for (int i = 0;; i++)
{
char * ch;
if ((ch = (char *)sqlite3_column_text(compiledStatement, i)))
{
NSString * ret = [NSString stringWithCString:ch encoding:NSUTF8StringEncoding];
}
else
{
break;
}
}
}
}
sqlite3_finalize(compiledStatement);
sqlite3_close(database);
このコードは、このようなテーブルに値を挿入します..