| 209 | #pragma region Vector general |
| 210 | |
| 211 | static void vector_value_at(sqlite3_context *context, |
| 212 | int argc, |
| 213 | sqlite3_value **argv) { |
| 214 | |
| 215 | vec_ptr pVec = valueAsVector(argv[0]); |
| 216 | |
| 217 | if (pVec == nullptr) |
| 218 | return; |
| 219 | |
| 220 | int pos = sqlite3_value_int(argv[1]); |
| 221 | |
| 222 | try { |
| 223 | |
| 224 | float result = pVec->at(pos); |
| 225 | sqlite3_result_double(context, result); |
| 226 | |
| 227 | } catch (const out_of_range &oor) { |
| 228 | |
| 229 | char *errmsg = sqlite3_mprintf("%d out of range: %s", pos, oor.what()); |
| 230 | |
| 231 | if (errmsg != nullptr) { |
| 232 | sqlite3_result_error(context, errmsg, -1); |
| 233 | sqlite3_free(errmsg); |
| 234 | } else { |
| 235 | sqlite3_result_error_nomem(context); |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | static void vector_length(sqlite3_context *context, |
| 241 | int argc, |