Created
December 8, 2016 08:01
-
-
Save madorin/83300eaf3d9044bc6e56a710b3700368 to your computer and use it in GitHub Desktop.
Firebird script parameters preprocessing
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
/* in order to support named params, which Firebird itself doesn't, | |
we need to replace :foo by ?, and store the name we just replaced */ | |
new_sql = c = emalloc(sql_len+1); | |
for (l = in_quote = in_param = 0; l <= sql_len; ++l) { | |
if (!(in_quote ^= (sql[l] == '\''))) { | |
if (!in_param) { | |
switch (sql[l]) { | |
case ':': | |
in_param = 1; | |
ppname = pname; | |
*ppname++ = sql[l]; | |
case '?': | |
*c++ = '?'; | |
++pindex; | |
continue; | |
} | |
} else { | |
if ((in_param &= ((sql[l] >= 'A' && sql[l] <= 'Z') || (sql[l] >= 'a' && sql[l] <= 'z') | |
|| (sql[l] >= '0' && sql[l] <= '9') || sql[l] == '_' || sql[l] == '-'))) { | |
*ppname++ = sql[l]; | |
continue; | |
} else { | |
*ppname++ = 0; | |
if (named_params) { | |
zval tmp; | |
ZVAL_LONG(&tmp, pindex); | |
zend_hash_str_update(named_params, pname, (unsigned int)(ppname - pname - 1), &tmp); | |
} | |
} | |
} | |
} | |
*c++ = sql[l]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment