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

The Archive Base Latest Questions

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

I need to do a search on all the columns, so instead of specifying

  • 0

I need to do a search on all the columns, so instead of specifying each column name in the where clause I would like to create a method that can search through all the columns.

-(void) fillSomeobjectNames:(NSString *)filter
{
    FMDatabase *db = [FMDatabase databaseWithPath:databasePath];

    [db open];

    NSString *sql = [NSString stringWithFormat:@"SELECT id, name, imagefile FROM %@ %@", mainTableName, filter];
    FMResultSet *results = [db executeQuery:sql];
    while([results next]) 
    {
        Someobject *someobject = [[Someobject alloc] init];
        [someobject setID:[results intForColumn:@"id"]];
        [someobject setName:[results stringForColumn:@"name"]];
        NSString *iconName = [[results stringForColumn:@"imagefile"] stringByReplacingOccurrencesOfString:@".jpg" withString:@""];
        [someobject setIconPath:[NSString stringWithFormat:@"%@-ico.jpg",iconName]];
        [someobjects someobject];
    }

    [db close];
}

‘filter’ can be ‘WHERE remark=[searchText] AND description=[searchText] AND so on…’

  • 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-28T06:23:23+00:00Added an answer on May 28, 2026 at 6:23 am

    I don’t think this can be done with a single SELECT statement. The best way to get column names is PRAGMA table_info(table_name), unfortunately this cannot be used in the SELECT statements, so you need one additional SELECT to get the column names, and then you can build your sql and do what you want:

    -(void) fillSomeobjectNames:(NSString *)filter
        {
            FMDatabase *db = [FMDatabase databaseWithPath:databasePath];
    
            [db open];
    
            FMResultSet columnNamesSet* = [db executeQuery:[NSString stringWithFormat:@"PRAGMA table_info(%@)", mainTableName]];
            NSMutableArray* columnNames = [[NSMutableArray alloc] init];
            while ([columnNamesSet next]) {
                [columnNames addObject:[columnNamesSet stringForColumn:@"name"]];
            }
            // put whatever you need to look for as mySearchPhrase
            NSString* partToAppend = [NSString stringWithFormat:@"=%@ OR ", @"mySearchPhrase"];
            NSString* filter = [columnNames componentsJoinedByString:partToAppend];
            filter = [filter stringByAppendingString:[NSString stringWithFormat:@"=%@", @"mySearchPhrase"]];
    
            // now your sql would look like this
            NSString *sql = [NSString stringWithFormat:@"SELECT id, name, imagefile FROM %@ WHERE %@", mainTableName, filter];
            FMResultSet *results = [db executeQuery:sql];
            while([results next]) 
            {
                Someobject *someobject = [[Someobject alloc] init];
                [someobject setID:[results intForColumn:@"id"]];
                [someobject setName:[results stringForColumn:@"name"]];
                NSString *iconName = [[results stringForColumn:@"imagefile"] stringByReplacingOccurrencesOfString:@".jpg" withString:@""];
                [someobject setIconPath:[NSString stringWithFormat:@"%@-ico.jpg",iconName]];
                [someobjects someobject];
            }
    
            [db close];
        }
    

    Note that I moved WHERE word out of the filter, and also I used OR instead of AND, which is what I think you intended to do.

    One additional thing to keep in mind is the data type in each column. You compare each one to a string, but is each column in your table of type text? The pragma statement that I used also returns the type of the given column (in the column named type), so you could use that to filter the columns that are of type text.

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

Sidebar

Related Questions

I need to search for all users containing a certain text string in their
I need to search a string and replace all occurrences of %FirstName% and %PolicyAmount%
I need all records which have year entered from search criteria. for ex: String
I need to generate all combinations (not permutations) in VB .NET, I've been search
I need to search across multiple columns from two tables in my database using
I need to search a name which is stored in collection. Search criteria: eg:
I have a simple MySQL query that selects all columns from the table based
I need to create a script that will be usable on 10 tables with
So say I have a node structure like: <Row> <Column Name=Primary Number>1</Column> <Column Name=Secondary
If I have a data table like this id, Name, Address, Status How would

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.