开发者

Cannot insert blob into SQLite database

I have a problem with blob sql datatype, the problem is that I cannot insert the NSData to database, the compiler shows no errors, but the database file size hasn't change after data insertion,i've tried all kind of 开发者_StackOverflowthings, this is my last function i wrote but it seem to work neider, please help, thanks in advance!

sqlite3 *database;
        if (sqlite3_open([databasePath UTF8String], &database)== SQLITE_OK)
        {
            NSString *statement = [[NSString alloc]initWithFormat:@"insert into %@(date,name,type,urlpath) values('%@','%@','0','%@')",mainPath,
                                   currentTime,
                                   (*incomingObject).fileName, 
                                   filterURL];
            NSLog(@"\n--==%@ %@==--",(*incomingObject).fileName,(*incomingObject).urlAdress);
            const char *sqlStatement = [statement UTF8String];
            [statement release];
            sqlite3_stmt *compiledStatement;
            sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL);
            sqlite3_step(compiledStatement);
            sqlite3_reset(compiledStatement);
            sqlite3_finalize(compiledStatement);
        }
        sqlite3_close(database);
        break;


It's not really good idea to pass parameters values in SQL statement. In this way you not protected from SQL injection.

I suggest to you use SQLite C-API functions like: sqlite3_bind_*. You will find sqlite3_bind_blob method which will allow you to insert blob into table

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