@@ -71,14 +71,17 @@ public static TableDataResponse getTableData(SQLiteDatabase db, String selectQue
7171 tableName = getTableName (selectQuery );
7272 }
7373
74+ final String quotedTableName = getQuotedTableName (tableName );
75+
7476 if (tableName != null ) {
75- final String pragmaQuery = "PRAGMA table_info(" + tableName + ")" ;
77+ final String pragmaQuery = "PRAGMA table_info(" + quotedTableName + ")" ;
7678 tableData .tableInfos = getTableInfo (db , pragmaQuery );
7779 }
7880 Cursor cursor = null ;
7981 boolean isView = false ;
8082 try {
81- cursor = db .rawQuery ("SELECT type FROM sqlite_master WHERE name=?" , new String []{tableName });
83+ cursor = db .rawQuery ("SELECT type FROM sqlite_master WHERE name=?" ,
84+ new String []{quotedTableName });
8285 if (cursor .moveToFirst ()) {
8386 isView = "view" .equalsIgnoreCase (cursor .getString (0 ));
8487 }
@@ -93,7 +96,7 @@ public static TableDataResponse getTableData(SQLiteDatabase db, String selectQue
9396
9497
9598 if (!TextUtils .isEmpty (tableName )) {
96- selectQuery = selectQuery .replace (tableName , "[" + tableName + "]" );
99+ selectQuery = selectQuery .replace (tableName , quotedTableName );
97100 }
98101
99102 try {
@@ -165,6 +168,11 @@ public static TableDataResponse getTableData(SQLiteDatabase db, String selectQue
165168
166169 }
167170
171+
172+ private static String getQuotedTableName (String tableName ) {
173+ return String .format ("[%s]" , tableName );
174+ }
175+
168176 private static List <TableDataResponse .TableInfo > getTableInfo (SQLiteDatabase db , String pragmaQuery ) {
169177
170178 Cursor cursor ;
@@ -220,6 +228,8 @@ public static UpdateRowResponse addRow(SQLiteDatabase db, String tableName,
220228 return updateRowResponse ;
221229 }
222230
231+ tableName = getQuotedTableName (tableName );
232+
223233 ContentValues contentValues = new ContentValues ();
224234
225235 for (RowDataRequest rowDataRequest : rowDataRequests ) {
@@ -260,6 +270,8 @@ public static UpdateRowResponse updateRow(SQLiteDatabase db, String tableName, L
260270 return updateRowResponse ;
261271 }
262272
273+ tableName = getQuotedTableName (tableName );
274+
263275 ContentValues contentValues = new ContentValues ();
264276
265277 String whereClause = null ;
@@ -314,6 +326,8 @@ public static UpdateRowResponse deleteRow(SQLiteDatabase db, String tableName,
314326 return updateRowResponse ;
315327 }
316328
329+ tableName = getQuotedTableName (tableName );
330+
317331
318332 String whereClause = null ;
319333 List <String > whereArgsList = new ArrayList <>();
@@ -353,6 +367,14 @@ public static TableDataResponse exec(SQLiteDatabase database, String sql) {
353367 TableDataResponse tableDataResponse = new TableDataResponse ();
354368 tableDataResponse .isSelectQuery = false ;
355369 try {
370+
371+ String tableName = getTableName (sql );
372+
373+ if (!TextUtils .isEmpty (tableName )) {
374+ String quotedTableName = getQuotedTableName (tableName );
375+ sql = sql .replace (tableName , quotedTableName );
376+ }
377+
356378 database .execSQL (sql );
357379 } catch (Exception e ) {
358380 e .printStackTrace ();
0 commit comments