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 6138311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:51:22+00:00 2026-05-23T17:51:22+00:00

I am creating an iOS app that reads data from a single SQLITE table

  • 0

I am creating an iOS app that reads data from a single SQLITE table using variables. I don’t have a problem running my select statement when all variables are populated, but I want to eventually have a large amount of variables and allow the users to skip ones that they don’t see as meaningful to them. In other words, how can I make this work even when variables are null or 0 such as ignoring that part of the select statement, but continuing on? I have tried to use IF statements or CASE statements, but then I get the undeclared error. I could repeat the entire getInitialDataToDisplay with IFs, but there has to be an easier way.

+ (void) getInitialDataToDisplay:(NSString *)dbPath{
int addOne = [[NSUserDefaults standardUserDefaults] integerForKey: @"criterion1key"]; 
int addTwo = [[NSUserDefaults standardUserDefaults] integerForKey: @"criterion2key"]; 
int addThree = [[NSUserDefaults standardUserDefaults] integerForKey: @"criterion3key"];      

if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {       
NSString *querystring= [NSString stringWithFormat:@"select * from animalswhere description > %i and description < %i and cash >= %i",addOne, addTwo, addThree];            //WORKS FINE IF ALL VARIABLES HAVE VALUES, BUT DOES NOTHING IF VARIABLES ARE EMPTY            
const char *sql = [querystring UTF8String];             
sqlite3_stmt *selectstmt;  if(sqlite3_prepare_v2(database, sql, -1,&selectstmt, NULL) == SQLITE_OK) 
{                       
while(sqlite3_step(selectstmt) == 
SQLITE_ROW) { 

NSInteger primaryKey = sqlite3_column_int(selectstmt, 0);

    Animal *animal = [[Animal alloc] initWithPrimaryKey:primaryKey];
            animal.name = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 3)];
             animal.description = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 4)];   
        animal.imageURL = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 5)];   
        animal.cash = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 32)]; 
            [appDelegate.animals addObject:animal];             
[animal release];           
}       
   }    
      }         else        sqlite3_close(database); 
}
  • 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-05-23T17:51:22+00:00Added an answer on May 23, 2026 at 5:51 pm

    Sounds like what you need is to use marker variables/values, and a little boolean logic:

    SELECT valuea, valueb, valuec
    FROM table
    WHERE valuea = %inputParmA
    AND (%inputParmB = 0 OR valueb = %inputParmB)
    

    This will have the effect of selecting all rows where valuea matches the passed-in value (of inputParmA), and, if inputParmB is non-zero, valueb matches inputParmB.
    You’ll have to adapt this for your needs, but it’s a quick-and-dirty alternative to using dynamic sql, if this isn’t available (or difficult to generate).
    Not completely sure about performance, but I have a query that has around a dozen of these, operating over a multi-million row database, and returns within a minute (hundreds of results).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app in Flash CS5 that I am creating for iOS. I
I'm using Core data in an iOS project. I have the data model setup
Im creating an RSS reader app...but I have noticed that UIWebView renders the RSS
I’m currently creating an iOS app that uploads files to a server. As multiple
I'm creating an iOS app who will have to stop the standby timer. I
I am looking at creating an app for OS X and/or iOS that allows
I am creating an iOS app using Flex 4.5 (Flash Builder 5.5) and I
I'm creating a basic blog app with rails/mongoid backend and an iOS client that
I am creating an iOS app that displays a web view. How can I
So my intention is to have a login in my iOS app that allows

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.