Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9032397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:58:24+00:00 2026-06-16T07:58:24+00:00

i am trying to run this query but neither NSLog is working nor the

  • 0

i am trying to run this query but neither NSLog is working nor the alert is showing .. query does not executes it does not gets into the if loop

viewDidLoad{


pin_lat = pinAnnotation.coordinate.latitude;

NSLog(@"pin latitude is %f",pin_lat); //This one is only working

sqlite3_stmt *statement;

         NSString *qsql = [NSString stringWithFormat:@"SELECT name FROM site WHERE latitude LIKE %f AND longitude LIKE %f",pin_lat,pin_long];

   if (sqlite3_open([qsql UTF8String], &db) == SQLITE_OK){
     //  sqlite3_exec(db, [statement UTF8String],NULL, NULL, &err == SQLITE_OK);

         NSLog(@"QUERY IS WORKING IN OPEN DB");

    if (sqlite3_prepare_v2(db, [qsql UTF8String], -1, &statement, nil)== SQLITE_OK)
    {
         NSLog(@"QUERY IS WORKING IN DB PREPARE");

        while(sqlite3_step(statement)==SQLITE_ROW)
        {
            /* char *field1 = (char *) sqlite3_column_text(statement, 3);  getting name value in field1
             NSString *field1Str =
             [[NSString alloc] initWithUTF8String: field1];
             [field1Str release];*/

            NSLog(@"QUERY IS WORKING");

            UIAlertView *alert_pin = [[UIAlertView alloc] initWithTitle:@"" message:@"Cannot create a duplicate location" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Done", nil];

            [alert_pin show];
            [alert_pin release];


        }

        //—-deletes the compiled statement from memory—-
        sqlite3_finalize(statement);
    }

    else{

        [mapView addAnnotation:pinAnnotation];  // this is working ... but i want the if loop to also work

    }

}

 sqlite3_close(db);
 // not exist to show alert
}

what is wrong with my query why is it not executing the query and opening the DB or printing the Log’s inside the if loop … can any one correct my code .. any help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T07:58:25+00:00Added an answer on June 16, 2026 at 7:58 am

    Midhun is correct. I’d further advise that each of these if statements should have a corresponding else clause that displays the return code as well as, if possible, the error message. Or, equivalently, check for failure at each step and, if so, report diagnostic information and return. Thus, it might look like:

    int rc;
    sqlite3_stmt *statement;
    
    NSString *qsql = [NSString stringWithFormat:@"SELECT name FROM site WHERE latitude LIKE %f AND longitude LIKE %f",pin_lat,pin_long];
    
    if ((rc = sqlite3_open([path UTF8String], &db)) != SQLITE_OK) {
        NSLog(@"%s sqlite3_open failed: (%d)", __FUNCTION__, rc);
        return;
    }
    
    NSLog(@"QUERY IS WORKING IN OPEN DB");
    
    if ((rc = sqlite3_prepare_v2(db, [qsql UTF8String], -1, &statement, nil)) != SQLITE_OK) {
        NSLog(@"%s sqlite3_prepare_v2 failed: \"%s\" (%d)", __FUNCTION__, sqlite3_errmsg(db), rc);
        sqlite3_close(db);
        return;
    }
    
    NSLog(@"QUERY IS WORKING IN DB PREPARE");
    
    while ((rc = sqlite3_step(statement)) == SQLITE_ROW)
    {
        const char *field0 = (const char *)sqlite3_column_text(statement, 0); // getting name value in field1
        NSString *field0Str = [NSString stringWithUTF8String:field0];
    
        NSLog(@"QUERY IS WORKING: %@", field0Str);
    
        UIAlertView *alert_pin = [[UIAlertView alloc] initWithTitle:@"" message:@"Cannot create a duplicate location" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Done", nil];
    
        [alert_pin show];
        [alert_pin release];
    }
    
    if (rc != SQLITE_DONE)
    {
        NSLog(@"%s sqlite3_step failed: \"%s\" (%d)", __FUNCTION__, sqlite3_errmsg(db), rc);
        sqlite3_finalize(statement);
        sqlite3_close(db);
    }
    
    if ((rc = sqlite3_finalize(statement)) != SQLITE_OK) {
        NSLog(@"%s sqlite3_finalize failed: \"%s\" (%d)", __FUNCTION__, sqlite3_errmsg(db), rc);
        sqlite3_finalize(statement);
        sqlite3_close(db);
    }
    
    sqlite3_close(db);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to run this query but is not working. I am getting
I am trying to run this query but myfield does not contain the full
Hi I am trying to run this query in SQL but it is not
I am trying to run this simple SELECT query using PDO::MySQL, but it does
I am trying to run this query, but it seems like it's not formatting
I am trying to run this query to SQlite database but its not executing
I'm trying to run this query but I get ORA-00904: Z1.LONGITUDE: invalid identifier Is
I am trying to run this delete query against a local Access tables, but
I am trying to run this query on http://dbpedia.org/sparql but I get an error
I have this query I am trying to run but I keep running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.