开发者

Universal application DB question

I'm making an universal application for both iPhone and iPad and I was wondering if there is an specific location where I have to put my sqlite database? Because apperently he can't find it and giving a result of not being able to open the database! = app not working :/

Currently I have my database in the "Other Sources" folder.

//Maakt een lijst  van path strings voor de specifieke directories voor de specifieke do开发者_StackOverflow社区mains.
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//Eerste object van paths wordt in de string gezet!
NSString *documentsDir = [documentPaths objectAtIndex:0];
//er wordt gezocht naar todo.sqlite in het opgegeven path!
NSString *databasePath = [documentsDir stringByAppendingPathComponent:@"todo.sqlite"];
pad = databasePath;

if (sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
    status = TRUE; //DEBUG PURPOSES ONLY!
    const char *sql = "SELECT pk FROM todo";
    sqlite3_stmt *statement;

    if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK) {
        while (sqlite3_step(statement) == SQLITE_ROW) {
            int primaryKey = sqlite3_column_int(statement, 0);
            Taak *taak = [[Taak alloc] initWithPrimaryKey:primaryKey database:database];
            [taken addObject:taak];
            [taak release];
        }
    }

    sqlite3_finalize(statement);
}else {
    status = FALSE; //DEBUG PURPOSES ONLY!
    sqlite3_close(database);
    NSAssert1(0, @"Failed to open database with message '%s'.", sqlite3_errmsg(database));
}

This is my connection code and I searched a lot of forums and tutorials and everyone is doing it like that!


if(sqlite3_open([databasepath UTF8String], &database) == SQLITE_OK) {
        const char* sqlStatement; 
        sqlStatement="select fld_carromdescription from tbl_carrom where fld_carromdetails like?";

        sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL);
        printf( "could not prepare statemnt: %s\n", sqlite3_errmsg(database));

        if( sqlite3_prepare_v2(database, sqlStatement, -1, & compiledStatement, NULL) == SQLITE_OK ) {
            sqlite3_bind_text(compiledStatement,1,[[usdflt objectForKey:@"phone"] UTF8String] , -1,SQLITE_STATIC);
            NSLog(@"Database check111");
            //  [tablearray removeAllObjects];
            while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
                printf("in loop");

                @try {
                    NSLog(@"Database check");
                    txtview.text=[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement,0)];
                    toplbl.text=[usdflt valueForKey:@"phone"];
                    [txtview scrollRangeToVisible:NSMakeRange(0, 0)];
                }

                @catch (NSException * e) {

                }
                @finally {

                }

            }
        }
        sqlite3_finalize(compiledStatement);

    }

    sqlite3_close(database);
}

Try this out.

I am also using the sqliteDB in other sources only. I have done 3 universal applications. I have no difficulties to get the access.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