Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

not able insert values into sqlite database.

y2kreddyy2kreddy Posts: 32Registered Users
Hi people,


HERE IS MY CODE,

const char *sqlStatement = (const char *)query;

//const char *sqlStatement ="insert into usertable values('one','two')";


if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement,NULL) == SQLITE_OK)
{
NSLog(@"inside");
// Loop through the results and add them to the feeds array
while(sqlite3_step(compiledStatement) == SQLITE_ROW)
{ }
sqlite3_finalize(compiledStatement);

}

if i run this code, the values does not get inserted into the database. however if i uncomment the second line and comment the first line it works fine.
the variable "query" is of type NSMutableString and it is a local variable declared in the header file.
sqlStatement is member variable for the method.
i tried several things like retain and release and nothing worked.
not able to resolve this for the past 2 days. and its kindof getting frustrated.

Anyone please HELP???
Post edited by y2kreddy on

Replies

  • LazyCoderLazyCoder Posts: 17Registered Users
    y2kreddy;262538 said:
    Hi people,


    HERE IS MY CODE,

    const char *sqlStatement = (const char *)query;

    //const char *sqlStatement ="insert into usertable values('one','two')";


    if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement,NULL) == SQLITE_OK)
    {
    NSLog(@"inside");
    // Loop through the results and add them to the feeds array
    while(sqlite3_step(compiledStatement) == SQLITE_ROW)
    { }
    sqlite3_finalize(compiledStatement);

    }

    if i run this code, the values does not get inserted into the database. however if i uncomment the second line and comment the first line it works fine.
    the variable "query" is of type NSMutableString and it is a local variable declared in the header file.
    sqlStatement is member variable for the method.
    i tried several things like retain and release and nothing worked.
    not able to resolve this for the past 2 days. and its kindof getting frustrated.

    Anyone please HELP???
    You may want use:

    const char *sqlStatement = [query cStringUsingEncoding:[NSString defaultCStringEncoding]];

    As first line.
    Right now you are casting 'id' to 'const char*'.
  • y2kreddyy2kreddy Posts: 32Registered Users
    Hey man

    i just used the below code and it worked fine.

    sqlStatement=[query cStringUsingEncoding:NSASCIIStringEncoding];

    i also tested with your code and its working too. i should have posted this 2 days ago. it would have saved lot of time for me , anyways thank you soo much for your response.

    Have a nice day.
    Thank You.
Sign In or Register to comment.