mirror of
https://github.com/ncruces/go-sqlite3.git
synced 2026-01-12 05:59:14 +00:00
Batch column scans. (#52)
This commit is contained in:
51
sqlite3/column.c
Normal file
51
sqlite3/column.c
Normal file
@@ -0,0 +1,51 @@
|
||||
#include <stddef.h>
|
||||
|
||||
#include "sqlite3.h"
|
||||
|
||||
union sqlite3_data {
|
||||
sqlite3_int64 i;
|
||||
double d;
|
||||
struct {
|
||||
const void *ptr;
|
||||
int len;
|
||||
};
|
||||
};
|
||||
|
||||
int sqlite3_columns_go(sqlite3_stmt *stmt, int nCol, char *aType,
|
||||
union sqlite3_data *aData) {
|
||||
if (nCol != sqlite3_column_count(stmt)) {
|
||||
return SQLITE_MISUSE;
|
||||
}
|
||||
int rc = SQLITE_OK;
|
||||
for (int i = 0; i < nCol; ++i) {
|
||||
const void *ptr = NULL;
|
||||
switch (aType[i] = sqlite3_column_type(stmt, i)) {
|
||||
default: // SQLITE_NULL
|
||||
aData[i] = (union sqlite3_data){};
|
||||
case SQLITE_INTEGER:
|
||||
aData[i].i = sqlite3_column_int64(stmt, i);
|
||||
continue;
|
||||
case SQLITE_FLOAT:
|
||||
aData[i].d = sqlite3_column_double(stmt, i);
|
||||
continue;
|
||||
case SQLITE_TEXT:
|
||||
ptr = sqlite3_column_text(stmt, i);
|
||||
break;
|
||||
case SQLITE_BLOB:
|
||||
ptr = sqlite3_column_blob(stmt, i);
|
||||
break;
|
||||
}
|
||||
if (ptr == NULL && rc == SQLITE_OK) {
|
||||
rc = sqlite3_errcode(sqlite3_db_handle(stmt));
|
||||
}
|
||||
aData[i].ptr = ptr;
|
||||
aData[i].len = sqlite3_column_bytes(stmt, i);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
static_assert(offsetof(union sqlite3_data, i) == 0, "Unexpected offset");
|
||||
static_assert(offsetof(union sqlite3_data, d) == 0, "Unexpected offset");
|
||||
static_assert(offsetof(union sqlite3_data, ptr) == 0, "Unexpected offset");
|
||||
static_assert(offsetof(union sqlite3_data, len) == 4, "Unexpected offset");
|
||||
static_assert(sizeof(union sqlite3_data) == 8, "Unexpected size");
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "ext/uint.c"
|
||||
#include "ext/uuid.c"
|
||||
// Bindings
|
||||
#include "column.c"
|
||||
#include "func.c"
|
||||
#include "log.c"
|
||||
#include "pointer.c"
|
||||
|
||||
@@ -136,8 +136,6 @@ static int go_cur_close_wrapper(sqlite3_vtab_cursor *pCursor) {
|
||||
static int go_vtab_find_function_wrapper(
|
||||
sqlite3_vtab *pVTab, int nArg, const char *zName,
|
||||
void (**pxFunc)(sqlite3_context *, int, sqlite3_value **), void **ppArg) {
|
||||
struct go_vtab *vtab = container_of(pVTab, struct go_vtab, base);
|
||||
|
||||
go_handle handle;
|
||||
int rc = go_vtab_find_function(pVTab, nArg, zName, &handle);
|
||||
if (rc) {
|
||||
|
||||
Reference in New Issue
Block a user