Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

first try at mysql_safe

  • Loading branch information...
commit ba8b99617babd4b935f4db4b60e88cc651d95cd0 1 parent 29329e5
@jneen authored
Showing with 11 additions and 0 deletions.
  1. +5 −0 lib/model.sh
  2. +6 −0 lib/util.sh
View
5 lib/model.sh
@@ -38,6 +38,11 @@ balls::model() {
}
balls::model.find() {
+ local query="$1"; shift
+ for param in "$@"; do
+ mysql_safe param
+ query="$(sed "s/\?/$param/" <<<"$query")"
+ done
balls::model.execute "SELECT * from $(balls::model.table_name) WHERE $@"
}
View
6 lib/util.sh
@@ -86,3 +86,9 @@ bash_safe() {
str="$(echo "$str" | sed "s/'/'\\\\''/g")"
export "$1"="'${str:0:${#str}-1}'"
}
+
+mysql_safe() {
+ local str="${!1}."
+ str="$(echo "$str" | sed "s/'/\\\\'/g" | tr '\n' '\\n')"
+ export "$1"="'${str:0:${#str}-1}'"
+}
Please sign in to comment.
Something went wrong with that request. Please try again.