libsql 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTING.md +60 -0
  3. data/HISTORY.md +6 -0
  4. data/LICENSE +31 -0
  5. data/Manifest.txt +96 -0
  6. data/README.md +59 -0
  7. data/Rakefile +28 -0
  8. data/TODO.md +57 -0
  9. data/examples/a.rb +9 -0
  10. data/examples/blob.rb +106 -0
  11. data/examples/define_aggregate.rb +75 -0
  12. data/examples/define_function.rb +104 -0
  13. data/examples/fts5.rb +152 -0
  14. data/examples/gem-db.rb +94 -0
  15. data/examples/schema-info.rb +34 -0
  16. data/ext/libsql/c/extconf.rb +86 -0
  17. data/ext/libsql/c/gen_constants.rb +353 -0
  18. data/ext/libsql/c/libsql_blob.c +240 -0
  19. data/ext/libsql/c/libsql_constants.c +1518 -0
  20. data/ext/libsql/c/libsql_database.c +1188 -0
  21. data/ext/libsql/c/libsql_ext.c +383 -0
  22. data/ext/libsql/c/libsql_ext.h +149 -0
  23. data/ext/libsql/c/libsql_statement.c +649 -0
  24. data/ext/libsql/c/notes.txt +134 -0
  25. data/ext/libsql/c/sqlite3.c +247030 -0
  26. data/ext/libsql/c/sqlite3.h +13436 -0
  27. data/lib/libsql/aggregate.rb +73 -0
  28. data/lib/libsql/blob.rb +186 -0
  29. data/lib/libsql/boolean.rb +42 -0
  30. data/lib/libsql/busy_timeout.rb +47 -0
  31. data/lib/libsql/column.rb +99 -0
  32. data/lib/libsql/csv_table_importer.rb +75 -0
  33. data/lib/libsql/database.rb +933 -0
  34. data/lib/libsql/function.rb +61 -0
  35. data/lib/libsql/index.rb +43 -0
  36. data/lib/libsql/memory_database.rb +15 -0
  37. data/lib/libsql/paths.rb +80 -0
  38. data/lib/libsql/profile_tap.rb +131 -0
  39. data/lib/libsql/progress_handler.rb +21 -0
  40. data/lib/libsql/schema.rb +225 -0
  41. data/lib/libsql/sqlite3/constants.rb +95 -0
  42. data/lib/libsql/sqlite3/database/function.rb +48 -0
  43. data/lib/libsql/sqlite3/database/status.rb +68 -0
  44. data/lib/libsql/sqlite3/libsql_version.rb +32 -0
  45. data/lib/libsql/sqlite3/status.rb +60 -0
  46. data/lib/libsql/sqlite3/version.rb +55 -0
  47. data/lib/libsql/sqlite3.rb +7 -0
  48. data/lib/libsql/statement.rb +421 -0
  49. data/lib/libsql/table.rb +91 -0
  50. data/lib/libsql/taps/console.rb +27 -0
  51. data/lib/libsql/taps/io.rb +74 -0
  52. data/lib/libsql/taps.rb +2 -0
  53. data/lib/libsql/trace_tap.rb +35 -0
  54. data/lib/libsql/type_map.rb +63 -0
  55. data/lib/libsql/type_maps/default_map.rb +166 -0
  56. data/lib/libsql/type_maps/storage_map.rb +38 -0
  57. data/lib/libsql/type_maps/text_map.rb +21 -0
  58. data/lib/libsql/version.rb +8 -0
  59. data/lib/libsql/view.rb +26 -0
  60. data/lib/libsql-ruby.rb +1 -0
  61. data/lib/libsql.rb +51 -0
  62. data/spec/aggregate_spec.rb +158 -0
  63. data/spec/blob_spec.rb +78 -0
  64. data/spec/boolean_spec.rb +24 -0
  65. data/spec/busy_handler.rb +157 -0
  66. data/spec/data/iso-3166-country.txt +242 -0
  67. data/spec/data/iso-3166-schema.sql +22 -0
  68. data/spec/data/iso-3166-subcountry.txt +3995 -0
  69. data/spec/data/make-iso-db.sh +12 -0
  70. data/spec/database_spec.rb +505 -0
  71. data/spec/default_map_spec.rb +92 -0
  72. data/spec/function_spec.rb +78 -0
  73. data/spec/integeration_spec.rb +97 -0
  74. data/spec/iso_3166_database.rb +58 -0
  75. data/spec/json_spec.rb +24 -0
  76. data/spec/libsql_spec.rb +4 -0
  77. data/spec/paths_spec.rb +28 -0
  78. data/spec/progress_handler_spec.rb +91 -0
  79. data/spec/rtree_spec.rb +66 -0
  80. data/spec/schema_spec.rb +131 -0
  81. data/spec/spec_helper.rb +48 -0
  82. data/spec/sqlite3/constants_spec.rb +108 -0
  83. data/spec/sqlite3/database_status_spec.rb +36 -0
  84. data/spec/sqlite3/libsql_version_spec.rb +16 -0
  85. data/spec/sqlite3/status_spec.rb +22 -0
  86. data/spec/sqlite3/version_spec.rb +28 -0
  87. data/spec/sqlite3_spec.rb +53 -0
  88. data/spec/statement_spec.rb +168 -0
  89. data/spec/storage_map_spec.rb +38 -0
  90. data/spec/tap_spec.rb +57 -0
  91. data/spec/text_map_spec.rb +20 -0
  92. data/spec/type_map_spec.rb +14 -0
  93. data/spec/version_spec.rb +8 -0
  94. data/tasks/custom.rake +134 -0
  95. data/tasks/default.rake +257 -0
  96. data/tasks/extension.rake +29 -0
  97. data/tasks/this.rb +208 -0
  98. metadata +325 -0
