Created
March 1, 2017 09:51
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**! | |
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