Android Studio Sqlite Sqlinjection 可以通过手势进行吗?

Android Studio Sqlite Sqlinjection possible with gestures?

我使用 SQLite 数据库实现了一个应用程序,数据存储在后台,无需任何用户交互。唯一需要使用的地方是用手势删除数据时,这是我的问题。 是否可以通过手势进行 SQL 注入?如果可以,我该如何预防?

如果用户没有输入文本,那么 SQL 注入的可能性很小。

但是,如果您完全使用便捷方法和/或将 rawQuery execSQL 与第二个参数一起使用,通过第二个参数传递任何值,那么这些值将被绑定以防止 SQL 注入.

  • 这假设您使用的是标准 SQLiteDatabase,符合 SDK。

插入行的示例

本例使用execSQL (both forms) and the insert便捷方法来演示使用绑定参数的原则,并在第一个示例中不使用绑定参数。

theSQLitedatabase.execSQL("INSERT INTO mytable VALUES('" + userdata + "')"); //<<<<<< potential for injection

theSQLitedatabase.execSQL("INSERT INTO mytable VALUES(?)",new String[]{userdata}); //<<<<< protects as value is bound by SQLite itself

/* Uses the convenience method that builds the SQL (as per 2nd example) and protects */
ContentValues cv = new Contentvalues();
cv.put(the_column_name_as_a_string,userdata);
theSQLitedatabase.insert("mytable",null,cv);