Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: iPhone Objective-C iOS
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 4-Jun-13 2:50am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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[^]
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 200
1 Kamal Rocks 184
2 PIEBALDconsult 150
3 BillWoodruff 148
4 Jochen Arndt 135
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 4 Jun 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100