Permalink
Browse files

first try at mysql_safe

  • Loading branch information...
1 parent 29329e5 commit ba8b99617babd4b935f4db4b60e88cc651d95cd0 @jneen committed Mar 31, 2011
Showing with 11 additions and 0 deletions.
  1. +5 −0 lib/model.sh
  2. +6 −0 lib/util.sh
View
@@ -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
@@ -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}'"
+}

0 comments on commit ba8b996

Please sign in to comment.