The purpose of this question, is not to figure out how to prevent SQL Injection attempts.
Instead I would like to know, how to detect lines of SQL code within an (Android Class) file
Unlike other SQL parser threads I am wanting to work within Android and I am simply after something like a Regex statement which could be used to detect SQL code within the current line
I have an example page of Android code like the below :
String query = "select * from users_table where username = '" + u_username + "' and password = '" + u_password +"'";
SQLiteDatabase db
//some un-important code here...
Cursor c = db.rawQuery( p_query, null );
return c.getCount() != 0;
}
Within which there are a lines of SQL code like:
select * from users_table where username = '" + u_username + "' and password = '" + u_password +"'
I have a function like the below, which reads in an (Android Class) file line by line. Then returns an ArrayList of String.
public ArrayList<String> SQLStatementsfromFile(File fileLocation) throws IOException {
ArrayList<String> SQLStatements = new ArrayList<>();
FileInputStream is;
BufferedReader reader;
if (fileLocation.exists()) {
is = new FileInputStream(fileLocation);
reader = new BufferedReader(new InputStreamReader(is));
String line = reader.readLine();
while (line != null) {
line = reader.readLine();
if (line != null) {
if (!line.isEmpty()) {
if (line.contains(SQL))
SQLStatements.add(line);
}
}
}
}
return SQLStatements;
}
What I would like to know is: are there any sort of possible Regex statements (or other code detection methods) which could be used to detect SQL code, from each line of android code (so it can be added to the ArrayList SQLStatements)?
To be clear, PLEASE do not give me tips on example code I have written above.
Or advice on examples given. Just PLEASE instead attempt to actually answer my question.
I know parameter-ised statements within SQL etc. are much more secure, but this is NOT why I have opened this thread, the above are simply examples of SQL code I would like to be detect (NOT SQL code I plan to utilize).
Thank you :-)