Why is SQLite record not found? - objective-c

I am trying to program a username/password log in view controller, there is no errors, no warnings in my app but it always output out "match not found" even when i select a username that already exist in my database..I'd really appreciate it if u could help
this is the code:
[super viewDidLoad];
NSString *docsDir;
NSArray *dirPaths;
// Get the documents directory
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = dirPaths [0];
_databasePath = [[NSString alloc]initWithString:[docsDir stringByAppendingPathComponent:#"bank.db"]];
NSFileManager *filemgr = [NSFileManager defaultManager];
if ([filemgr fileExistsAtPath:_databasePath] == NO)
{
const char *dbpath = [_databasePath UTF8String];
if (sqlite3_open(dbpath, &_bankDb) == SQLITE_OK)
{
char *errMsg;
const char *sql_stmt = " CREATE TABLE IF NOT EXISTS USER (USERNAME TEXT PRIMARY KEY, PASSWORD TEXT)";
if (sqlite3_exec(_bankDb, sql_stmt, NULL, NULL, &errMsg) != SQLITE_OK)
{
_status.text= #"failed to create table";
}
sqlite3_close(_bankDb);
} else {
_status.text=#"failed to open/create database";
}
}
- (IBAction)findContact:(id)sender {
const char *dbpath = [_databasePath UTF8String];
sqlite3_stmt *statement;
if (sqlite3_open(dbpath, &_bankDb) == SQLITE_OK)
{
NSString *querySQL = [NSString stringWithFormat:#"SELECT USERNAME, PASSWORD FROM USER WHERE USERNAME=\"%#\"", _usernameTextField.text];
const char *query_stmt = [querySQL UTF8String];
if (sqlite3_prepare_v2(_bankDb, query_stmt, -1, &statement, NULL) == SQLITE_OK)
{
if (sqlite3_step(statement) == SQLITE_ROW)
{
NSString *usernameField=[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 0)];
_usernameTextField.text=usernameField;
NSString *passwordField = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 1) ];
_passwordTextField.text=passwordField;
_status.text=#"match found";
} else {
_status.text=#"match not found";
}
sqlite3_finalize(statement);
}
sqlite3_close(_bankDb);
}
}

You should do the following things,
look at sqlite3_errmsg values if any queries fail (e.g. sqlite3_prepare_v2 does not return SQLITE_OK or sqlite3_step does not return either SQLITE3_DONE or SQLITE3_ROW);
Do not use stringWithFormat with your queries, but rather use ? placeholders and bind values with sqlite3_bind_text
Thus:
if (sqlite3_open(dbpath, &_bankDb) == SQLITE_OK)
{
const char *query_stmt = "SELECT USERNAME, PASSWORD FROM USER WHERE USERNAME=?";
if (sqlite3_prepare_v2(_bankDb, query_stmt, -1, &statement, NULL) != SQLITE_OK)
NSAssert(0, #"prepare failed: %s", sqlite3_errmsg(_bankDb));
if (sqlite3_bind_text(statement, 1, [_usernameTextField.text UTF8String], -1, NULL) != SQLITE_OK)
NSAssert(0, #"bind failed: %s", sqlite3_errmsg(_bankDb));
int rc = sqlite3_step(statement);
if (rc == SQLITE_ROW)
{
NSString *usernameField=[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 0)];
_usernameTextField.text=usernameField;
NSString *passwordField = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 1) ];
_passwordTextField.text=passwordField;
_status.text=#"match found";
} else if (rc == SQLITE_DONE) {
_status.text=#"match not found";
} else {
NSAssert(0, #"step failed: %s", sqlite3_errmsg(_bankDb));
}
sqlite3_finalize(statement);
sqlite3_close(_bankDb);
}
If you're still failing with match not found, you should:
examine the contents of _usernameTextField.text to make sure your IBOutlet is hooked up correctly.
look at the contents of the database and make sure a record with the desired userid is found; you haven't shown us where you add the userid, so it's hard for us to diagnose why the userid in question was not found.
I must confess that the overall logic (just looking for matching records for that userid and populating the password field if you found the userid) looks highly suspect (you shouldn't be storing passwords in plaintext, you certainly shouldn't be returning a password provided simply a userid), but I'm focusing solely on the tactical issue of why you're seeing match not found error message.

