First attempt to support 64-bit ints

This commit is contained in:
Alexey Romanov
2010-11-09 16:49:19 +03:00
parent 71ab94ba7c
commit 4864e114e8
3 changed files with 21 additions and 3 deletions

View File

@@ -161,6 +161,9 @@ static void sql_free_async(void *_async_command)
async_command->driver_data->async_handle = 0; async_command->driver_data->async_handle = 0;
if (async_command->int64s) {
free(async_command->int64s);
}
if (async_command->floats) { if (async_command->floats) {
free(async_command->floats); free(async_command->floats);
} }
@@ -189,6 +192,9 @@ static void sql_exec_async(void *_async_command) {
char *rest = NULL; char *rest = NULL;
sqlite3_stmt *statement = async_command->statement; sqlite3_stmt *statement = async_command->statement;
sqlite3_int64 *int64s = NULL;
int int64_count = 0;
double *floats = NULL; double *floats = NULL;
int float_count = 0; int float_count = 0;
@@ -240,10 +246,14 @@ static void sql_exec_async(void *_async_command) {
// fflush (drv->log); // fflush (drv->log);
switch (sqlite3_column_type(statement, i)) { switch (sqlite3_column_type(statement, i)) {
case SQLITE_INTEGER: { case SQLITE_INTEGER: {
int64_count++;
int64s = realloc(int64s, sizeof(sqlite3_int64) * int64_count);
int64s[int64_count - 1] = sqlite3_column_int64(statement, i);
term_count += 2; term_count += 2;
dataset = realloc(dataset, sizeof(*dataset) * term_count); dataset = realloc(dataset, sizeof(*dataset) * term_count);
dataset[term_count - 2] = ERL_DRV_INT; dataset[term_count - 2] = ERL_DRV_INT64;
dataset[term_count - 1] = sqlite3_column_int(statement, i); dataset[term_count - 1] = &int64s[int64_count - 1];
break; break;
} }
case SQLITE_FLOAT: { case SQLITE_FLOAT: {
@@ -327,7 +337,7 @@ static void sql_exec_async(void *_async_command) {
} else if (strcasestr(sqlite3_sql(statement), "INSERT")) { } else if (strcasestr(sqlite3_sql(statement), "INSERT")) {
long long rowid = sqlite3_last_insert_rowid(drv->db); sqlite3_int64 rowid = sqlite3_last_insert_rowid(drv->db);
term_count += 6; term_count += 6;
dataset = realloc(dataset, sizeof(*dataset) * term_count); dataset = realloc(dataset, sizeof(*dataset) * term_count);
dataset[term_count - 6] = ERL_DRV_ATOM; dataset[term_count - 6] = ERL_DRV_ATOM;

View File

@@ -48,6 +48,7 @@ typedef struct async_sqlite3_command {
double *floats; double *floats;
int binaries_count; int binaries_count;
ErlDrvBinary **binaries; ErlDrvBinary **binaries;
sqlite3_int64 *int64s;
} async_sqlite3_command; } async_sqlite3_command;

View File

@@ -133,6 +133,13 @@ nonexistent_table_info_test() ->
?assertEqual(table_does_not_exist, sqlite3:table_info(ct, nonexistent)), ?assertEqual(table_does_not_exist, sqlite3:table_info(ct, nonexistent)),
sqlite3:close(ct). sqlite3:close(ct).
large_number_test() ->
sqlite3:open(ct),
N1 = 4294967295,
N2 = (N1 + 1) div 2,
Query1 = io_lib:format("select ~p, ~p", [N1, N2]),
?assertEqual([{N1, N2}], rows(sqlite3:sql_exec(ct, Query1))).
% create, read, update, delete % create, read, update, delete
%%==================================================================== %%====================================================================
%% Internal functions %% Internal functions