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..
2
-
1Please be more specific.hol– hol2012-08-27 05:50:29 +00:00Commented Aug 27, 2012 at 5:50
-
1why every time we give the sqlite open and close for inserting, updating and deleting from web server. Multiple time open and close is running why we give common declaration for this.Raj– Raj2012-08-27 09:21:23 +00:00Commented Aug 27, 2012 at 9:21
Add a comment
|
2 Answers
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.
1 Comment
Raj
I commonly use sqlite3 object and sqlite statement and query string for database connection and processing step. Is it correctly im using or not.
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));
}
}