dbd/common.c

changeset 28
44b1d78b50f5
parent 17
21c4feaeafe7
child 31
999ef93f0dbc
equal deleted inserted replaced
27:1d2369ebee21 28:44b1d78b50f5
10 10
11 return in; 11 return in;
12 } 12 }
13 13
14 /* 14 /*
15 * replace '?' placeholders with $\d+ placeholders 15 * replace '?' placeholders with {native_prefix}\d+ placeholders
16 * to be compatible with PSQL API 16 * to be compatible with native API
17 */ 17 */
18 char *replace_placeholders(lua_State *L, char native_prefix, const char *sql) { 18 char *replace_placeholders(lua_State *L, char native_prefix, const char *sql) {
19 size_t len = strlen(sql); 19 size_t len = strlen(sql);
20 int num_placeholders = 0; 20 int num_placeholders = 0;
21 int extra_space = 0; 21 int extra_space = 0;
74 74
75 if (sql[i] == '?' && !in_quote) { 75 if (sql[i] == '?' && !in_quote) {
76 size_t n; 76 size_t n;
77 77
78 if (ph_num > MAX_PLACEHOLDERS) { 78 if (ph_num > MAX_PLACEHOLDERS) {
79 luaL_error(L, "Sorry, you are using more than %d placeholders. Use ${num} format instead", MAX_PLACEHOLDERS); 79 luaL_error(L, "Sorry, you are using more than %d placeholders. Use %c{num} format instead", MAX_PLACEHOLDERS, native_prefix);
80 } 80 }
81 81
82 n = snprintf(&newsql[newpos], MAX_PLACEHOLDER_SIZE, format_str, ph_num++); 82 n = snprintf(&newsql[newpos], MAX_PLACEHOLDER_SIZE, format_str, ph_num++);
83 83
84 newpos += n; 84 newpos += n;

mercurial