开发者

Error in insert query of sqlite

开发者 https://www.devze.com 2023-04-09 20:12 出处:网络
I am making an iphone app, in which I am using sqlite. In one class when I tried to insert a string it get crash and 开发者_开发百科giving the following error

I am making an iphone app, in which I am using sqlite. In one class when I tried to insert a string it get crash and 开发者_开发百科giving the following error

-[CFString UTF8String]: message sent to deallocated instance 0xe555220

I don't know Why it is happening.

Following is the insert query which I am implementing.

-(void)againinsert
{
sqlite3_stmt *addStmt = nil;

if(addStmt == nil) 
{ 
    NSString *str = @"don't know";
    const char *sql = "insert into medicationdetail1(doctorname, emailid, medicationname,   status) values (?,?,?,?)";
    if(sqlite3_prepare_v2(database, sql , -1, &addStmt, NULL) != SQLITE_OK)
    {
        NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database));
    }
    sqlite3_bind_text(addStmt, 1, [comparedoctorname UTF8String], -1, SQLITE_TRANSIENT);
    sqlite3_bind_text(addStmt, 2, [globalemail    UTF8String], -1, SQLITE_TRANSIENT);
    sqlite3_bind_text(addStmt, 4, [comparemedic UTF8String], -1, SQLITE_TRANSIENT);
    sqlite3_bind_text(addStmt, 7, [str UTF8String], -1, SQLITE_TRANSIENT);
    if(SQLITE_DONE != sqlite3_step(addStmt))
    {
        NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database));
    }

}

}

When the breakpoint moves from second to third statement it get crash.

Please provide the solution.

Thanku very much.


use this one

sqlite3_bind_text(addStmt, 3, [comparemedic UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(addStmt, 4, [str UTF8String], -1, SQLITE_TRANSIENT);


USE

sqlite3_bind_text(addStmt, 1, [comparedoctorname UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(addStmt, 2, [globalemail    UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(addStmt, 3, [comparemedic UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(addStmt, 4, [str UTF8String], -1, SQLITE_TRANSIENT);
0

精彩评论

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