0

iOS開発にSQLiteデータベース(Firefoxアドオン)を使用しています。データベースに手動でデータを挿入します。しかし、初めてプログラムを実行し、そのデータを表示します。しかし、手動でデータベースにデータを再度挿入した後、そのデータは表示されません。私はiOS開発の初心者です。ベローは私のデータベース接続を持っています。助けてください。

- (void)viewDidLoad
{
    NSString *defaultDBPath;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error;
    NSString *ddPath = [self getDBPath];
    BOOL success = [fileManager fileExistsAtPath:ddPath];

    if(!success) {

        defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"AddressBook.sqlite"];
        success = [fileManager copyItemAtPath:defaultDBPath toPath:ddPath error:&error];

        if (!success)
            NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
    }

   // const char *dbpath=[ddPath UTF8String];
    const char *dbpath1=[ddPath UTF8String];
    sqlite3_stmt *statement;
     NSMutableArray  *company =[[NSMutableArray alloc]init];

    if (sqlite3_open(dbpath1, &contactDB)==SQLITE_OK)
    {
        NSString *querySQL=[NSString stringWithFormat:@"SELECT CompanyName FROM tblCompany order by CompanyName"];

        const char *query_stmt=[querySQL UTF8String];

        if (sqlite3_prepare_v2(contactDB, query_stmt, -1, &statement, NULL)==SQLITE_OK)
        {
            int i=0;
            while(sqlite3_step(statement)==SQLITE_ROW)
            {
                NSString *my=[[NSString alloc]initWithUTF8String:(const char*)sqlite3_column_text(statement, 0)];
                NSLog(@"name %@",my);


               [company insertObject:my atIndex:i];
               i=i+1;
                companyDetails=[NSDictionary dictionaryWithContentsOfFile:my];

               // [[cell textlabel] setText:my];
            }
            companies =company;
            companyKey=[companyDetails allKeys];
            sqlite3_finalize(statement);
        }
        else
            NSLog(@"Not connected");
        sqlite3_close(contactDB);
    }

Getdatabaseパスメソッド::

- (NSString *) getDBPath {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
    NSString *documentsDir = [paths objectAtIndex:0];
    return [documentsDir stringByAppendingPathComponent:@"Address.sqlite"];
}

これらを試しましたが、iOSアプリケーションで更新されたデータベースデータが表示されません。解決策を教えてください。

4

1 に答える 1

0

このようにファイルパスをチェックするには、プロジェクトフォルダ内の.sqliteファイルをチェックしません

/Users/username/Library/Application Support/iPhone Simulator/5.0/Applications/4F4574E2-AD8A-493E-9B16-2D456AFAEB6C/Documents/your file.sqlite 

//username - your user name
//4F4574E2-AD8A-493E-9B16-2D456AFAEB6C  -it changed for projects
于 2013-01-08T04:20:57.433 に答える