|
|
@ -41,7 +41,7 @@ class DelegateCommon extends AbsDelegate { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void dropTable(SQLiteDatabase db, String tableName) { |
|
|
|
void dropTable(SQLiteDatabase db, String tableName) { |
|
|
|
db = checkDb(db); |
|
|
|
db = checkDb(db); |
|
|
|
String deleteSQL = "DROP TABLE IF EXISTS ".concat(tableName); |
|
|
|
String deleteSQL = String.format("DROP TABLE IF EXISTS %s", tableName); |
|
|
|
print(DROP_TABLE, deleteSQL); |
|
|
|
print(DROP_TABLE, deleteSQL); |
|
|
|
//db.beginTransaction();
|
|
|
|
//db.beginTransaction();
|
|
|
|
db.execSQL(deleteSQL); |
|
|
|
db.execSQL(deleteSQL); |
|
|
@ -75,12 +75,11 @@ class DelegateCommon extends AbsDelegate { |
|
|
|
db = checkDb(db); |
|
|
|
db = checkDb(db); |
|
|
|
Cursor cursor = null; |
|
|
|
Cursor cursor = null; |
|
|
|
try { |
|
|
|
try { |
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
String sql = |
|
|
|
sb.append("SELECT COUNT(*) AS c FROM sqlite_master WHERE type='table' AND name='"); |
|
|
|
String.format("SELECT name FROM sqlite_master WHERE type='table' AND name='%s'", |
|
|
|
sb.append(tableName); |
|
|
|
tableName); |
|
|
|
sb.append("'"); |
|
|
|
print(TABLE_EXISTS, sql); |
|
|
|
print(TABLE_EXISTS, sb.toString()); |
|
|
|
cursor = db.rawQuery(sql, null); |
|
|
|
cursor = db.rawQuery(sb.toString(), null); |
|
|
|
|
|
|
|
if (cursor != null && cursor.moveToNext()) { |
|
|
|
if (cursor != null && cursor.moveToNext()) { |
|
|
|
int count = cursor.getInt(0); |
|
|
|
int count = cursor.getInt(0); |
|
|
|
if (count > 0) { |
|
|
|
if (count > 0) { |
|
|
@ -133,7 +132,7 @@ class DelegateCommon extends AbsDelegate { |
|
|
|
//外键Map,在Sqlite3中foreign修饰的字段必须放在最后
|
|
|
|
//外键Map,在Sqlite3中foreign修饰的字段必须放在最后
|
|
|
|
final List<Field> foreignArray = new ArrayList<>(); |
|
|
|
final List<Field> foreignArray = new ArrayList<>(); |
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
sb.append("CREATE TABLE ") |
|
|
|
sb.append("CREATE TABLE IF NOT EXISTS ") |
|
|
|
.append(CommonUtil.getClassName(clazz)) |
|
|
|
.append(CommonUtil.getClassName(clazz)) |
|
|
|
.append(" ("); |
|
|
|
.append(" ("); |
|
|
|
for (Field field : fields) { |
|
|
|
for (Field field : fields) { |
|
|
@ -187,7 +186,7 @@ class DelegateCommon extends AbsDelegate { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (SqlUtil.isUnique(field)){ |
|
|
|
if (SqlUtil.isUnique(field)) { |
|
|
|
sb.append(" UNIQUE"); |
|
|
|
sb.append(" UNIQUE"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|