MCPcopy Create free account
hub / github.com/agraef/pure-lang / sql3util_bind_value

Function sql3util_bind_value

pure-sql3/sql3util.c:182–213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

180 which need these conversions. */
181
182int sql3util_bind_value(sqlite3_stmt* stm, int col, pure_expr *x)
183{
184 int32_t iv; double dv; const char *sv; void *pv; mpz_t zv;
185 size_t n;
186 if (pure_is_int(x, &iv))
187 return sqlite3_bind_int(stm, col, iv);
188 else if (pure_is_mpz(x, &zv)) {
189 mpz_clear(zv);
190 return sqlite3_bind_int64(stm, col, pure_get_int64(x));
191 } else if (pure_is_double(x, &dv))
192 return sqlite3_bind_double(stm, col, dv);
193 else if (pure_is_string(x, &sv))
194 return sqlite3_bind_text(stm, col, sv, -1, SQLITE_TRANSIENT);
195 else if (pure_is_tuplev(x, &n, NULL) && n==2) {
196 pure_expr **xs;
197 int res = 0;
198 pure_is_tuplev(x, &n, &xs);
199 if (xs && pure_is_int(xs[0], &iv) && pure_is_pointer(xs[1], &pv))
200 res = sqlite3_bind_blob(stm, col, pv, iv, SQLITE_TRANSIENT);
201 else
202 pure_throw(pure_app(pure_quoted_symbol(pure_sym("sql3::bad_sql_value")),
203 x));
204 if (xs) free(xs);
205 return res;
206 } else if (pure_is_sqlnull(x))
207 return sqlite3_bind_null(stm, col);
208 else {
209 pure_throw
210 (pure_app(pure_quoted_symbol(pure_sym("sql3::bad_sql_value")), x));
211 return 0;
212 }
213}
214
215void sql3util_result_value(sqlite3_context* ctx, pure_expr *x)
216{

Callers

nothing calls this directly

Calls 12

pure_is_intFunction · 0.85
pure_is_mpzFunction · 0.85
pure_get_int64Function · 0.85
pure_is_doubleFunction · 0.85
pure_is_stringFunction · 0.85
pure_is_tuplevFunction · 0.85
pure_is_pointerFunction · 0.85
pure_throwFunction · 0.85
pure_appFunction · 0.85
pure_quoted_symbolFunction · 0.85
pure_symFunction · 0.85
pure_is_sqlnullFunction · 0.70

Tested by

no test coverage detected