Click here to Skip to main content
15,884,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
sqlite3 *database;
sqlite3_stmt *compiledStmt;
// Init the animals Array
NSString *docsDir;
NSArray *dirPaths;
// Get the documents directory
dirPaths = NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = dirPaths[0];
// Build the path to the database file
databasePath = [[NSString alloc] initWithString:
[docsDir stringByAppendingPathComponent:student.db]];

// Open the database from the users filessytem
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
{

NSString *insertSQL=insert into studentsDetail(image) values(?);
if (sqlite3_prepare_v2(database, [insertSQL cStringUsingEncoding:NSUTF8StringEncoding], -1, &compiledStmt, NULL)== SQLITE_OK)
{
NSLog(@"before");
UIImage *image = [UIImage imageNamed:@"Cameroon.png"];
NSData *imageData=UIImagePNGRepresentation(image);

sqlite3_bind_blob(compiledStmt, 1, [imageData bytes], [imageData length], SQLITE_TRANSIENT);
if(sqlite3_step(compiledStmt) != SQLITE_DONE ) {
NSLog( @"Error: %s", sqlite3_errmsg(database) );
} else {
NSLog( @"Insert into row id = %lld", (sqlite3_last_insert_rowid(database)));

}
sqlite3_finalize(compiledStmt);
}
}
sqlite3_close(database);

what is wrong in the code...
Posted

1 solution

Debug your code and find what exactly the problem is?

At least get the error so some can help you move on.

Also check this CP article on same:
C# & SQLite - Storing Images[^]

..and similar answer here[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900