0

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;

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

7 Comments

sqlite3_bind_blob(compiledStatement, 5, [(*incomingObject).file bytes], [(*incomingObject).file length], NULL);
Can you show code with that part in first post? Does it insert other data in that request? And which one from properties is blob data? Also you should pass bytes not NSData itself. For example like this: ` sqlite3_bind_blob(statement, index, [imageData bytes], [imageData length], SQLITE_STATIC);` Where imageData is NSData object.
Also make sure what compiledStatement is not NULL. I just don't see this kind of check in your code. In case if data not inserted at all, make sure your database placed outside of application bundle which is signed itself and it's content can't be changed.
if (!compiledStatement) { printf("\n §Compiled statements is NULL"); } // it shows that the statement isnt NULL
yes, other data is inserted in the code, but the blob just does't react !!
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.