I want execute the insert query the query was working fine when we call this InsUpdateDelData its return false then the data was not inserted
- (IBAction)addToCart:(id)sender {
AppDelegate *obj = (AppDelegate *)[[UIApplication sharedApplication]delegate] ;
NSString *insert = #"ahmadyarimran#yahoo.com" ;
NSString *insertSQL = [NSString stringWithFormat:
#"INSERT INTO cart_user(user_id,product_price,product_type,categories_type,product_images,description) values('%#','%#','%#','%#','%#','%#')",insert,handBegsImages.product_price,handBegsImages.product_tagline,handbegCategoriess.handbegid,handBegsImages.main_image,handBegsImages.product_description];
BOOL abc = [obj InsUpdateDelData:insertSQL];
NSLog(#"print the value of abc %#=", abc) ;
if (abc == TRUE) {
NSLog(#"# Data was Inserted");
}
else{
[Utility showAlertView:#"Plz try again message" message:#"Again" viewcontroller:self];
}
}
-(BOOL)InsUpdateDelData:(NSString*)SqlStr
{
if([SqlStr isEqual:#""])
return NO;
BOOL RetrunValue;
RetrunValue = NO;
const char *sql = [SqlStr cStringUsingEncoding:NSUTF8StringEncoding];
sqlite3_stmt *stmt;
if (sqlite3_prepare_v2(database, sql, -1, &stmt, nil) == SQLITE_OK)
RetrunValue = YES;
if(RetrunValue == YES)
{
if(sqlite3_step(stmt) != SQLITE_DONE) {
}
sqlite3_finalize(stmt);
}
return RetrunValue;
}
If InsUpdateDelData returned NO, then that means that sqlite3_prepare_v2 did not return SQLITE_OK. If you want to know why it did not return SQLITE_OK, then log the error immediately after sqlite3_prepare_v2 failed, but before calling any other SQLite functions:
NSLog(#"err=%s", sqlite3_errmsg(database));
Related
I'm following some tutorials from youtube for sqlite crud operations. I have textfields with name, contact and address , when i hit save button it show message in console that data is saved but when i look at database it nothing appears there. My database path is correct and no errors in code but 'm confused why it isn't going. My path code is this,
-(void)copyandpaste{
NSArray *arr1 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *str1 = [arr1 objectAtIndex:0];
strpath = [str1 stringByAppendingPathComponent:#"personinfo.sqlite"];
if (![[NSFileManager defaultManager]fileExistsAtPath:strpath]) {
NSString *local = [[NSBundle mainBundle]pathForResource:#"personinfo" ofType:#"sqlite"];
[[NSFileManager defaultManager]copyItemAtPath:local toPath:strpath error:nil];
}
NSLog(#"%#",strpath);
}
this method is called in appdelegate.m file,
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[self copyandpaste];
return YES;
}
I have mad NSObject class for database connection. the connection code is this,
-(id)init{
appdel = (AppDelegate *)[[UIApplication sharedApplication]delegate]; //get all methods in AppDelegate
strmain = appdel.strpath;
return self;
}
-(NSMutableArray *)getalluser:(NSString *)query{
arrdata = [[NSMutableArray alloc]init];
if (sqlite3_open([strmain UTF8String], &(database))==SQLITE_OK) {
sqlite3_stmt *connection;
if (sqlite3_prepare_v2(database, [query UTF8String], -1, &connection, nil)==SQLITE_OK) {
while (sqlite3_step(connection)==SQLITE_ROW) {
NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
NSString *str12 = [[NSString alloc]initWithUTF8String:(char *)sqlite3_column_text(connection, 0)]; //name in first column
NSLog(#"Checking");
NSString *str13 = [[NSString alloc]initWithUTF8String:(char *)sqlite3_column_text(connection, 1)]; //contact in second column
NSString *str14 = [[NSString alloc]initWithUTF8String:(char *)sqlite3_column_text(connection, 2)]; //address in third column
[dic setObject:str12 forKey:#"name"];
[dic setObject:str13 forKey:#"contact"];
[dic setObject:str14 forKey:#"address"];
[arrdata addObject:dic];
}
}
sqlite3_finalize(connection);
}
sqlite3_close(database);
return arrdata;
}
My save button code with query is this,
- (IBAction)btnSave:(id)sender {
NSString *saveDATA=[[NSString alloc]initWithFormat:#"insert into stuInfo values('%#','%#','%#')",txtName,txtContact,txtAddress];
dboperations *db = [[dboperations alloc ]init];
BOOL ds = [db getalluser:saveDATA];
if (ds) {
NSLog(#"Data Saved in database");
}else{
NSLog(#"Data is not Saved in database");
}
}
- (NSString*) saveData:(NSString *)name cont:(NSString *)contacts add:(NSString *)address
{
const char *dbpath = [YOUR_DATA_BASE_PATH UTF8String];
if (sqlite3_open(dbpath, &database) == SQLITE_OK)
{
NSLog(#"=============saveData open==============");
const char * query="insert into YOUR_TABLE_NAME(name,contacts,address) values(?,?,?);";
sqlite3_stmt *inset_statement;
char *errMsg;
if (sqlite3_open(dbpath, &database)!=SQLITE_OK) {
NSLog(#"Error to Open");
return nil;
}
if (sqlite3_prepare_v2(database, query , -1,&inset_statement, NULL) != SQLITE_OK )
{
NSLog(#"%s Prepare failure '%s' (%1d)", __FUNCTION__, sqlite3_errmsg(database), sqlite3_errcode(database));
NSLog(#"Error to Prepare");
return nil;
}
//No of data to insert
sqlite3_bind_text(inset_statement,1,[name UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(inset_statement,2,[contacts UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(inset_statement,3,[address UTF8String], -1, SQLITE_TRANSIENT);
if(sqlite3_step(inset_statement)== SQLITE_DONE)
{
long long lastRowId = sqlite3_last_insert_rowid(database);
NSString *rowId = [NSString stringWithFormat:#"%d", (int)lastRowId];
NSLog(#"Row ID of Last Inserted row %#",rowId);
sqlite3_finalize(inset_statement);
sqlite3_close(database);
NSLog(#"=============saveData Close==============");
return rowId;
}
if (sqlite3_exec(database, query, NULL, NULL, &errMsg)
!= SQLITE_OK)
{
NSLog(#"Failed to Insert msg in message table Error = %s",errMsg);
sqlite3_finalize(inset_statement);
sqlite3_close(database);
NSLog(#"=============saveData Close==============");
return nil;
}
else
{
sqlite3_finalize(inset_statement);
}
}
NSLog(#"=============saveData Close==============");
sqlite3_close(database);
return nil;
}
You are not handling if there are any errors in the SQLite statements you are preparing.
The function will always return true because arrdata is never null
You need to add anelse statements to your
if (sqlite3_prepare_v2(database, [query UTF8String], -1, &connection, nil)==SQLITE_OK)
to show any errors...
NSLog(#"%s",sqlite3_errmsg(database));
This is my code.
It is only returning the first row from database. I know something is really wrong but don't know what. Please help.
if(sqlite3_open([databasePath UTF8String],&texttalkdb)==SQLITE_OK)
{
sqlite3_stmt *statement;
if(sqlite3_prepare_v2(texttalkdb, [sql UTF8String], -1,&statement, NULL)==SQLITE_OK)
{
if(sqlite3_step(statement)==SQLITE_ROW)
{
for(int i=0;i<=20;i++)
{
char *pass=(char*)sqlite3_column_text(statement,i);
NSString *passStr = [NSString stringWithFormat:#"%s",pass];
NSString *msg=[[NSString alloc]initWithUTF8String:pass];
[arr addObject:msg];
}
}
sqlite3_finalize(statement);
}
sqlite3_close(texttalkdb);
}
NSLog(#"%#",arr);
return arr;
Try this
if(sqlite3_prepare_v2(texttalkdb, [sql UTF8String], -1,&statement, NULL)==SQLITE_OK)
{
while( sqlite3_step(statement) == SQLITE_ROW )
{
//get records
}
}
Step 1: This is for check the getting values is empty or not
+(NSString*)charToString:(char*)chart
{
NSString *string = #" ";
if(string)
{
chart = [self checkEmptyChar:chart];
string=[NSString stringWithUTF8String:chart];
}
return string;
}
Step 2: This is for checking character
+(char *)checkEmptyChar:(char *)check
{
NSString *string = #" ";
if (check == NULL)
check = string;
return check;
}
Step 3: To fetch SQLite Coding
if (sqlite3_prepare_v2(database, [query UTF8String], -1, &stment, nil) == SQLITE_OK)
{
while (sqlite3_step(stment) == SQLITE_ROW)
{
for(int i=0;i<=20;i++)
{
NSString *msg = [self charToString: (char *)sqlite3_column_text(stment, i)];
[array addObject:msg];
}
}
sqlite3_reset(stment);
}
sqlite3_finalize(stment);
}
sqlite3_close(database);
- (void) updateTimeStamp:(NSDictionary *) record forRowID: (NSString *) updateTableName
{
int dictionarySize = [record count];
NSMutableData *dKeys = [NSMutableData dataWithLength:sizeof(id) *dictionarySize];
NSMutableData * dValues = [NSMutableData dataWithLength: sizeof(id) * dictionarySize];
[record getObjects:(__unsafe_unretained id *)dValues.mutableBytes andKeys:(__unsafe_unretained id *)dKeys.mutableBytes];
[dValues appendBytes:&updateTableName length:sizeof(id)];
NSString * query = [NSString stringWithFormat:#"update %# set %# = ? where Table_Name= ?",tableName,[[record allKeys] componentsJoinedByString:#" = ?, "]];
[self bindSQL:[query UTF8String] withVargs:(va_list)dValues.mutableBytes];
if(sqlite3_step(statment) == SQLITE_DONE);
{
NSLog(#"prepead Timestamp %s",sqlite3_errmsg(database));
}
sqlite3_reset(statment);
#synchronized(self)
{
if(sqlite3_finalize(statment) != SQLITE_OK)
{
NSLog(#"doQuery: sqlite3_finalize failed (%s)", sqlite3_errmsg(database));
}
}
}
When i run application that function work perfectly? not an any issue but that function after database is locked ? what the problem with the function please give me solution
i have many table so i open database once time in function when all timestamp updated after close the database.
bindSQL function below
- (void) bindSQL:(const char *) cQuery withVargs:(va_list)vargs
{
int param_count;
NSLog(#"%d",sqlite3_prepare_v2(database, cQuery, -1, &statment, NULL));
if(sqlite3_prepare_v2(database, cQuery, -1, &statment, NULL) != SQLITE_OK)
{
NSLog(#"bindSQL: could not prepare statement (%s) %s", sqlite3_errmsg(database), cQuery);
statment = NULL;
return;
}
if((param_count = sqlite3_bind_parameter_count(statment)))
{
for(int i =0; i < param_count ;i++)
{
id object = va_arg(vargs,id);
if(object == nil)
{
sqlite3_bind_null(statment, i+1);
}
else if ([object respondsToSelector:#selector(objCType)])
{
if(strchr("islqISLBQ", *[object objCType]))
{
sqlite3_bind_int(statment, i+1, [object intValue]);
}
else if (strchr("fd", *[object objCType]))
{
sqlite3_bind_double(statment, i+1, [object doubleValue]);
}
else
{
NSLog(#"bindSQL: Unhandled objCType: %s query: %s", [object objCType], cQuery);
statment = NULL;
return;
}
}
else if ([object respondsToSelector:#selector(UTF8String)])
{
sqlite3_bind_text(statment, i+1, [object UTF8String], -1, SQLITE_TRANSIENT);
}
else if ([object isEqual:[NSNull null]])
{
statment = NULL;
return;
}
else
{
NSLog(#"bindSQL: Unhandled parameter type: %# query: %s", [object class], cQuery);
statment = NULL;
return;
}
}
}
va_end(vargs);
return;
}
This code creates two statement objects:
NSLog(#"%d",sqlite3_prepare_v2(database, cQuery, -1, &statment, NULL));
if(sqlite3_prepare_v2(database, cQuery, -1, &statment, NULL) != SQLITE_OK)
of which only one is finalized later.
If you want to check the return code, better use a variable:
int rc = sqlite3_prepare_v2(database, cQuery, -1, &statment, NULL);
NSLog(#"%d", rc);
if (rc != SQLITE_OK)
So I'm fairly new to iOS development and I'm having problems with my select function. I made a function that should take in a select query and the table name and return an array of results where each array entry is a dictionary with a row of results. Somehow my query for column names is deleting my columnNames variable and returning crazy results. I'm just trying to figure out an easy way to store, access, manipulate query results
Here is the function that converts results into array:
-(NSMutableArray *)selectQuery:(NSString*)query
table:(NSString*)table
{
NSMutableArray *returnArray = [NSMutableArray new];
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
{
NSMutableArray *columnNames;
NSString *tableQuery = [NSString stringWithFormat:#"PRAGMA table_info('%#')", table];
if (sqlite3_prepare_v2(database, [tableQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
{
while (sqlite3_step(statement) == SQLITE_ROW)
{
[columnNames addObject:[NSString stringWithUTF8String:(const char*)sqlite3_column_text(statement, 1)]];
}
}
else
{
NSLog(#"Error preparing table query:");
NSLog(tableQuery);
}
if (sqlite3_prepare_v2(database, [query UTF8String], -1, &statement, nil) == SQLITE_OK)
{
while(sqlite3_step(statement)==SQLITE_ROW)
{
NSMutableDictionary *temp= [NSMutableDictionary new];
for (int i = 0; i < [columnNames count]; i++)
{
[temp setObject:[NSString stringWithUTF8String:(const char*)sqlite3_column_text(statement, i)] forKey:columnNames[i]];
}
if (temp != nil)
{
[returnArray addObject:temp];
temp = nil;
}
}
sqlite3_reset(statement);
sqlite3_close(database);
}
else
{
NSLog(#"Error preparing select statement with query:");
NSLog(query);
}
}
else
{
NSLog(#"Could not open database");
}
return returnArray;
}
and heres the call to it
NSMutableArray *queryResults = [dbInstance selectQuery:[NSString stringWithFormat:#"SELECT gallons, mileage FROM fillups WHERE carId = \"%d\" ORDER BY date asc",
carId]
table:#"fillups"];
You are never instantiating columnNames. Thus, your attempt to add column names to that array will not succeed. To remedy this, when you declare it, you want to instantiate the mutable array object, too:
NSMutableArray *columnNames = [NSMutableArray array];
Unrelated to this problem, when you're done retrieving the column names, before you prepare your second statement, don't forget to release the memory associated with the first prepared statement:
sqlite3_finalize(statement);
Finally, when you're done retrieving the second prepared SQL statement, rather than calling sqlite3_reset, you want to call sqlite3_finalize again for that second prepared statement. The sqlite3_reset is used to reset a statement when you want to bind new values to ? placeholders in a statement, which is not applicable here, so no sqlite3_reset is needed. But if you don't call sqlite3_finalize, you're not releasing the memory associated with the prepared statement.
By the way, if you wanted to dynamically retrieve the column names and column types (without having to do PRAGMA table_info), you could do something like:
int rc;
if ((rc = sqlite3_prepare_v2(database, [query UTF8String], -1, &statement, NULL)) != SQLITE_OK) {
NSLog(#"select failed %d: %s", rc, sqlite3_errmsg(database));
}
NSMutableArray *returnArray = [NSMutableArray array];
NSInteger columnCount = sqlite3_column_count(statement);
id value;
while ((rc = sqlite3_step(statement)) == SQLITE_ROW) {
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
for (NSInteger i = 0; i < columnCount; i++) {
NSString *columnName = [NSString stringWithUTF8String:sqlite3_column_name(statement, i)];
switch (sqlite3_column_type(statement, i)) {
case SQLITE_NULL:
value = [NSNull null];
break;
case SQLITE_TEXT:
value = [NSString stringWithUTF8String:(const char *)sqlite3_column_text(statement, i)];
break;
case SQLITE_INTEGER:
value = #(sqlite3_column_int64(statement, i));
break;
case SQLITE_FLOAT:
value = #(sqlite3_column_double(statement, i));
break;
case SQLITE_BLOB:
{
NSInteger length = sqlite3_column_bytes(statement, i);
const void *bytes = sqlite3_column_blob(statement, i);
value = [NSData dataWithBytes:bytes length:length];
break;
}
default:
NSLog(#"unknown column type");
value = [NSNull null];
break;
}
dictionary[columnName] = value;
}
[returnArray addObject:dictionary];
}
if (rc != SQLITE_DONE) {
NSLog(#"error returning results %d %s", rc, sqlite3_errmsg(database));
}
sqlite3_finalize(statement);
How to retrieve data from sqlite database? Getting return value zero.
-(id)init{
if(self==[super init]){
database=nil;
}
return self;
}
-(void)addDetails:(NSString *)_name withAddress:(NSString *)_address withAge:(int)_age withMobile:(double)_mobile{
// NSLog(#"in db class --->%# %# %d %f",_name,_address,_age,_mobile);
// NSString *name=#"...has done it";
if([self openDBConnection] == TRUE) {
const char *sql= "insert into Personal (Name,Address,Age,Mobiel) Values(?, ?, ?, ?)";
sqlite3_stmt *updateUser_stmt = nil;
NSInteger retVal = sqlite3_prepare_v2(database, sql, -1, &updateUser_stmt, NULL);
NSLog(#"the return value is %d",retVal);
if(retVal == SQLITE_OK)
{
sqlite3_bind_text (updateUser_stmt , 1, [_name UTF8String],-1,SQLITE_STATIC);
sqlite3_bind_text (updateUser_stmt , 2, [_address UTF8String], -1, SQLITE_STATIC);
sqlite3_bind_int(updateUser_stmt, 3, _age);
sqlite3_bind_double(updateUser_stmt, 4, _mobile);
// sqlite3_bind_text (updateUser_stmt , 4, [HomeUserDetails.strName UTF8String], -1, SQLITE_STATIC);
NSInteger resultInt = sqlite3_step(updateUser_stmt );
if(SQLITE_DONE != resultInt)
NSLog(#"Error while inserting data. '%s'", sqlite3_errmsg(database));
else
{
NSLog(#"MyA user details added to database");
}
}
sqlite3_reset(updateUser_stmt );
sqlite3_finalize(updateUser_stmt );
updateUser_stmt = nil;
}
}
-(void) modifyUserDetails :(Person *)_person
{
NSLog(#"in update");
if([self openDBConnection] == TRUE)
{
NSString *str = [NSString stringWithFormat:#"UPDATE Personal SET Address='%#', Age='%d' , Mobiel='%d' WHERE Name='%#'",
_person.address, [_person getAge], [_person getMobile], _person.name];
NSLog(#" String :%#",str);
//NSString *str = [NSString stringWithFormat:#"UPDATE Room SET Access=1 WHERE RoomName='%#'",room.m_roomName];
const char *sql = [str UTF8String];
// [NSString stringWithFormat:#"UPDATE Room SET Access=%d WHERE RoomName=%#", access,room.m_roomName];
sqlite3_stmt *updateUser_stmt = nil;
if(sqlite3_prepare_v2(database, sql, -1, &updateUser_stmt, NULL) == SQLITE_OK)
{
sqlite3_bind_text(updateUser_stmt, 1, [_person.name UTF8String], -1, SQLITE_STATIC);
sqlite3_bind_text(updateUser_stmt, 2, [_person.address UTF8String], -1, SQLITE_STATIC);
sqlite3_bind_int(updateUser_stmt, 3, [_person getAge]);
sqlite3_bind_double(updateUser_stmt, 4, [_person getMobile]);
if(SQLITE_DONE != sqlite3_step(updateUser_stmt))
NSLog(#"Error while updating data data. '%s'", sqlite3_errmsg(database));
}
sqlite3_reset(updateUser_stmt );
sqlite3_finalize(updateUser_stmt );
updateUser_stmt = nil;
}
}
-(void)getUserDetails
{
UIApplication *app=[UIApplication sharedApplication];
appdlegate=app.delegate;
if(appdlegate.arrayNames)
[appdlegate.arrayNames removeAllObjects];
NSLog(#"in get users");
if([self openDBConnection] == TRUE)
{
const char *sql = "select Name,Address,Age,Mobiel from Personal";//AccessLevel,HintA HintQ,Name,pwd
sqlite3_stmt *getAccess_stmt = nil;
NSInteger retVal = sqlite3_prepare_v2(database, sql, -1, &getAccess_stmt, NULL);
if(retVal == SQLITE_OK)
{
while(sqlite3_step(getAccess_stmt) == SQLITE_ROW)
{
char* name = (char*) sqlite3_column_text(getAccess_stmt, 0);
NSString *tmp;
if (name != NULL){
tmp = [NSString stringWithUTF8String:name];
NSLog(#"value form db :%#",tmp);
}
[appdlegate.arrayNames addObject:tmp];
char *addrs = (char*) sqlite3_column_text(getAccess_stmt, 1);
if (addrs != NULL){
NSString *tmp = [NSString stringWithUTF8String:addrs];
NSLog(#"value from db :%#",tmp);
}
int age =sqlite3_column_int(getAccess_stmt,2);
if(age){
NSLog(#"age from db: %d",age);
}
int mobile=sqlite3_column_double(getAccess_stmt, 3);
;
if(mobile){
NSLog(#"mobile from db: %d",mobile);
}
}
}
sqlite3_reset(getAccess_stmt );
sqlite3_finalize(getAccess_stmt );
getAccess_stmt = nil;
}
}
-(Person *)getPerticular:(NSString *)_name
{
Person *person;
UIApplication *app=[UIApplication sharedApplication];
appdlegate=app.delegate;
NSLog(#"in get users");
if([self openDBConnection] == TRUE)
{
NSString *query = [NSString stringWithFormat:#"select *from Personal where name ='%#'",_name];
const char *sql =[query cStringUsingEncoding:NSASCIIStringEncoding];
//const char *sql = "select *from Personal where name=''";//AccessLevel,HintA HintQ,Name,pwd
sqlite3_stmt *getAccess_stmt = nil;
NSInteger retVal = sqlite3_prepare_v2(database, sql, -1, &getAccess_stmt, NULL);
if(retVal == SQLITE_OK)
{
person=[[Person alloc]init];
while(sqlite3_step(getAccess_stmt) == SQLITE_ROW)
{
char* name = (char*) sqlite3_column_text(getAccess_stmt, 0);
NSString *tmp;
if (name != NULL){
tmp = [NSString stringWithUTF8String:name];
NSLog(#"value perticular form db :%#",tmp);
person.name=tmp;
}
char *addrs = (char*) sqlite3_column_text(getAccess_stmt, 1);
if (addrs != NULL){
NSString *tmp = [NSString stringWithUTF8String:addrs];
NSLog(#"value perticular from db :%#",tmp);
person.address=tmp;
}
int age =sqlite3_column_int(getAccess_stmt,2);
if(age){
NSLog(#"perticular age from db: %d",age);
[person setAge:age];
}
int mobile=sqlite3_column_double(getAccess_stmt, 3);
;
if(mobile){
NSLog(#"mobile from db: %d",mobile);
[person setMobile:mobile];
}
}
}
sqlite3_reset(getAccess_stmt );
sqlite3_finalize(getAccess_stmt );
getAccess_stmt = nil;
}
return person;
}
-(void)createConnection{
NSError *error;
NSArray *strdest=[NSArray arrayWithObjects:NSHomeDirectory(),#"Documents",DB_NAME,nil];
dest=[NSString pathWithComponents:strdest];
NSFileManager *manager=[NSFileManager defaultManager];
NSArray *strSrc=[NSArray arrayWithObjects:NSHomeDirectory(),#"SqlliteDemo.app",DB_NAME, nil];
NSString *source=[NSString pathWithComponents:strSrc];
BOOL sucess=[manager fileExistsAtPath:dest];
if(sucess){
NSLog(#"alredy db copied to documents");
}
else {
[manager copyItemAtPath:source toPath:dest error:&error];
if(error){
NSLog(#"NO Error");
}
else{
NSLog(#"error is %#",error);
}
}
}
-(BOOL)openDBConnection{
[self createConnection];
if(!database){
if(sqlite3_open([dest UTF8String], &database)==SQLITE_OK){
return TRUE;
}else {
return FALSE;
}
}
return TRUE;
}
-(void)finalizeStatements{
if(database)sqlite3_close(database);
}
Think so there is some problem in your Query shown below, please cross check the same query in the command line. Even see if u have properly added the db file in ur project, that too may create some problem.
NSString *query = [NSString stringWithFormat:#"select *from Personal where name ='%#'",_name];