2010-08-25 24 views
0

是否有一种简单的方法从Android中的每个表中获取CREATE字符串,而不是在onCreate覆盖中重新定义它们。我非常恼火,只是为每张桌子解析整个事情,但我希望有一种更简单的方法,我还没有找到。从SQLite3数据库中“创建”字符串

回答

2

使用内置表sqlite_master

sqlite-3.7.2 e$ sqlite3 
SQLite version 3.7.2 
Enter ".help" for instructions 
Enter SQL statements terminated with a ";" 
sqlite> create table t1 (a, b, c integer); 
sqlite> create table t2 (d, e, f text); 
sqlite> select * from sqlite_master; 
table|t1|t1|2|CREATE TABLE t1 (a, b, c integer) 
table|t2|t2|3|CREATE TABLE t2 (d, e, f text) 
sqlite> select sql from sqlite_master; 
CREATE TABLE t1 (a, b, c integer) 
CREATE TABLE t2 (d, e, f text) 

参见:SQLite3 FAQ #7