NSString *path = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"branddb.sqlite"];
sqlite3 *database;
sqlite3_open([path UTF8String], &database);
sqlite3_stmt *statement;
const char *getTableInfo = "select * from sqlite_master where type='table' order by name";
sqlite3_prepare_v2(database, getTableInfo, -1, &statement, nil);
while (sqlite3_step(statement) == SQLITE_ROW) {
char *nameData = (char *)sqlite3_column_text(statement, 1);
NSString *tableName = [[NSString alloc] initWithUTF8String:nameData];
NSLog(@"name:%@",tableName);
}
const char *getColumn = "PRAGMA table_info(menu)";
sqlite3_prepare_v2(database, getColumn, -1, &statement, nil);
while (sqlite3_step(statement) == SQLITE_ROW) {
char *nameData = (char *)sqlite3_column_text(statement, 1);
NSString *columnName = [[NSString alloc] initWithUTF8String:nameData];
NSLog(@"columnName:%@",columnName);
}
sqlite3_finalize(statement);
/****************************华丽的分割线********************************/
关键代码:
查询数据库内的表名
select * from sqlite_master where type='table' order by name
/****************************华丽的分割线********************************/
查询表内的字段名
PRAGMA table_info(menu)