Related

Objective C Sqlite Update Query Based on ID

Trying to learn Sqlite without using a wrapper and have managed most things but am really stuck on UPDATE queries
I am trying to update a sting in one column based on its _ID number which is the primary Key and is unique.
I have tried all sorts of code from all over google . This one says it has worked but when I check the column has not been updated
here is the code
NSDateFormatter *formatter;
NSString *dateString;
formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:#"dd-MM-yyyy HH:mm"];
dateString = [formatter stringFromDate:[NSDate date]];
NSString *IDCODE = code.stringValue;
NSInteger b = [IDCODE integerValue];
sqlite3 *contactDB; //Declare a pointer to sqlite database structure
const char *dbpath = [dbPath UTF8String]; // Convert NSString to UTF-8
if (sqlite3_open(dbpath, &contactDB) == SQLITE_OK)
{
//Database opened successfully
NSString *databaseName = #"vistorlog.db";
// Get the path to the documents directory and append the databaseName
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
NSString *databasePath = [documentsDir stringByAppendingPathComponent:databaseName];
const char *dbPath=[databasePath UTF8String];
if (sqlite3_open(dbPath, &myDB)==SQLITE_OK) {
NSLog(#"database Opened");
const char* updateQuery="update LOG set TIMEOUT='22/03/19' where _ID=1";
sqlite3_stmt *stmt;
if (sqlite3_prepare_v2(myDB, updateQuery, -1, &stmt, NULL)==SQLITE_OK) {
NSLog(#"Query Executed");
}else{
NSLog(#"Query NOT Executed");
}
}
sqlite3_close(myDB);
}
else {
//Failed to open database
}
It opens the DB vistorlog.db ok. There is a table called LOG and there is column called TIMEOUT which is where I want the string to be updated and there is a column called _ID which is what Im basing the query on yet it won't update
eventually I want to have the update statement use the string variable dateString as the string to update and b as the integer variable for the _ID
any ideas where Im going wrong?
Any help appreciated
Mark
EDIT
WORKING CODE TO UPDATE A QUERY
sqlite3 *contactDB; //Declare a pointer to sqlite database structure
const char *dbpath = [dbPath UTF8String]; // Convert NSString to UTF-8
if (sqlite3_open(dbpath, &contactDB) == SQLITE_OK)
{
//Database opened successfully
NSString *databaseName = #"vistorlog.db";
// Get the path to the documents directory and append the databaseName
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
NSString *databasePath = [documentsDir stringByAppendingPathComponent:databaseName];
const char *dbPath=[databasePath UTF8String];
if (sqlite3_open(dbPath, &myDB)==SQLITE_OK) {
NSLog(#"database Opened");
// define dateString and IDCODE as strings before this
const char *updateQuery = "Update log set TIMEOUT=? where _ID=?";
sqlite3_stmt *stmt;
// Prepare Stment
if (sqlite3_prepare_v2(myDB, updateQuery, -1, &stmt, NULL) == SQLITE_OK) {
sqlite3_bind_text(stmt, 1, [dateString UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 2, [IDCODE UTF8String], -1, SQLITE_TRANSIENT); if(sqlite3_step(stmt) == SQLITE_DONE) {
NSLog(#"Query Executed");
} else {
NSLog(#"Query NOT Executed: %s", sqlite3_errmsg(myDB));
}
sqlite3_finalize(stmt);
}else{
NSLog(#"Statement NOT Prepared: %s", sqlite3_errmsg(myDB));
}
}
sqlite3_close(myDB);
}
else {
//Failed to open database
}
Don't forget to import sqlite3.h
Mark
You are only preparing the statement but not actually executing it.
You need to execute sqlite3_step() after you execute sqlite3_prepare_v2
if (sqlite3_prepare_v2(myDB, updateQuery, -1, &stmt, NULL) == SQLITE_OK) {
if(sqlite3_step(stmt) == SQLITE_DONE) {
NSLog(#"Query Executed");
} else {
NSLog(#"Query NOT Executed: %s", sqlite3_errmsg(myDB));
}
sqlite3_finalize(stmt);
}else{
NSLog(#"Statement NOT Prepared: %s", sqlite3_errmsg(myDB));
}

Can't insert " character into Sqlite DB [Objective-C]

I'm inserting some data on a sqlite db, It works fine but what I noticed is that I can't insert words that contains the character ", is it a common issue? should I change parse the text and edit every " character I find?
This is the code i'm using in order to insert data into my DB:
UICollectionViewCell *cell = (UICollectionViewCell *)button.superview.superview;
NSIndexPath *indexPath = [self.customCollectionView indexPathForCell:cell];
FolderProducts *item = _feedItems[indexPath.item];
sqlite3_stmt *statement;
const char *dbpath = [databasePath UTF8String];
if (sqlite3_open(dbpath, &Carrello) == SQLITE_OK)
{
NSString *insertSQL = [NSString stringWithFormat: #"INSERT INTO CarrelloMese (titolo, codice, prezzo, urlImg) VALUES (\"%#\", \"%#\", \"%#\", \"%#\")",item.nomeProdotto, item.codice, item.prezzo, item.urlImg];
const char *insert_stmt = [insertSQL UTF8String];
sqlite3_prepare_v2(Carrello, insert_stmt, -1, &statement, NULL);
if (sqlite3_step(statement) == SQLITE_DONE)
{
} else {
}
sqlite3_finalize(statement);
sqlite3_close(Carrello);
}
You need to bind your SQLite statements using the sqlite3_bind_xxx() function. Basically, you remove all variables from your statement (in your case the %#) and replace them with '?'. SQLite then knows that where an ? is HAS to be a variable, and therefore doesn't get it mixed up with a command.
For example, say you wanted to bind the word "INSERT". Using ? SQLite won't read this as a command and then flag an error.
Read the docs (link above) for full information on how to use the bind function.
Here's what your code might look like with binding (UNTESTED):
sqlite3_stmt *statement;
const char *dbpath = [databasePath UTF8String];
if (sqlite3_open(dbpath, &Carrello) == SQLITE_OK)
{
NSString *insertSQL = [NSString stringWithFormat: #"INSERT INTO CarrelloMese (titolo, codice, prezzo, urlImg) VALUES (?,?,?,?)"];
const char *insert_stmt = [insertSQL UTF8String];
sqlite3_prepare_v2(Carrello, insert_stmt, -1, &statement, NULL);
if (sqlite3_bind_text(statement, 0, item.nomeProdotto.UTF8String, item.nomeProdotto.length, SQLITE_STATIC) != SQLITE_OK) {
NSLog(#"An error occurred");
}
// Etc etc
// SQLite bind works like this: sqlite_bind_text/int/e.t.c(sqlite3_stmt,index_of_variable, value);
// there are optionally parameters for text length and copy type SQLITE_STATIC and SQLITE_TRANSIENT.
if (sqlite3_step(statement) == SQLITE_DONE)
{
} else {
}
sqlite3_finalize(statement);
sqlite3_close(Carrello);
}

Delete data in SQLite

I want to delete record from database,
I define in file.h the database, and in the file.m the insert data and read data it's work, but the delete was not work.
this is the file.h
#import "sqlite3.h"
#define DATA_FILE #"prova12"
#define TABLE_NAME #"password"
#define FIELDS_NAME_SID #"pass"
#define FIELDS_NAME_SNAME #"foto"
#define FIELDS_NAME_SCLASS #"studentClass"
#define FIELDS_NAME_PROVA #"provaClass"
{sqlite3 *db;
}
in the file.m
for the path:
-(NSString *)dataFilePath {
NSArray * myPaths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory,NSUserDomainMask, YES); NSString * myDocPath = [myPaths objectAtIndex:0];
NSString *filename = [myDocPath stringByAppendingPathComponent:DATA_FILE];
return filename;
for read:
-(NSMutableArray*)selectAll
{
NSMutableArray *list = [[NSMutableArray alloc] initWithObjects:nil];
NSString *filename = [self dataFilePath];
NSLog(#"%#",filename);
if (sqlite3_open([filename UTF8String], &db) != SQLITE_OK) {
sqlite3_close(db);
NSAssert(NO,#"no");
} else {
NSString *qsql = [NSString stringWithFormat: #"SELECT %# FROM %#", FIELDS_NAME_SID, TABLE_NAME];
NSLog(#"qui%#",qsql);
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(db, [qsql UTF8String], -1, &statement, NULL) == SQLITE_OK) {
sqlite3_bind_text(statement, 1, [inserisci.text UTF8String], -1, NULL);
while (sqlite3_step(statement) == SQLITE_ROW) {
char *field1 = (char *) sqlite3_column_text(statement, 0);
NSString *field1Str = [[NSString alloc] initWithUTF8String: field1];
//studentId.text = field1Str;
//[field1Str release];
[list addObject:field1Str];
NSLog(#"%d",list.count);
}
}
sqlite3_finalize(statement);
sqlite3_close(db);
}
return list;
}
and this for save:
-(IBAction) save {
NSString *filename = [self dataFilePath];
if (sqlite3_open([filename UTF8String], &db) != SQLITE_OK) {
sqlite3_close(db);
NSAssert(NO,#"no");
} else {
NSString *sqlStr = [NSString stringWithFormat: #"INSERT OR REPLACE INTO %# (%#, %#, %# ,%#) VALUES (?,?,?,?)",
TABLE_NAME, FIELDS_NAME_SID, FIELDS_NAME_SNAME, FIELDS_NAME_SCLASS, FIELDS_NAME_PROVA];
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(db, [sqlStr UTF8String], -1, &statement, NULL) == SQLITE_OK) {
NSLog(#"quiiiiddddd %#", filename);
sqlite3_bind_text(statement, 1, [inserisci.text UTF8String], -1, NULL);
sqlite3_bind_text(statement, 2, [immagine UTF8String], -1, NULL);
sqlite3_bind_text(statement, 3, [inserisci.text UTF8String], -1, NULL);
sqlite3_bind_text(statement, 4, [inserisci.text UTF8String], -1, NULL);
if (sqlite3_step(statement) != SQLITE_DONE) {
NSAssert(0, #"no");
}
}
sqlite3_finalize(statement);
sqlite3_close(db);
}
but I don't have an idea to delete data, can anyone please help me?
you want to delete all record ore selected
-(bool)deleteEvent:(int)eventID
{
DBSettings *dbSettings = [[DBSettings alloc]init];
[dbSettings checkAndCreateDatabase];
DatabaseName=dbSettings.DBName;
DatabasePath=dbSettings.DBPath;
[dbSettings release];
sqlite3 *database;
if(sqlite3_open([DatabasePath UTF8String], &database) == SQLITE_OK)
{
const char *sqlStatement;
NSString *query = [NSString stringWithFormat:#"%#'%i'",kDeleteQuery,eventID];
//Convert NSString to char pointer for execution
sqlStatement=[query UTF8String];
if(sqlite3_prepare_v2(database, sqlStatement, -1, &deleteStmt, NULL) != SQLITE_OK)
NSAssert1(0, #"Error while creating add statement. '%s'", sqlite3_errmsg(database));
if(SQLITE_DONE != sqlite3_step(deleteStmt))
{
NSAssert1(0, #"Error while deleting data. '%s'", sqlite3_errmsg(database));
}
sqlite3_finalize(deleteStmt);
sqlite3_close(database);
return YES;
}
return NO;
}
kDeleteQuery "Is your query for all record or selected"
-(void)deleteDetails:(int *)detailId
{
if (sqlite3_open([filename UTF8String], &db) != SQLITE_OK)
{
sqlite3_close(db);
}
else
{
sqlite3_stmt *statement;
NSString *strSQL =[NSString stringWithFormat:#"DELETE FROM tablename WHERE id = %d", detailId];
mainSql = [strSQL UTF8String];
if(sqlite3_prepare_v2(db, mainSql , -1, &statement, NULL)==SQLITE_OK)
{
while(sqlite3_step(statement) == SQLITE_ROW)
{
NSLog(#"Records are deleted");
}
}
else
{
NSLog(#"Error : -------'%s'", sqlite3_errmsg(db));
}
}
sqlite3_reset(statement);
sqlite3_finalize(statement);
sqlite3_close(db);
}

SQLite, Objective C: method returns int max value

-(int)countTheNumberOfDublicatesForType:(int)typeID
{
NSInteger quantity=0;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:user_data];
sqlite3* database = NULL;
sqlite3_stmt *statement;
if(sqlite3_open([path UTF8String], &database) == SQLITE_OK)
{
const char *sqlQuery=sqlite3_mprintf("SELECT COUNT(refID)\
FROM dublicates\
WHERE typeREF=%i",typeID);
if(sqlite3_prepare_v2(database, sqlQuery,-1, &statement, NULL) == SQLITE_OK)
sqlite3_bind_int(statement, 1,typeID);
if(sqlite3_step(statement) == SQLITE_ROW)
{
quantity = sqlite3_column_int(statement, 0);
}
sqlite3_finalize(statement);
sqlite3_free((char*)sqlQuery);
sqlite3_close(database);
}
else
{
//
}
return quantity;
}
The math in this method returns the max value of int. Where's the mistake and how to manage it the way it would return the real values from db? Thank you in advance.
EDIT:
You have no error handling, you are binding to a nonexistent parameter, the code is indented wrong, and you are reading with a wrong data type.
Use something like this:
if (sqlite3_open([path UTF8String], &database) != SQLITE_OK) {
sqlite3_errmsg(database); // log or print this
sqlite3_close(database);
return 0;
}
if (sqlite3_prepare_v2(database,
"SELECT COUNT(refID) FROM dublicates WHERE typeREF=?",
-1, &statement, NULL) != SQLITE_OK) {
sqlite3_errmsg(database); // log or print this
sqlite3_close(database);
return 0;
}
sqlite3_bind_int(statement, 1, typeID);
if (sqlite3_step(statement) != SQLITE_ROW)
sqlite3_errmsg(database); // log or print this
else
quantity = sqlite3_column_int(statement, 0);
sqlite3_finalize(statement);
sqlite3_close(database);

How to call different tables in an "if and else" part of the same database in iPhone?

I have a database. It has two tables in it. I want to call one table in an if condition. How do I call the second table in the else part if the if conditions fail?
This is the code I used:
{
NSArray *Paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *DocumentsDirectory = [Paths objectAtIndex:0];
NSString *Path = [DocumentsDirectory stringByAppendingPathComponent:#"StoreList.sqlite"];
// Open the database from the users filessytem.
if (sqlite3_open([Path UTF8String], &database) == SQLITE_OK) {
// Setup the SQL Statement and compile it for faster access
//*********const char *sqlStatement = "select * from Store where Zipcode ='%#'",inputTxt ;
NSString *sqlStatement = [NSString stringWithFormat:#"select * from Store where Zipcode ='%#' or Address = '%#' or CityName = '%#'",inputTxt, inputTxt, inputTxt];
NSLog(#" Query in if :%#",sqlStatement);
sqlite3_stmt *compiledStatement;
if (sqlite3_prepare_v2(database, [sqlStatement UTF8String], -1, &compiledStatement, NULL) == SQLITE_OK) {
// Loop through the results and add them to the feeds array.
if(sqlite3_step(compiledStatement) == SQLITE_ROW) {
// Read the data from the result row
NSString *latValue = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
NSLog(#"Latitude:%#",latValue);
NSString *longValue = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)];
NSLog(#"Longitude:%#",longValue);
//currentLocationLbl.text=[NSString stringWithFormat:#" %# , %#" ,latValue,longValue];
// delegate.latitudeVal=latValue;
// delegate.longitudeVal=longValue;
txtChangeLocation.text = #"";
isFromChangeLoc=TRUE;
//self.tabBarController.selectedIndex=3;
}
else {
NSLog(#"ELSE PART");
// Open the database from the user's filessytem.
if (sqlite3_open([Path UTF8String], &database) == SQLITE_OK) {
// Setup the SQL Statement and compile it for faster access
//*********const char *sqlStatement = "select * from Store where Zipcode ='%#'",inputTxt ;
NSString *sqlStatement = [NSString stringWithFormat:#"select * from zipcodes where zip ='35004'"];
NSLog(#" Query in if :%#",sqlStatement);
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, [sqlStatement UTF8String], -1, &compiledStatement, NULL) == SQLITE_OK) {
// Loop through the results and add them to the feeds array
if(sqlite3_step(compiledStatement) == SQLITE_ROW) {
// Read the data from the result row
NSString *latValue = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
NSLog(#"Latitude:%#",latValue);
NSString *longValue = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)];
NSLog(#"Longitude:%#",longValue);
//currentLocationLbl.text=[NSString stringWithFormat:#" %# , %#" ,latValue,longValue];
// delegate.latitudeVal=latValue;
// delegate.longitudeVal=longValue;
txtChangeLocation.text = #"";
isFromChangeLoc=TRUE;
}
}
}
}
sqlite3_finalize(compiledStatement);
sqlite3_close(database);
}
}
I'm getting the input from the text box. When I give the correct value, which is there in the database, it is working fine, the fetch of the data is correct. If I give the wrong data in the textbox it's not working fine - the else condition fails.
How can this issue be fixed?
When going on else you open the same database again, that's not needed (and might cause some problems as well, haven't tried it). Use a BOOL when running the first (select) statement and set it to YES or NO if it fails or not. After you finish with the first statement check the BOOL value and if ==NO run the second statement.
...
BOOL success = NO;
NSString *sqlStatement = [NSString stringWithFormat:#"select * from Store where Zipcode '%#' or Address = '%#' or CityName = '%#'",inputTxt, inputTxt, inputTxt];
NSLog(#" Query in if :%#",sqlStatement);
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, [sqlStatement UTF8String], -1, &compiledStatement, NULL) == SQLITE_OK){
if(sqlite3_step(compiledStatement) == SQLITE_ROW) {
// Read the data from the result row
NSString *latValue = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
NSLog(#"Latitude:%#",latValue);
NSString *longValue = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)];
NSLog(#"Longitude:%#",longValue);
//currentLocationLbl.text=[NSString stringWithFormat:#" %# , %#" ,latValue,longValue];
// delegate.latitudeVal=latValue;
// delegate.longitudeVal=longValue;
txtChangeLocation.text = #"";
isFromChangeLoc=TRUE;
//self.tabBarController.selectedIndex=3;
success=YES;
}
}
sqlite3_finalize(compiledStatement);
if(success){
//do the else from your code
NSString *sqlStatement = [NSString stringWithFormat:#"select * from zipcodes where zip ='35004'"];
NSLog(#" Query in if :%#",sqlStatement);
if(sqlite3_prepare_v2(database, [sqlStatement UTF8String], -1, &compiledStatement, NULL) == SQLITE_OK){
// Loop through the results and add them to the feeds array
if(sqlite3_step(compiledStatement) == SQLITE_ROW) {
// Read the data from the result row
NSString *latValue = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
NSLog(#"Latitude:%#",latValue);
NSString *longValue = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)];
NSLog(#"Longitude:%#",longValue);
//currentLocationLbl.text=[NSString stringWithFormat:#" %# , %#" ,latValue,longValue];
// delegate.latitudeVal=latValue;
// delegate.longitudeVal=longValue;
txtChangeLocation.text = #"";
isFromChangeLoc=TRUE;
}
}
sqlite3_finalize(compiledStatement);
}
I haven't run it, so it might contain some bugs.