Skip to content

Instantly share code, notes, and snippets.

@KoKuToru
Last active August 29, 2015 14:21
Show Gist options
  • Save KoKuToru/629bd90d5d6ee9a47864 to your computer and use it in GitHub Desktop.
Save KoKuToru/629bd90d5d6ee9a47864 to your computer and use it in GitHub Desktop.
ANDROID SQL OH THANKS
Stack<Character> stack = new Stack<>();
int last_split = 0;
boolean ignore_next = false;
for(int i = 0; i < full_cmd.length(); ++i) {
if (ignore_next){
ignore_next = false;
continue;
}
char c = full_cmd.charAt(i);
if (c == ']') {
c = '[';
}
switch (c) {
case '\'':
case '\"':
case '`':
case '[':
if (!stack.isEmpty() && stack.peek() == c) {
stack.pop();
} else {
stack.push(c);
}
break;
case '\\':
ignore_next = true;
break;
case ';':
if (stack.empty()) {
String cmd = full_cmd.substring(last_split, i);
db.execSQL(cmd);
last_split = i+1;
}
break;
}
}
if (last_split < full_cmd.length()) {
String cmd = full_cmd.substring(last_split, full_cmd.length()).trim();
if (!cmd.isEmpty()) {
db.execSQL(cmd);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment