Florik
Florik

Reputation: 1260

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 things, 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;

Upvotes: 0

Views: 863

Answers (1)

Serhii Mamontov
Serhii Mamontov

Reputation: 4932

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

Upvotes: 3

Related Questions