@@ -195,6 +195,69 @@ make_sqlite3_error_tuple(ErlNifEnv* env, int rc, sqlite3* db)
195195 return make_error_tuple (env , make_binary (env , msg , len ));
196196}
197197
198+ static ERL_NIF_TERM
199+ raise_badarg (ErlNifEnv * env , ERL_NIF_TERM term )
200+ {
201+ ERL_NIF_TERM badarg = enif_make_tuple2 (env , am_badarg , term );
202+ return enif_raise_exception (env , badarg );
203+ }
204+
205+ static ERL_NIF_TERM
206+ make_cell (ErlNifEnv * env , sqlite3_stmt * statement , unsigned int i )
207+ {
208+ switch (sqlite3_column_type (statement , i )) {
209+ case SQLITE_INTEGER :
210+ return enif_make_int64 (env , sqlite3_column_int64 (statement , i ));
211+
212+ case SQLITE_FLOAT :
213+ return enif_make_double (env , sqlite3_column_double (statement , i ));
214+
215+ case SQLITE_NULL :
216+ return am_nil ;
217+
218+ case SQLITE_BLOB :
219+ return make_binary (
220+ env ,
221+ sqlite3_column_blob (statement , i ),
222+ sqlite3_column_bytes (statement , i ));
223+
224+ case SQLITE_TEXT :
225+ return make_binary (
226+ env ,
227+ sqlite3_column_text (statement , i ),
228+ sqlite3_column_bytes (statement , i ));
229+
230+ default :
231+ return am_nil ;
232+ }
233+ }
234+
235+ static ERL_NIF_TERM
236+ make_row (ErlNifEnv * env , sqlite3_stmt * statement )
237+ {
238+ assert (env );
239+ assert (statement );
240+
241+ ERL_NIF_TERM * columns = NULL ;
242+ ERL_NIF_TERM row ;
243+ unsigned int count = sqlite3_column_count (statement );
244+
245+ columns = enif_alloc (sizeof (ERL_NIF_TERM ) * count );
246+ if (!columns ) {
247+ return make_error_tuple (env , am_out_of_memory );
248+ }
249+
250+ for (unsigned int i = 0 ; i < count ; i ++ ) {
251+ columns [i ] = make_cell (env , statement , i );
252+ }
253+
254+ row = enif_make_list_from_array (env , columns , count );
255+
256+ enif_free (columns );
257+
258+ return row ;
259+ }
260+
198261///
199262/// Opens a new SQLite database
200263///
@@ -424,13 +487,6 @@ exqlite_prepare(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
424487 return make_ok_tuple (env , result );
425488}
426489
427- static ERL_NIF_TERM
428- raise_badarg (ErlNifEnv * env , ERL_NIF_TERM term )
429- {
430- ERL_NIF_TERM badarg = enif_make_tuple2 (env , am_badarg , term );
431- return enif_raise_exception (env , badarg );
432- }
433-
434490///
435491/// Reset the prepared statement
436492///
@@ -581,62 +637,6 @@ exqlite_bind_null(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
581637 return enif_make_int (env , rc );
582638}
583639
584- static ERL_NIF_TERM
585- make_cell (ErlNifEnv * env , sqlite3_stmt * statement , unsigned int i )
586- {
587- switch (sqlite3_column_type (statement , i )) {
588- case SQLITE_INTEGER :
589- return enif_make_int64 (env , sqlite3_column_int64 (statement , i ));
590-
591- case SQLITE_FLOAT :
592- return enif_make_double (env , sqlite3_column_double (statement , i ));
593-
594- case SQLITE_NULL :
595- return am_nil ;
596-
597- case SQLITE_BLOB :
598- return make_binary (
599- env ,
600- sqlite3_column_blob (statement , i ),
601- sqlite3_column_bytes (statement , i ));
602-
603- case SQLITE_TEXT :
604- return make_binary (
605- env ,
606- sqlite3_column_text (statement , i ),
607- sqlite3_column_bytes (statement , i ));
608-
609- default :
610- return am_nil ;
611- }
612- }
613-
614- static ERL_NIF_TERM
615- make_row (ErlNifEnv * env , sqlite3_stmt * statement )
616- {
617- assert (env );
618- assert (statement );
619-
620- ERL_NIF_TERM * columns = NULL ;
621- ERL_NIF_TERM row ;
622- unsigned int count = sqlite3_column_count (statement );
623-
624- columns = enif_alloc (sizeof (ERL_NIF_TERM ) * count );
625- if (!columns ) {
626- return make_error_tuple (env , am_out_of_memory );
627- }
628-
629- for (unsigned int i = 0 ; i < count ; i ++ ) {
630- columns [i ] = make_cell (env , statement , i );
631- }
632-
633- row = enif_make_list_from_array (env , columns , count );
634-
635- enif_free (columns );
636-
637- return row ;
638- }
639-
640640///
641641/// Steps the sqlite prepared statement multiple times.
642642///
@@ -967,7 +967,7 @@ exqlite_release(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
967967 return am_ok ;
968968}
969969
970- static void
970+ void
971971connection_type_destructor (ErlNifEnv * env , void * arg )
972972{
973973 assert (env );
@@ -986,7 +986,7 @@ connection_type_destructor(ErlNifEnv* env, void* arg)
986986 }
987987}
988988
989- static void
989+ void
990990statement_type_destructor (ErlNifEnv * env , void * arg )
991991{
992992 assert (env );
@@ -1005,7 +1005,7 @@ statement_type_destructor(ErlNifEnv* env, void* arg)
10051005 }
10061006}
10071007
1008- static int
1008+ int
10091009on_load (ErlNifEnv * env , void * * priv , ERL_NIF_TERM info )
10101010{
10111011 assert (env );
0 commit comments