Addes support for 64-bit integers.
This commit is contained in:
@@ -313,6 +313,7 @@ static int
|
||||
bind_cell(ErlNifEnv *env, const ERL_NIF_TERM cell, sqlite3_stmt *stmt, unsigned int i)
|
||||
{
|
||||
int the_int;
|
||||
ErlNifSInt64 the_long_int;
|
||||
double the_double;
|
||||
char the_atom[MAX_ATOM_LENGTH+1];
|
||||
ErlNifBinary the_blob;
|
||||
@@ -322,6 +323,9 @@ bind_cell(ErlNifEnv *env, const ERL_NIF_TERM cell, sqlite3_stmt *stmt, unsigned
|
||||
if(enif_get_int(env, cell, &the_int))
|
||||
return sqlite3_bind_int(stmt, i, the_int);
|
||||
|
||||
if(enif_get_int64(env, cell, &the_long_int))
|
||||
return sqlite3_bind_int64(stmt, i, the_long_int);
|
||||
|
||||
if(enif_get_double(env, cell, &the_double))
|
||||
return sqlite3_bind_double(stmt, i, the_double);
|
||||
|
||||
@@ -413,7 +417,7 @@ make_cell(ErlNifEnv *env, sqlite3_stmt *statement, unsigned int i)
|
||||
|
||||
switch(type) {
|
||||
case SQLITE_INTEGER:
|
||||
return enif_make_int(env, sqlite3_column_int(statement, i));
|
||||
return enif_make_int64(env, sqlite3_column_int64(statement, i));
|
||||
case SQLITE_FLOAT:
|
||||
return enif_make_double(env, sqlite3_column_double(statement, i));
|
||||
case SQLITE_BLOB:
|
||||
|
||||
@@ -71,6 +71,10 @@ bind_test() ->
|
||||
esqlite3:bind(Statement, [{blob, [<<"eleven">>, 0]}, 12]), % iolist bound as blob with trailing eos.
|
||||
esqlite3:step(Statement),
|
||||
|
||||
%% int64
|
||||
esqlite3:bind(Statement, [int64, 308553449069486081]),
|
||||
esqlite3:step(Statement),
|
||||
|
||||
%% utf-8
|
||||
esqlite3:bind(Statement, [[<<228,184,138,230,181,183>>], 100]),
|
||||
esqlite3:step(Statement),
|
||||
@@ -88,10 +92,15 @@ bind_test() ->
|
||||
?assertEqual([{{blob, <<$e,$l,$e,$v,$e,$n,0>>}, 12}],
|
||||
esqlite3:q("select one, two from test_table where two = 12", Db)),
|
||||
|
||||
%% int64
|
||||
?assertEqual([{<<"int64">>, 308553449069486081}],
|
||||
esqlite3:q("select one, two from test_table where one = 'int64';", Db)),
|
||||
|
||||
%% utf-8
|
||||
?assertEqual([{<<228,184,138,230,181,183>>, 100}],
|
||||
esqlite3:q("select one, two from test_table where two = 100", Db)),
|
||||
|
||||
|
||||
ok.
|
||||
|
||||
bind_for_queries_test() ->
|
||||
|
||||
Reference in New Issue
Block a user