私はテーブルにデータを挿入する方法を知っている 私は別のアプリケーションでこれは多くの時間を試してみてください完璧だが、私は新しいデータベースとテーブルを作成します。私はボタンを追加呼び出すときに、私は、この保存エラーコンソールにエラーが表示されます。どのようにiphoneのsqliteデータベースの日付を保存する
no such table: bit
、これはあなたが
static sqlite3_stmt *addStmt = nil;
を宣言する必要が
#import "untitled.h"
#import<sqlite3.h>
#define DATABASE_NAME @"hello.sqlite"
@implementation untitled
@synthesize enter;
- (NSString *) getDBPath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSLog(@"*****##:%@",documentsDir);
return [documentsDir stringByAppendingPathComponent:DATABASE_NAME];
}
- (void) copyDatabaseIfNeeded {
//Using NSFileManager we can perform many file system operations.
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSString *dbPath = [self getDBPath];
NSLog(@"*****:%@",dbPath);
BOOL success = [fileManager fileExistsAtPath:dbPath];
if(!success) {
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:DATABASE_NAME];
success = [fileManager copyItemAtPath:defaultDBPath toPath:dbPath error:&error];
if (!success)
NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
}
}
-(void)Add
{
NSString *filePath = [self getDBPath];
NSLog(@"this check:%@",filePath);
sqlite3 *database;
if(sqlite3_open([filePath UTF8String], &database) == SQLITE_OK) {
const char *sqlStatement = "insert into bit(Title) VALUES (?)";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
sqlite3_bind_text(compiledStatement, 1, [enter.text UTF8String], -1, SQLITE_TRANSIENT);
}
if(sqlite3_step(compiledStatement) != SQLITE_DONE) {
NSLog(@"Save Error: %s", sqlite3_errmsg(database));
}
else {
sqlite3_reset(compiledStatement);
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"UIAlertView" message:@"Record added" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
alert = nil;
}
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
}
-(IBAction)sumit{
[self Add];
}
SQLiteに日付を保存することができます。しかし、文字列 –
として保存する方が良いでしょう。どの時点で "ビット"テーブルを作成しますか?あなたは "ビット"テーブルの作成ステートメントを投稿できますか? – CarlJ