iOSAppDev
iOSAppDev

Reputation: 2783

Can not execute sqlite3_prepare_v2

I can not execute sqlite3_prepare_v2. When I debug the program the program opens the DB , after that it comes to sqlite3_prepare_v2 . When I click continue it comes out of if loop & control transfers to finalize statement. Here is my code

sqlite3 * database;

if(sqlite3_open([db_path UTF8String], &database)==SQLITE_OK)
{

    sqlite3_stmt * compiledstatement;

    sqlstmt = @" my select sql query";

    if(sqlite3_prepare_v2(database, sqlstmt, -1, &compiledstatement,NULL)==SQLITE_OK)

    {

        while(sqlite3_step(compiledstatement)==SQLITE_ROW)

        {

            // select query logic


        }

    }

    sqlite3_finalize(compiledstatement);

}

sqlite3_close(database);

Upvotes: 0

Views: 1719

Answers (1)

Donal O'Danachair
Donal O'Danachair

Reputation: 1470

sqlstmt is an NSString in your code. It should be a C string. Change

if (sqlite3_prepare_v2(database, sqlstmt, -1, &compiledstatement,NULL)==SQLITE_OK)

to

if (sqlite3_prepare_v2(database, [sqlstmt **UTF8String**], -1, &compiledstatement,NULL)==SQLITE_OK)

Upvotes: 2

Related Questions