如何在sqlite中按类型获取表
大家好,
我正在从我的数据库中获取所有表格。
我的代码是
if(sqlite3_open([databasePath UTF8String], &database) == 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);
}
,但我需要很少的表需要添加到一个数组中,而铰孔需要添加到另一个数组中。
例如:我有水果、鲜花等表格,还有 list1、list2、list3 等表格。
我需要将水果,鲜花...放入一个数组中,并且需要将列表1,列表2...添加到另一个数组中。因为我正在显示水果,鲜花...中的所有项目,
并且在列表1,列表2中我维护这些类别中所有选定的项目。
但通过使用上面的代码我得到了所有的表列表。
任何人都可以帮助我吗?
(如果有人没有明白我的问题,请让我添加评论)
提前谢谢你。 我怎样才能以不同的方式获得桌子。
HI folks,
i am getting all the tables from mydatabase.
my code is
if(sqlite3_open([databasePath UTF8String], &database) == 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 hasPrefix 测试表名是否以“list”开头:
if ([aName hasPrefix:@"list"]) // true if aName 以“list”开头
[listCategoriesList addObject:aName];
else
[otherCategoriesList addObject:aName];
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];
为了将表分成两组,您需要某种方法来区分它们。要么你事先知道哪些表应该属于list1,要么list1应该包含所有以“f”开头的表,或者所有行数为奇数的表,或者...
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...