开发者

how to get tables by type in sqlite

开发者 https://www.devze.com 2023-02-19 00:09 出处:网络
HI folks, i am getting all the tables from mydatabase. my code is if(sqlite3_open([databasePath UTF8String], &database开发者_如何学Python) == SQLITE_OK) {

HI folks,

i am getting all the tables from mydatabase.

my code is

if(sqlite3_open([databasePath UTF8String], &database开发者_如何学Python) == SQLITE_OK) {
        // Setup the SQL Statement and compile it for faster access

        const char *sqlStatement = "SELECT * FROM sqlite_master where type='table'";
        sqlite3_stmt *compiledStatement;
        if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
            // Loop through the results and add them to the feeds array
            while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
                // Read the data from the result row
                NSString *aName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];


                [categoriesList addObject:aName];


            }
        }

        // Release the compiled statement from memory
        sqlite3_finalize(compiledStatement);

    }

but i need few of table need to add in one array and reaming are need to add in another array.

for eg: i have tables like fruits,flowers,... And another tables like list1,list2,list3.

i need to get fruits,flowers... into one array and list1,list2... are needed to be added into another array.Because i am displaying all the items in fruits,flowers ....

And in list1,list2 i maintain the all the selected item among these categories.

but by using the above code i am getting all the list of tables.

can any one please help me.

(let me add comment if any one didn't get my question)

Thank u in advance. how can i get tables differently.


You can test that the table name starts with "list" using hasPrefix:

if ([aName hasPrefix:@"list"]) // true if aName starts with "list"

[listCategoriesList addObject:aName];

else

[otherCategoriesList addObject:aName];


In order to separate the tables into two groups, you need some way to distinguish between them. Either you know in advance which tables should belong to list1, or list1 should contain all the tables that start with 'f', or all the tables with an odd number of rows, or...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号