Skip to content

Instantly share code, notes, and snippets.

@jolle-c
Created March 1, 2017 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jolle-c/693b0cb599482a34d0cf8ee7d59e9fbc to your computer and use it in GitHub Desktop.
Save jolle-c/693b0cb599482a34d0cf8ee7d59e9fbc to your computer and use it in GitHub Desktop.
Will make sql injection safe string of each item in an array
/**!
array -> encodesql
Adds a method to the lasso 9 array and staticarray types that will run encodesql on each item in the array.
This changes the array in place.
It also alters each item to type string.
EXAMPLE USAGE
local(ids = array('1', '5', '22'))
local(sql = "SELECT * FROM mytable AS mt
WHERE mt.id IN ('" + #ids -> encodesql& -> join("', '") + "');")
*/
define array -> encodesql() => {
loop(.size) => {
if(.get(loop_count) -> isa(::pair)) => {
.get(loop_count) = pair(.get(loop_count) -> first -> asstring -> encodesql, .get(loop_count) -> second -> asstring -> encodesql)
else
.get(loop_count) = .get(loop_count) -> asstring -> encodesql
}
}
}
define staticarray -> encodesql() => {
loop(.size) => {
if(.get(loop_count) -> isa(::pair)) => {
.get(loop_count) = pair(.get(loop_count) -> first -> asstring -> encodesql, .get(loop_count) -> second -> asstring -> encodesql)
else
.get(loop_count) = .get(loop_count) -> asstring -> encodesql
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment