I'm facing a strength problem on fetching database. My codes works fine normally but when I fetch value from database repeatedly in small period time its showing error opening!: 14 sql_lite error that means it can't open the database. My Codes are shown below :
#import "sqlite3.h"
#import "FMDatabase.h"
+ (NSString *)getDBPath
{
NSString *dbPath=[TPUtlis applicationDocumentsDirectory];
dbPath=[dbPath stringByAppendingPathComponent:DATABASE_FILE_PATH];
dbPath=[TPUtlis getDirectoryAtPath:dbPath withInterMediateDirectory:NO];
dbPath=[dbPath stringByAppendingPathComponent:DATABASE_NAME];
return dbPath;
}
+ (FMDatabase *)getDatabase
{
FMDatabase *database = [FMDatabase databaseWithPath:[DBManager getDBPath]];
if([database open]) return database;
else return nil;
}
+ (NSMutableArray*)fetchmenu:(int)startLimit noOfRows:(int)noOfRows
{
NSMutableArray *arr = [[NSMutableArray alloc]init];
FMDatabase *database=[DBManager getDatabase];
if(database)
{
sqlite3 *database;
NSString *dbpath = [DBManager getDBPath];
const char* dbPath=[dbpath UTF8String];
if(sqlite3_open(dbPath, &database)==SQLITE_OK)
{
NSString *stm = [NSString stringWithFormat:@"SELECT * FROM menulist ORDER BY menuOrder limit %d,%d",startLimit, noOfRows];
//NSLog(@"Executed Menu Query with limits: %@", stm);
const char *sqlQuerry= [stm UTF8String];
sqlite3_stmt *querryStatement;
if(sqlite3_prepare_v2(database, sqlQuerry, -1, &querryStatement, NULL)==SQLITE_OK)
{
NSLog(@"conversion successful....");
while (sqlite3_step(querryStatement)==SQLITE_ROW)
{
NSMutableDictionary *menuMsgDict = [[NSMutableDictionary alloc] init];
[menuMsgDict setValue:[[NSString alloc] initWithUTF8String:
(const char *)sqlite3_column_text(querryStatement, 0)] forKey:@"MenuId"];
[menuMsgDict setValue:[[NSString alloc] initWithUTF8String:
(const char *)sqlite3_column_text(querryStatement, 1)] forKey:@"MenuName"];
[menuMsgDict setValue:@"" forKey:@"SubMenu"];
[arr addObject:menuMsgDict];
}
sqlite3_reset(querryStatement);
}
else
NSLog(@"error while conversion....");
sqlite3_close(database);
}
}
return arr;
}
What is wrong with this code? Please help me out.
Aucun commentaire:
Enregistrer un commentaire