@@ -0,0 +1,383 @@
1
+ /**
2
+ * Copyright (c) 2023 Jeremy Hinegardner
3
+ * All rights reserved. See LICENSE and/or COPYING for details.
4
+ *
5
+ * vim: shiftwidth=4
6
+ :*/
7
+
8
+ #include "libsql_ext.h"
9
+
10
+ /* Module and Classes */
11
+ VALUE mL; /* module Libsql */
12
+ VALUE mLS; /* module Libsql::SQLite3 */
13
+ VALUE mLSV; /* module Libsql::SQLite3::Version */
14
+ VALUE mLSLibsqlVersion;/* module Libsql::SQLite3::LibsqlVersion */
15
+ VALUE eLS_Error; /* class Libsql::SQLite3::Error */
16
+ VALUE cLS_Stat; /* class Libsql::SQLite3::Stat */
17
+
18
+ /*----------------------------------------------------------------------
19
+ * module methods for Libsql::SQLite3
20
+ *---------------------------------------------------------------------*/
21
+
22
+ /*
23
+ * call-seq:
24
+ * Libsql::SQLite3.threadsafe? -> true or false
25
+ *
26
+ * Has the SQLite3 extension been compiled "threadsafe". If threadsafe? is
27
+ * true then the internal SQLite mutexes are enabled and SQLite is threadsafe.
28
+ * That is threadsafe within the context of 'C' threads.
29
+ *
30
+ */
31
+ VALUE libsql_ext_sqlite3_threadsafe(VALUE self)
32
+ {
33
+ if (sqlite3_threadsafe()) {
34
+ return Qtrue;
35
+ } else {
36
+ return Qfalse;
37
+ }
38
+ }
39
+
40
+ /*
41
+ * call-seq:
42
+ * Libsql::SQLite.temp_directory -> String or nil
43
+ *
44
+ * Return the directory name that all that all the temporary files created by
45
+ * SQLite creates will be placed. If _nil_ is returned, then SQLite will search
46
+ * for an appropriate directory.
47
+ */
48
+ VALUE libsql_ext_sqlite3_get_temp_directory( VALUE self )
49
+ {
50
+ if (NULL == sqlite3_temp_directory) {
51
+ return Qnil;
52
+ } else {
53
+ return rb_str_new2( sqlite3_temp_directory );
54
+ }
55
+ }
56
+
57
+ /*
58
+ * call-seq:
59
+ * Libsql::SQLite.temp_directory = "/tmp/location"
60
+ *
61
+ * Set the temporary directory used by sqlite to store temporary directories.
62
+ * It is not safe to set this value after a Database has been opened.
63
+ *
64
+ */
65
+ VALUE libsql_ext_sqlite3_set_temp_directory( VALUE self, VALUE new_dir )
66
+ {
67
+ char *p = NULL ;
68
+
69
+ if ( NULL != sqlite3_temp_directory ) {
70
+ free( sqlite3_temp_directory );
71
+ }
72
+
73
+ if ( Qnil != new_dir ) {
74
+ VALUE str = StringValue( new_dir );
75
+
76
+ p = calloc( RSTRING_LEN(str) + 1, sizeof(char) );
77
+ strncpy( p, RSTRING_PTR(str), RSTRING_LEN(str) );
78
+ }
79
+
80
+ sqlite3_temp_directory = p;
81
+
82
+ return Qnil;
83
+ }
84
+
85
+ VALUE libsql_ext_format_string( const char* pattern, VALUE string )
86
+ {
87
+ VALUE to_s= rb_funcall( string, rb_intern("to_s"), 0 );
88
+ VALUE str = StringValue( to_s );
89
+ char *p = sqlite3_mprintf(pattern, RSTRING_PTR(str));
90
+ VALUE rv = Qnil;
91
+ if ( NULL != p ) {
92
+ rv = rb_str_new2( p );
93
+ sqlite3_free( p );
94
+ } else {
95
+ rb_raise( rb_eNoMemError, "Unable to quote string" );
96
+ }
97
+
98
+ return rv;
99
+ }
100
+ /*
101
+ * call-seq:
102
+ * Libsql::SQLite.escape( string ) => escaped_string
103
+ *
104
+ * Takes the input string and escapes each ' (single quote) character by
105
+ * doubling it.
106
+ */
107
+ VALUE libsql_ext_sqlite3_escape( VALUE self, VALUE string )
108
+ {
109
+ return ( Qnil == string ) ? Qnil : libsql_ext_format_string( "%q", string );
110
+ }
111
+
112
+ /*
113
+ * call-seq:
114
+ * Libsql::SQLite.quote( string ) => quoted-escaped string
115
+ *
116
+ * Takes the input string and surrounds it with single quotes, it also escapes
117
+ * each embedded single quote with double quotes.
118
+ */
119
+ VALUE libsql_ext_sqlite3_quote( VALUE self, VALUE string )
120
+ {
121
+ return ( Qnil == string ) ? Qnil : libsql_ext_format_string( "%Q", string );
122
+ }
123
+
124
+ /*
125
+ * call-seq:
126
+ * Libsql::SQLite3.complete?( ... , opts = { :utf16 => false }) -> True, False
127
+ *
128
+ * Is the text passed in as a parameter a complete SQL statement? Or is
129
+ * additional input required before sending the SQL to the extension. If the
130
+ * extra 'opts' parameter is used, you can send in a UTF-16 encoded string as
131
+ * the SQL.
132
+ *
133
+ * A complete statement must end with a semicolon.
134
+ *
135
+ */
136
+ VALUE libsql_ext_sqlite3_complete(VALUE self, VALUE args)
137
+ {
138
+ VALUE sql = rb_ary_shift( args );
139
+ VALUE opts = rb_ary_shift( args );
140
+ VALUE utf16 = Qnil;
141
+ int result = 0;
142
+
143
+ if ( ( Qnil != opts ) && ( T_HASH == TYPE(opts) ) ){
144
+ utf16 = rb_hash_aref( opts, rb_intern("utf16") );
145
+ }
146
+
147
+ if ( (Qfalse == utf16) || (Qnil == utf16) ) {
148
+ result = sqlite3_complete( StringValuePtr( sql ) );
149
+ } else {
150
+ result = sqlite3_complete16( (void*) StringValuePtr( sql ) );
151
+ }
152
+
153
+ return ( result > 0 ) ? Qtrue : Qfalse;
154
+ }
155
+
156
+ /*
157
+ * call-seq:
158
+ * Libsql::SQLite3::Stat.update!( reset = false ) -> nil
159
+ *
160
+ * Populates the _@current_ and _@higwater_ instance variables of self
161
+ * object with the values from the sqlite3_status call. If reset it true then
162
+ * the highwater mark for the stat is reset
163
+ *
164
+ */
165
+ VALUE libsql_ext_sqlite3_stat_update_bang( int argc, VALUE *argv, VALUE self )
166
+ {
167
+ int status_op = -1;
168
+ int current = -1;
169
+ int highwater = -1;
170
+ VALUE reset = Qfalse;
171
+ int reset_flag = 0;
172
+ int rc;
173
+
174
+ status_op = FIX2INT( rb_iv_get( self, "@code" ) );
175
+ if ( argc > 0 ) {
176
+ reset = argv[0];
177
+ reset_flag = ( Qtrue == reset ) ? 1 : 0 ;
178
+ }
179
+
180
+ rc = sqlite3_status( status_op, &current, &highwater, reset_flag );
181
+
182
+ if ( SQLITE_OK != rc ) {
183
+ VALUE n = rb_iv_get( self, "@name" ) ;
184
+ char* name = StringValuePtr( n );
185
+ rb_raise(eLS_Error, "Failure to retrieve status for %s : [SQLITE_ERROR %d] \n", name, rc);
186
+ }
187
+
188
+ rb_iv_set( self, "@current", INT2NUM( current ) );
189
+ rb_iv_set( self, "@highwater", INT2NUM( highwater) );
190
+
191
+ return Qnil;
192
+ }
193
+
194
+ /*
195
+ * call-seq:
196
+ * Libsql::SQLite3.randomness( N ) -> String of length N
197
+ *
198
+ * Generate N bytes of random data.
199
+ *
200
+ */
201
+ VALUE libsql_ext_sqlite3_randomness(VALUE self, VALUE num_bytes)
202
+ {
203
+ int n = NUM2INT(num_bytes);
204
+ char *buf = ALLOCA_N(char, n);
205
+
206
+ sqlite3_randomness( n, buf );
207
+ return rb_str_new( buf, n );
208
+ }
209
+
210
+ /*----------------------------------------------------------------------
211
+ * module methods for Libsql::SQLite3::Version
212
+ *---------------------------------------------------------------------*/
213
+
214
+ /*
215
+ * call-seq:
216
+ * Libsql::SQLite3::Version.to_s -> String
217
+ *
218
+ * Return the SQLite C library version number as a string
219
+ *
220
+ */
221
+ VALUE libsql_ext_sqlite3_runtime_version(VALUE self)
222
+ {
223
+ return rb_str_new2(sqlite3_libversion());
224
+ }
225
+
226
+ /*
227
+ * call-seq:
228
+ * Libsql::SQLite3.Version.to_i -> Fixnum
229
+ *
230
+ * Return the SQLite C library version number as an integer
231
+ *
232
+ */
233
+ VALUE libsql_ext_sqlite3_runtime_version_number(VALUE self)
234
+ {
235
+ return INT2FIX(sqlite3_libversion_number());
236
+ }
237
+
238
+ /*
239
+ * call-seq:
240
+ * Libsql::SQLite3::Version.runtime_source_id -> String
241
+ *
242
+ * Return the SQLite C library source id as a string
243
+ *
244
+ */
245
+ VALUE libsql_ext_sqlite3_runtime_source_id(VALUE self)
246
+ {
247
+ return rb_str_new2(sqlite3_sourceid());
248
+ }
249
+
250
+ /*
251
+ * call-seq:
252
+ * Libsql::SQLite::Version.compiled_version -> String
253
+ *
254
+ * Return the compiletime version number as a string.
255
+ *
256
+ */
257
+ VALUE libsql_ext_sqlite3_compiled_version(VALUE self)
258
+ {
259
+ return rb_str_new2( SQLITE_VERSION );
260
+ }
261
+
262
+ /*
263
+ * call-seql:
264
+ * Libsql::SQLite::Version.compiled_version_number -> Fixnum
265
+ *
266
+ * Return the compiletime library version from the
267
+ * embedded version of sqlite3.
268
+ *
269
+ */
270
+ VALUE libsql_ext_sqlite3_compiled_version_number( VALUE self )
271
+ {
272
+ return INT2FIX( SQLITE_VERSION_NUMBER );
273
+ }
274
+
275
+ /*
276
+ * call-seq:
277
+ * Libsql::SQLite3::Version.compiled_source_id -> String
278
+ *
279
+ * Return the compiled SQLite C library source id as a string
280
+ *
281
+ */
282
+ VALUE libsql_ext_sqlite3_compiled_source_id(VALUE self)
283
+ {
284
+ return rb_str_new2( SQLITE_SOURCE_ID );
285
+ }
286
+
287
+ /*
288
+ * call-seq:
289
+ * Libsql::SQLite3::LibsqlVersion.compiled_version -> String
290
+ *
291
+ * Return the compiled SQLite C library source libsql_version as a string
292
+ *
293
+ */
294
+ VALUE libsql_ext_sqlite3_libsql_compiled_version(VALUE self) {
295
+ return rb_str_new2( LIBSQL_VERSION );
296
+ }
297
+
298
+ /*
299
+ * call-seq:
300
+ * Libsql::SQLite3::LibsqlVersion.to_s -> String
301
+ *
302
+ * Return the runtime SQLite C library source libsql_version as a string
303
+ *
304
+ */
305
+ VALUE libsql_ext_sqlite3_libsql_runtime_version(VALUE self) {
306
+ return rb_str_new2( libsql_libversion() );
307
+ }
308
+
309
+
310
+ /**
311
+ * Document-class: Libsql::SQLite3
312
+ *
313
+ * The SQLite ruby extension inside Libsql.
314
+ *
315
+ */
316
+
317
+ void Init_libsql_ext()
318
+ {
319
+ int rc = 0;
320
+
321
+ /*
322
+ * top level module encapsulating the entire Libsql library
323
+ */
324
+ mL = rb_define_module("Libsql");
325
+
326
+ mLS = rb_define_module_under(mL, "SQLite3");
327
+ rb_define_module_function(mLS, "threadsafe?", libsql_ext_sqlite3_threadsafe, 0);
328
+ rb_define_module_function(mLS, "complete?", libsql_ext_sqlite3_complete, -2);
329
+ rb_define_module_function(mLS, "randomness", libsql_ext_sqlite3_randomness,1);
330
+ rb_define_module_function(mLS, "temp_directory", libsql_ext_sqlite3_get_temp_directory, 0);
331
+ rb_define_module_function(mLS, "temp_directory=", libsql_ext_sqlite3_set_temp_directory, 1);
332
+
333
+ rb_define_module_function(mLS, "escape", libsql_ext_sqlite3_escape, 1);
334
+ rb_define_module_function(mLS, "quote", libsql_ext_sqlite3_quote, 1);
335
+
336
+ /*
337
+ * class encapsulating a single Stat
338
+ */
339
+ cLS_Stat = rb_define_class_under(mLS, "Stat", rb_cObject);
340
+ rb_define_method(cLS_Stat, "update!", libsql_ext_sqlite3_stat_update_bang, -1);
341
+
342
+ /*
343
+ * Base class of all SQLite3 errors
344
+ */
345
+ eLS_Error = rb_define_class_under(mLS, "Error", rb_eStandardError); /* in libsql_ext.c */
346
+
347
+ /**
348
+ * Encapsulation of the SQLite C library version
349
+ */
350
+ mLSV = rb_define_module_under(mLS, "Version");
351
+ rb_define_module_function(mLSV, "to_s", libsql_ext_sqlite3_runtime_version, 0); /* in libsql_ext.c */
352
+ rb_define_module_function(mLSV, "runtime_version", libsql_ext_sqlite3_runtime_version, 0); /* in libsql_ext.c */
353
+ rb_define_module_function(mLSV, "to_i", libsql_ext_sqlite3_runtime_version_number, 0); /* in libsql_ext.c */
354
+ rb_define_module_function(mLSV, "runtime_version_number", libsql_ext_sqlite3_runtime_version_number, 0); /* in libsql_ext.c */
355
+ rb_define_module_function(mLSV, "compiled_version", libsql_ext_sqlite3_compiled_version, 0 ); /* in libsql_ext.c */
356
+ rb_define_module_function(mLSV, "compiled_version_number", libsql_ext_sqlite3_compiled_version_number, 0 ); /* in libsql_ext.c */
357
+ rb_define_module_function(mLSV, "runtime_source_id", libsql_ext_sqlite3_runtime_source_id, 0); /* in libsql_ext.c */
358
+ rb_define_module_function(mLSV, "compiled_source_id", libsql_ext_sqlite3_compiled_source_id, 0); /* in libsql_ext.c */
359
+
360
+ mLSLibsqlVersion = rb_define_module_under(mLS, "LibsqlVersion");
361
+ rb_define_module_function(mLSLibsqlVersion, "to_s", libsql_ext_sqlite3_libsql_runtime_version, 0); /* in libsql_ext.c */
362
+ rb_define_module_function(mLSLibsqlVersion, "runtime_version", libsql_ext_sqlite3_libsql_runtime_version, 0 ); /* in libsql_ext.c */
363
+ rb_define_module_function(mLSLibsqlVersion, "compiled_version", libsql_ext_sqlite3_libsql_compiled_version, 0 ); /* in libsql_ext.c */
364
+
365
+ /*
366
+ * Initialize the rest of the module
367
+ */
368
+ Init_libsql_ext_constants( );
369
+ Init_libsql_ext_database( );
370
+ Init_libsql_ext_statement( );
371
+ Init_libsql_ext_blob( );
372
+
373
+ /*
374
+ * initialize sqlite itself
375
+ */
376
+ rc = sqlite3_initialize();
377
+ if ( SQLITE_OK != rc ) {
378
+ rb_raise(eLS_Error, "Failure to initialize the sqlite3 library : [SQLITE_ERROR %d]\n", rc);
379
+ }
380
+
381
+ }
382
+
383
+
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Copyright (c) 2023 Jeremy Hinegardner
3
+ * All rights reserved. See LICENSE and/or COPYING for details.
4
+ *
5
+ * vim: shiftwidth=4
6
+ */
7
+
8
+ #ifndef __LIBSQL_H__
9
+ #define __LIBSQL_H__
10
+
11
+ #include "ruby.h"
12
+ #include "sqlite3.h"
13
+ #include <string.h>
14
+
15
+ /* wrapper struct around the sqlite3 opaque pointer */
16
+ typedef struct libsql_ext_sqlite3 {
17
+ sqlite3 *db;
18
+ VALUE trace_obj;
19
+ VALUE profile_obj;
20
+ VALUE busy_handler_obj;
21
+ VALUE progress_handler_obj;
22
+ } libsql_ext_sqlite3;
23
+
24
+ /* wrapper struct around the sqlite3_statement opaque pointer */
25
+ typedef struct libsql_ext_sqlite3_stmt {
26
+ sqlite3_stmt *stmt;
27
+ VALUE remaining_sql;
28
+ } libsql_ext_sqlite3_stmt;
29
+
30
+ /* wrapper struct around the sqlite3_blob opaque ponter */
31
+ typedef struct libsql_ext_sqlite3_blob {
32
+ sqlite3_blob *blob;
33
+ sqlite3 *db;
34
+ int length;
35
+ int current_offset;
36
+ } libsql_ext_sqlite3_blob;
37
+
38
+ /* wrapper struct around the information needed to call rb_apply
39
+ * used to encapsulate data into a call for libsql_ext_wrap_apply
40
+ */
41
+ typedef struct libsql_ext_protected {
42
+ VALUE instance;
43
+ ID method;
44
+ int argc;
45
+ VALUE *argv;
46
+ } libsql_ext_protected_t;
47
+
48
+ /** module and classes **/
49
+ extern VALUE mL; /* module Libsql */
50
+ extern VALUE mLS; /* module Libsql::SQLite3 */
51
+ extern VALUE mLSV; /* module Libsql::SQLite3::Version */
52
+ extern VALUE mLSLibsqlVersion;/* module Libsql::SQLite3::LibsqlVersion */
53
+ extern VALUE eLS_Error; /* class Libsql::SQLite3::Error */
54
+
55
+ /*----------------------------------------------------------------------
56
+ * Prototype for Libsql::SQLite3::Database
57
+ *---------------------------------------------------------------------*/
58
+ extern VALUE cLS_Database; /* class Libsql::SQLite3::Database */
59
+
60
+ extern void libsql_ext_define_constants_under(VALUE);
61
+ extern VALUE libsql_ext_sqlite3_database_alloc(VALUE klass);
62
+ extern void libsql_ext_sqlite3_database_free(libsql_ext_sqlite3*);
63
+ extern VALUE libsql_ext_sqlite3_database_open(int argc, VALUE* argv, VALUE self);
64
+ extern VALUE libsql_ext_sqlite3_database_close(VALUE self);
65
+ extern VALUE libsql_ext_sqlite3_database_open16(VALUE self, VALUE rFilename);
66
+ extern VALUE libsql_ext_sqlite3_database_last_insert_rowid(VALUE self);
67
+ extern VALUE libsql_ext_sqlite3_database_is_autocommit(VALUE self);
68
+ extern VALUE libsql_ext_sqlite3_database_row_changes(VALUE self);
69
+ extern VALUE libsql_ext_sqlite3_database_total_changes(VALUE self);
70
+ extern VALUE libsql_ext_sqlite3_database_table_column_metadata(VALUE self, VALUE db_name, VALUE tbl_name, VALUE col_name);
71
+
72
+ extern VALUE libsql_ext_sqlite3_database_prepare(VALUE self, VALUE rSQL);
73
+ extern VALUE libsql_ext_sqlite3_database_register_trace_tap(VALUE self, VALUE tap);
74
+ extern VALUE libsql_ext_sqlite3_database_register_profile_tap(VALUE self, VALUE tap);
75
+ extern VALUE libsql_ext_sqlite3_database_busy_handler(VALUE self, VALUE handler);
76
+
77
+ /*----------------------------------------------------------------------
78
+ * Prototype for Libsql::SQLite3::Statement
79
+ *---------------------------------------------------------------------*/
80
+ extern VALUE cLS_Statement; /* class Libsql::SQLite3::Statement */
81
+
82
+ extern VALUE libsql_ext_sqlite3_statement_alloc(VALUE klass);
83
+ extern void libsql_ext_sqlite3_statement_free(libsql_ext_sqlite3_stmt* );
84
+ extern VALUE libsql_ext_sqlite3_statement_sql(VALUE self);
85
+ extern VALUE libsql_ext_sqlite3_statement_close(VALUE self);
86
+ extern VALUE libsql_ext_sqlite3_statement_step(VALUE self);
87
+ extern VALUE libsql_ext_sqlite3_statement_column_count(VALUE self);
88
+ extern VALUE libsql_ext_sqlite3_statement_column_name(VALUE self, VALUE index);
89
+ extern VALUE libsql_ext_sqlite3_statement_column_decltype(VALUE self, VALUE index);
90
+ extern VALUE libsql_ext_sqlite3_statement_column_type(VALUE self, VALUE index);
91
+ extern VALUE libsql_ext_sqlite3_statement_column_blob(VALUE self, VALUE index);
92
+ extern VALUE libsql_ext_sqlite3_statement_column_text(VALUE self, VALUE index);
93
+ extern VALUE libsql_ext_sqlite3_statement_column_int(VALUE self, VALUE index);
94
+ extern VALUE libsql_ext_sqlite3_statement_column_int64(VALUE self, VALUE index);
95
+ extern VALUE libsql_ext_sqlite3_statement_column_double(VALUE self, VALUE index);
96
+
97
+ extern VALUE libsql_ext_sqlite3_statement_column_database_name(VALUE self, VALUE position);
98
+ extern VALUE libsql_ext_sqlite3_statement_column_table_name(VALUE self, VALUE position);
99
+ extern VALUE libsql_ext_sqlite3_statement_column_origin_name(VALUE self, VALUE position);
100
+
101
+ extern VALUE libsql_ext_sqlite3_statement_reset(VALUE self);
102
+ extern VALUE libsql_ext_sqlite3_statement_clear_bindings(VALUE self);
103
+ extern VALUE libsql_ext_sqlite3_statement_bind_parameter_count(VALUE self);
104
+ extern VALUE libsql_ext_sqlite3_statement_bind_parameter_index(VALUE self, VALUE parameter_name);
105
+ extern VALUE libsql_ext_sqlite3_statement_remaining_sql(VALUE self);
106
+ extern VALUE libsql_ext_sqlite3_statement_bind_text(VALUE self, VALUE position, VALUE value);
107
+ extern VALUE libsql_ext_sqlite3_statement_bind_blob(VALUE self, VALUE position, VALUE value);
108
+ extern VALUE libsql_ext_sqlite3_statement_bind_zeroblob(VALUE self, VALUE position, VALUE value);
109
+ extern VALUE libsql_ext_sqlite3_statement_bind_int(VALUE self, VALUE position, VALUE value);
110
+ extern VALUE libsql_ext_sqlite3_statement_bind_int64(VALUE self, VALUE position, VALUE value);
111
+ extern VALUE libsql_ext_sqlite3_statement_bind_double(VALUE self, VALUE position, VALUE value);
112
+ extern VALUE libsql_ext_sqlite3_statement_bind_null(VALUE self, VALUE position);
113
+
114
+ /*----------------------------------------------------------------------
115
+ * Prototype for Libsql::SQLite3::Blob
116
+ *---------------------------------------------------------------------*/
117
+ extern VALUE cLS_Blob; /* class Libsql::SQLite3::Blob */
118
+
119
+ extern VALUE libsql_ext_sqlite3_blob_alloc(VALUE klass);
120
+ extern VALUE libsql_ext_sqlite3_blob_initialize( VALUE self, VALUE db, VALUE db_name, VALUE table_name, VALUE column_name, VALUE rowid, VALUE flag) ;
121
+ extern void libsql_ext_sqlite3_blob_free(libsql_ext_sqlite3_blob* );
122
+ extern VALUE libsql_ext_sqlite3_blob_read(VALUE self, VALUE length);
123
+ extern VALUE libsql_ext_sqlite3_blob_write(VALUE self, VALUE buffer);
124
+ extern VALUE libsql_ext_sqlite3_blob_close(VALUE self);
125
+ extern VALUE libsql_ext_sqlite3_blob_length(VALUE self);
126
+
127
+ /*----------------------------------------------------------------------
128
+ * more initialization methods
129
+ *----------------------------------------------------------------------*/
130
+ extern void Init_libsql_ext_constants( );
131
+ extern void Init_libsql_ext_database( );
132
+ extern void Init_libsql_ext_statement( );
133
+ extern void Init_libsql_ext_blob( );
134
+
135
+
136
+ /***********************************************************************
137
+ * Type conversion macros between sqlite data types and ruby types
138
+ **********************************************************************/
139
+
140
+ #define SQLINT64_2NUM(x) ( LL2NUM( x ) )
141
+ #define SQLUINT64_2NUM(x) ( ULL2NUM( x ) )
142
+ #define NUM2SQLINT64( obj ) ( NUM2LL( obj ) )
143
+ #define NUM2SQLUINT64( obj ) ( NUM2ULL( obj ) )
144
+
145
+ /***********************************************************************
146
+ * return the last exception in ruby's error message
147
+ */
148
+ #define ERROR_INFO_MESSAGE() ( rb_obj_as_string( rb_gv_get("$!") ) )
149
+ #endif