| 180 | which need these conversions. */ |
| 181 | |
| 182 | int 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 | |
| 215 | void sql3util_result_value(sqlite3_context* ctx, pure_expr *x) |
| 216 | { |
nothing calls this directly
no test coverage detected