私はios devを初めて使用しており、次の問題が発生しています: 私は必要なテーブルを初期化しました。 "いいえこのようなテーブル"のエラーは、ここにステップとコードです:このテーブルはありません:初期化後でもsqliteのtablename
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Function called to create a copy of the database if needed.
[[SQLiteUtilities sharedSQLiteManager] initializationDatabase];
return YES;
}
and here is the implementation:
-(void)initializationDatabase {
NSString *path = [self databaseFilePath];
BOOL isExists = [[NSFileManager defaultManager] fileExistsAtPath:path];
if (isExists) return;
FMDatabase *db = [FMDatabase databaseWithPath:path];
if ([db open] == NO) {
return;
}
NSString *sql =
@"CREATE TABLE albums("
"albumid INTEGER PRIMARY KEY AUTOINCREMENT,"
"directory CHAR(20) NOT NULL,"
"albumname CHAR(32) NOT NULL,"
"count INT NOT NULL,"
"orderid INT NOT NULL"
");"
"CREATE TABLE photos("
"photoid INTEGER PRIMARY KEY AUTOINCREMENT,"
"albumid INTEGER NOT NULL DEFAULT 0,"
"filename CHAR(50) NOT NULL DEFAULT \"\","
"originalname CHAR(50) DEFAULT \"\","
"addtime INTEGER NOT NULL DEFAULT 0,"
"createtime INTEGER NOT NULL DEFAULT 0,"
"filesize INTEGER NOT NULL DEFAULT 0"
");";
//[db executeQuery:sql1];
[db executeQuery:sql];
[db close];
}
and when i try to add anything as follows i get the "no such table:albums" error:
- (AlbumsUtilities *)createAlbumWithName:(NSString *)name {
FMDatabase *db = [FMDatabase databaseWithPath:[self databaseFilePath]];
if (![db open]) return nil;
NSString *directory = createRandomAlbumDirectory();
int maxid = 0;
BOOL success = [db executeUpdate:@"INSERT INTO albums(directory,albumname,count,orderid) VALUES(?,?,0,?)", directory,name,@(maxid)];
AlbumsUtilities *album = nil;
if (success) {
....(not getting here of course)
}
[db close];
return album;
}
おかげで、ありがとう、ありがとうございます。この@try
を呼び出すと、テーブル
作成し初期化した後、空白のファイル.sqlite拡張子
を追加すると、あなたのSQLite Fでありますileはドキュメントディレクトリにありますか? –
はい私は何度もチェックしましたが、私は削除して、それがちょうどの場合に再作成されているかどうかをチェックしました。 私はテーブルを落として、シミュレータをクリアしましたが、何も動作していません。 – user3411226