2010-08-25 65 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