Search code examples
iphoneiosobjective-csqlitefmdb

Select data from variable_tableName in Sqlite


I am using Fmdb wrapper around Sqlite, everything is working fine. Now I want to load data from a variable table, the table name is stored in an NSString. I don't know how to write query for that. Please help!


Solution

  • I never used FMDB Wrapper. But reading the Documetation, it looks like -executeQuery is a method from FMDatabase Class that takes the QueryString as a parameter and returns an object of FMResultSet Class. So, argument is of NSString type and you can use %@ operator to add the dynamic string values in your QueryString.

    Sample Code :

    FMResultSet *results = nil;
    results = [yourDB executeQuery:[NSString stringWithFormat:@"SELECT * FROM %@",variable_tableName]];