开发者

Database Application not work properly

开发者 https://www.devze.com 2023-02-19 04:26 出处:网络
In my application i open the database many time in one loop and then again i open the database it will not execute if (sqlite3_open([[self getDBPath] UTF8String], &database) == SQLITE_OK) this sta

In my application i open the database many time in one loop and then again i open the database it will not execute if (sqlite3_open([[self getDBPath] UTF8String], &database) == SQLITE_OK) this statement so my application doesnt work....

-(NSString *)getDBPath
{

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
    NSString *documentsDir = [paths objectAtIndex:0];

    return [documentsDir stringByAppendingPathComponent:@"BasicGreetings.sqlite"];

}



-(void) fillimage:(NSInteger)imgno
{
    testAppDelegate *appDelg = (testAppDelegate *)[[UIApplication sharedApplication]delegate];

    sqlite3 *database= nil;

    if (sqlite3_open([[self getDBPath] UTF8String], &database) == SQLITE_开发者_JAVA技巧OK)
    {

        const char *sql = "select setflag from Tblsetflag where imgNo = ?";
        sqlite3_stmt *selectStmt = nil;

        if (sqlite3_prepare_v2(database, sql, -1, &selectStmt, NULL) == SQLITE_OK) 
        {
            sqlite3_bind_int(selectStmt, 1,imgno);

            while (sqlite3_step(selectStmt) == SQLITE_ROW)
            {
                appDelg.a = sqlite3_column_int(selectStmt, 0);
                NSLog(@"%d",appDelg.a);
            }
        }


    }
    sqlite3_close(database);



}


Can you post the code to getDBPath, I suspect it can't find the file... check that value you return from that method (run in the simulator) and browse the simulator documents directory in Finder and verify the file exists.


Don't open and close your database on every pass through your -fillimage: method. You really should open it once at the start of your application (or when your application has become active from the background) and close it when your application exits or goes to the background.

You also never finalize your prepared statement, which may be leading to the sqlite3_close() failing. Again, you may want to create a prepared statement once, then reset it every time you run that method and finalize it before the SQLite database is closed.

0

精彩评论

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