diff --git a/c_src/esqlite3_nif.c b/c_src/esqlite3_nif.c index 5b981b2..1a41305 100644 --- a/c_src/esqlite3_nif.c +++ b/c_src/esqlite3_nif.c @@ -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: diff --git a/test/esqlite_test.erl b/test/esqlite_test.erl index 4453311..42535d5 100644 --- a/test/esqlite_test.erl +++ b/test/esqlite_test.erl @@ -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() ->