Reputation: 39
I want to insert and update and delete and select the 1000 record in database. When and where i want open and close the database connection. i insert and update and delete the data in database but i error "Out of Memory","Unable to open the database file","Locked Database" this kind of error raise from my side. How to resolve this problem please help guys..
Upvotes: 2
Views: 1621
Reputation: 406
NSData *d=UIImageJPEGRepresentation(image, 0.50);
[dm writeImageInTable:[Base64 encode:d]];
-(void)writeImageInTable:(NSString *)imageString
{
if (sqlite3_open([DB_PATH UTF8String], &database)==SQLITE_OK)
{
NSString *str=[NSString stringWithFormat:@"INSERT INTO imageTable (image) VALUES('%@')",imageString];
// NSLog(@"%@",str);
const char *getFolderQuery=[str UTF8String];
if(sqlite3_prepare_v2(database, getFolderQuery, -1, &queryForImage, NULL)==SQLITE_OK)
{
NSLog(@"test");
int queryResult;
if((queryResult=sqlite3_step(queryForImage)) == SQLITE_DONE)
{
NSLog(@"sqlite done insert");
}
NSLog(@"sqlite error inside %s", sqlite3_errmsg(database));
}
sqlite3_reset(queryForImage);
sqlite3_finalize(queryForImage);
NSLog(@"sqlite error %s", sqlite3_errmsg(database));
sqlite3_finalize(queryForImage);
}
else
{
}
if(sqlite3_close(database)==SQLITE_OK)
{
NSLog(@"database closed");
}
else
{
NSLog(@"database still open with error %s",sqlite3_errmsg(database));
}
}
Upvotes: 0
Reputation: 975
Hey raj whenever you going to deal with the database you firstly open the database Open db and after making changes you must close the database by calling Close Db method. Here are some links for using sqlite in iPhone
http://www.techotopia.com/index.php/An_Example_SQLite_based_iPhone_Application
http://blog.saers.com/archives/2008/03/14/sqlite-for-iphone-sdk/
http://how2s.org/index.php/How_to_get_started_with_SQLite_on_the_iPhone
i think it helps you.
Upvotes: 1