无法将blob插入SQLite数据库

时间:2011-08-15 13:31:24

标签: iphone ipad sqlite

我的blob sql数据类型有问题,问题是我无法将NSData插入数据库,编译器显示没有错误,但数据插入后数据库文件大小没有变化,我尝试过各种各样的事情,这是我写的最后一个功能,但它似乎工作neider,请帮助,提前谢谢!

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;

1 个答案:

答案 0 :(得分:3)

在SQL语句中传递参数值并不是一个好主意。这样就不会受到SQL注入的保护。

我建议您使用SQLite C-API函数,例如: sqlite3_bind _ * 。您将找到允许您将blob插入表

sqlite3_bind_blob方法
相关问题