amalgalite 1.8.0-x64-mingw-ucrt

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTING.md +60 -0
  3. data/HISTORY.md +386 -0
  4. data/LICENSE +31 -0
  5. data/Manifest.txt +105 -0
  6. data/README.md +62 -0
  7. data/Rakefile +27 -0
  8. data/TODO.md +57 -0
  9. data/bin/amalgalite-pack +147 -0
  10. data/examples/a.rb +9 -0
  11. data/examples/blob.rb +88 -0
  12. data/examples/bootstrap.rb +36 -0
  13. data/examples/define_aggregate.rb +75 -0
  14. data/examples/define_function.rb +104 -0
  15. data/examples/fts5.rb +152 -0
  16. data/examples/gem-db.rb +94 -0
  17. data/examples/require_me.rb +11 -0
  18. data/examples/requires.rb +42 -0
  19. data/examples/schema-info.rb +34 -0
  20. data/ext/amalgalite/c/amalgalite.c +355 -0
  21. data/ext/amalgalite/c/amalgalite.h +151 -0
  22. data/ext/amalgalite/c/amalgalite_blob.c +240 -0
  23. data/ext/amalgalite/c/amalgalite_constants.c +1432 -0
  24. data/ext/amalgalite/c/amalgalite_database.c +1188 -0
  25. data/ext/amalgalite/c/amalgalite_requires_bootstrap.c +282 -0
  26. data/ext/amalgalite/c/amalgalite_statement.c +649 -0
  27. data/ext/amalgalite/c/extconf.rb +71 -0
  28. data/ext/amalgalite/c/gen_constants.rb +353 -0
  29. data/ext/amalgalite/c/notes.txt +134 -0
  30. data/ext/amalgalite/c/sqlite3.c +243616 -0
  31. data/ext/amalgalite/c/sqlite3.h +12894 -0
  32. data/ext/amalgalite/c/sqlite3_options.h +4 -0
  33. data/ext/amalgalite/c/sqlite3ext.h +705 -0
  34. data/lib/amalgalite/3.1/amalgalite.so +0 -0
  35. data/lib/amalgalite/aggregate.rb +73 -0
  36. data/lib/amalgalite/blob.rb +186 -0
  37. data/lib/amalgalite/boolean.rb +42 -0
  38. data/lib/amalgalite/busy_timeout.rb +47 -0
  39. data/lib/amalgalite/column.rb +99 -0
  40. data/lib/amalgalite/core_ext/kernel/require.rb +21 -0
  41. data/lib/amalgalite/csv_table_importer.rb +75 -0
  42. data/lib/amalgalite/database.rb +933 -0
  43. data/lib/amalgalite/function.rb +61 -0
  44. data/lib/amalgalite/index.rb +43 -0
  45. data/lib/amalgalite/memory_database.rb +15 -0
  46. data/lib/amalgalite/packer.rb +231 -0
  47. data/lib/amalgalite/paths.rb +80 -0
  48. data/lib/amalgalite/profile_tap.rb +131 -0
  49. data/lib/amalgalite/progress_handler.rb +21 -0
  50. data/lib/amalgalite/requires.rb +151 -0
  51. data/lib/amalgalite/schema.rb +225 -0
  52. data/lib/amalgalite/sqlite3/constants.rb +95 -0
  53. data/lib/amalgalite/sqlite3/database/function.rb +48 -0
  54. data/lib/amalgalite/sqlite3/database/status.rb +68 -0
  55. data/lib/amalgalite/sqlite3/status.rb +60 -0
  56. data/lib/amalgalite/sqlite3/version.rb +55 -0
  57. data/lib/amalgalite/sqlite3.rb +6 -0
  58. data/lib/amalgalite/statement.rb +421 -0
  59. data/lib/amalgalite/table.rb +91 -0
  60. data/lib/amalgalite/taps/console.rb +27 -0
  61. data/lib/amalgalite/taps/io.rb +74 -0
  62. data/lib/amalgalite/taps.rb +2 -0
  63. data/lib/amalgalite/trace_tap.rb +35 -0
  64. data/lib/amalgalite/type_map.rb +63 -0
  65. data/lib/amalgalite/type_maps/default_map.rb +166 -0
  66. data/lib/amalgalite/type_maps/storage_map.rb +38 -0
  67. data/lib/amalgalite/type_maps/text_map.rb +21 -0
  68. data/lib/amalgalite/version.rb +8 -0
  69. data/lib/amalgalite/view.rb +26 -0
  70. data/lib/amalgalite.rb +51 -0
  71. data/spec/aggregate_spec.rb +158 -0
  72. data/spec/amalgalite_spec.rb +4 -0
  73. data/spec/blob_spec.rb +78 -0
  74. data/spec/boolean_spec.rb +24 -0
  75. data/spec/busy_handler.rb +157 -0
  76. data/spec/data/iso-3166-country.txt +242 -0
  77. data/spec/data/iso-3166-schema.sql +22 -0
  78. data/spec/data/iso-3166-subcountry.txt +3995 -0
  79. data/spec/data/make-iso-db.sh +12 -0
  80. data/spec/database_spec.rb +505 -0
  81. data/spec/default_map_spec.rb +92 -0
  82. data/spec/function_spec.rb +78 -0
  83. data/spec/integeration_spec.rb +97 -0
  84. data/spec/iso_3166_database.rb +58 -0
  85. data/spec/json_spec.rb +24 -0
  86. data/spec/packer_spec.rb +60 -0
  87. data/spec/paths_spec.rb +28 -0
  88. data/spec/progress_handler_spec.rb +91 -0
  89. data/spec/requires_spec.rb +54 -0
  90. data/spec/rtree_spec.rb +66 -0
  91. data/spec/schema_spec.rb +131 -0
  92. data/spec/spec_helper.rb +48 -0
  93. data/spec/sqlite3/constants_spec.rb +108 -0
  94. data/spec/sqlite3/database_status_spec.rb +36 -0
  95. data/spec/sqlite3/status_spec.rb +22 -0
  96. data/spec/sqlite3/version_spec.rb +28 -0
  97. data/spec/sqlite3_spec.rb +53 -0
  98. data/spec/statement_spec.rb +168 -0
  99. data/spec/storage_map_spec.rb +38 -0
  100. data/spec/tap_spec.rb +57 -0
  101. data/spec/text_map_spec.rb +20 -0
  102. data/spec/type_map_spec.rb +14 -0
  103. data/spec/version_spec.rb +8 -0
  104. data/tasks/custom.rake +101 -0
  105. data/tasks/default.rake +244 -0
  106. data/tasks/extension.rake +28 -0
  107. data/tasks/this.rb +208 -0
  108. metadata +325 -0
@@ -0,0 +1,240 @@
1
+ #include "amalgalite.h"
2
+ /**
3
+ * Copyright (c) 2008 Jeremy Hinegardner
4
+ * All rights reserved. See LICENSE and/or COPYING for details.
5
+ *
6
+ * vim: shiftwidth=4
7
+ */
8
+
9
+ /* class Amalgliate::SQLite3::Blob */
10
+ VALUE cAS_Blob;
11
+
12
+ /**
13
+ * call-seq:
14
+ * Blob.new( database, table_name, column_name, row_id, flag ) -> Blob
15
+ *
16
+ * Create a new Blob object and associate it with the approriate, database,
17
+ * table, column and row. +flag+ indicates if the Blob is to be opened for
18
+ * writing "w" or reading "r".
19
+ *
20
+ */
21
+ VALUE am_sqlite3_blob_initialize( VALUE self, VALUE db, VALUE db_name, VALUE table_name, VALUE column_name, VALUE rowid, VALUE flag)
22
+ {
23
+ am_sqlite3_blob *am_blob;
24
+ int rc;
25
+ am_sqlite3 *am_db;
26
+ char *zDb = StringValuePtr( db_name );
27
+ char *zTable = StringValuePtr( table_name );
28
+ char *zColumn = StringValuePtr( column_name );
29
+ sqlite3_int64 iRow = NUM2SQLINT64( rowid ) ;
30
+ VALUE flag_str = StringValue( flag );
31
+ int flags = 0;
32
+
33
+ /* extract the blob struct */
34
+ Data_Get_Struct(self, am_sqlite3_blob, am_blob);
35
+
36
+ /* extract the sqlite3 db struct */
37
+ Data_Get_Struct(db, am_sqlite3, am_db);
38
+
39
+ /* make sure that the flags are valid, only 'r' or 'w' are allowed */
40
+ if ( ( RSTRING_LEN( flag_str ) != 1) ||
41
+ ( ( 'r' != RSTRING_PTR( flag_str )[0] ) &&
42
+ ( 'w' != RSTRING_PTR( flag_str )[0] ))) {
43
+ rb_raise( eAS_Error, "Error opening Blob in db = %s, table = %s, column = %s, rowid = %lu. Invalid flag '%s'. Must be either 'w' or 'r'\n",
44
+ zDb, zTable, zColumn, (unsigned long)iRow, RSTRING_PTR( flag_str ));
45
+ }
46
+
47
+ /* switch to write mode */
48
+ if ( 'w' == RSTRING_PTR( flag_str )[0] ) {
49
+ flags = 1;
50
+ }
51
+
52
+ /* open the blob and associate the db to it */
53
+ rc = sqlite3_blob_open( am_db->db, zDb, zTable, zColumn, iRow, flags, &( am_blob->blob ) );
54
+ if ( SQLITE_OK != rc ) {
55
+ rb_raise( eAS_Error, "Error opening Blob in db = %s, table = %s, column = %s, rowid = %lu : [SQLITE_ERROR %d] %s\n", zDb, zTable, zColumn, (unsigned long)iRow, rc, sqlite3_errmsg( am_db->db) );
56
+ }
57
+ am_blob->length = sqlite3_blob_bytes( am_blob->blob );
58
+ am_blob->db = am_db->db;
59
+
60
+ /* if a block is given then yield self and close the blob when done */
61
+ if ( rb_block_given_p() ) {
62
+ rb_yield( self );
63
+ am_sqlite3_blob_close( self );
64
+ return Qnil;
65
+ } else {
66
+ return self;
67
+ }
68
+ }
69
+
70
+ /**
71
+ * call-seq:
72
+ * blob.close -> nil
73
+ *
74
+ * Closes the blob.
75
+ */
76
+ VALUE am_sqlite3_blob_close( VALUE self )
77
+ {
78
+ am_sqlite3_blob *am_blob;
79
+ int rc;
80
+
81
+ Data_Get_Struct(self, am_sqlite3_blob, am_blob);
82
+ rc = sqlite3_blob_close( am_blob->blob );
83
+ if ( SQLITE_OK != rc ) {
84
+ rb_raise(eAS_Error, "Error closing blob: [SQLITE_ERROR %d] %s\n",
85
+ rc, sqlite3_errmsg( am_blob->db ));
86
+ }
87
+
88
+
89
+ return Qnil;
90
+ }
91
+
92
+
93
+ /**
94
+ * call-seq:
95
+ * blob.length -> length in bytes of the blob
96
+ *
97
+ * Returns the number of bytes in the blob.
98
+ */
99
+ VALUE am_sqlite3_blob_length( VALUE self )
100
+ {
101
+ am_sqlite3_blob *am_blob;
102
+
103
+ Data_Get_Struct(self, am_sqlite3_blob, am_blob);
104
+
105
+ return INT2FIX( am_blob->length );
106
+ }
107
+
108
+ /**
109
+ * call-seq:
110
+ * blob.read( int ) -> String containting int number of bytes or nil if eof.
111
+ *
112
+ * returns int number of bytes as a String from the database
113
+ */
114
+ VALUE am_sqlite3_blob_read( VALUE self, VALUE length )
115
+ {
116
+ am_sqlite3_blob *am_blob;
117
+ int rc;
118
+ int n = NUM2INT( length );
119
+ void *buf = NULL;
120
+ VALUE result;
121
+
122
+ Data_Get_Struct(self, am_sqlite3_blob, am_blob);
123
+
124
+ /* we have to be exact on the number of bytes to read. n + current_offset
125
+ * cannot be larger than the blob's length
126
+ */
127
+ if ( (n + am_blob->current_offset > am_blob->length)) {
128
+ n = am_blob->length - am_blob->current_offset;
129
+ }
130
+
131
+ if ( am_blob->current_offset == am_blob->length ) {
132
+ return Qnil;
133
+ }
134
+
135
+ buf = (void *)malloc( n );
136
+ rc = sqlite3_blob_read( am_blob->blob, buf, n, am_blob->current_offset);
137
+
138
+ if ( rc != SQLITE_OK ) {
139
+ rb_raise(eAS_Error, "Error reading %d bytes blob at offset %d: [SQLITE_ERROR %d] %s\n",
140
+ n, am_blob->current_offset, rc, sqlite3_errmsg( am_blob->db ));
141
+ }
142
+
143
+ am_blob->current_offset += n;
144
+
145
+ result = rb_str_new( (char*)buf, n );
146
+ free( buf );
147
+ return result;
148
+
149
+ }
150
+
151
+ /**
152
+ * call-seq:
153
+ * blob.write( buf ) -> int
154
+ *
155
+ * writes the contents of the string buffer to the blob and returns the number
156
+ * of bytes written.
157
+ *
158
+ */
159
+ VALUE am_sqlite3_blob_write( VALUE self, VALUE buf )
160
+ {
161
+ am_sqlite3_blob *am_blob;
162
+ int rc;
163
+ VALUE str = StringValue( buf );
164
+ int n = (int)RSTRING_LEN( str );
165
+ char *chk_buf = NULL;
166
+
167
+ Data_Get_Struct(self, am_sqlite3_blob, am_blob);
168
+
169
+ rc = sqlite3_blob_write( am_blob->blob, RSTRING_PTR(str), n, am_blob->current_offset);
170
+
171
+ if ( rc != SQLITE_OK ) {
172
+ rb_raise(eAS_Error, "Error writing %d bytes blob at offset %d: [SQLITE_ERROR %d] %s\n",
173
+ n, am_blob->current_offset, rc, sqlite3_errmsg( am_blob->db ));
174
+ }
175
+
176
+ chk_buf = (char *) malloc( n + 1);
177
+ chk_buf[n] = '\0';
178
+ sqlite3_blob_read( am_blob->blob, chk_buf, n, 0);
179
+
180
+ am_blob->current_offset += n;
181
+
182
+ return INT2FIX( n );
183
+
184
+ }
185
+
186
+
187
+ /***********************************************************************
188
+ * Ruby life cycle methods
189
+ ***********************************************************************/
190
+
191
+ /*
192
+ * garbage collector free method for the am_sqlite3_blob structure
193
+ */
194
+ void am_sqlite3_blob_free(am_sqlite3_blob* wrapper)
195
+ {
196
+ free(wrapper);
197
+ return;
198
+ }
199
+
200
+ /*
201
+ * allocate the am_blob structure
202
+ */
203
+ VALUE am_sqlite3_blob_alloc(VALUE klass)
204
+ {
205
+ am_sqlite3_blob *wrapper = ALLOC( am_sqlite3_blob );
206
+ VALUE obj ;
207
+
208
+ wrapper->current_offset = 0;
209
+ wrapper->db = NULL;
210
+ obj = Data_Wrap_Struct(klass, NULL, am_sqlite3_blob_free, wrapper);
211
+ return obj;
212
+ }
213
+
214
+
215
+ /**
216
+ * Document-class: Amalgalite::SQLite3::Blob
217
+ *
218
+ * The Blob class enables incremental IO on blob items. If you do not need
219
+ * incremental IO on a binary object, then you do not need to use Blob.
220
+ */
221
+
222
+ void Init_amalgalite_blob( )
223
+ {
224
+
225
+ VALUE ma = rb_define_module("Amalgalite");
226
+ VALUE mas = rb_define_module_under(ma, "SQLite3");
227
+
228
+ /*
229
+ * Encapsulate the SQLite3 Statement handle in a class
230
+ */
231
+ cAS_Blob = rb_define_class_under( mas, "Blob", rb_cObject );
232
+ rb_define_alloc_func(cAS_Blob, am_sqlite3_blob_alloc);
233
+ rb_define_method(cAS_Blob, "initialize", am_sqlite3_blob_initialize, 6);
234
+ rb_define_method(cAS_Blob, "close", am_sqlite3_blob_close, 0);
235
+ rb_define_method(cAS_Blob, "read", am_sqlite3_blob_read, 1);
236
+ rb_define_method(cAS_Blob, "write", am_sqlite3_blob_write, 1);
237
+ rb_define_method(cAS_Blob, "length", am_sqlite3_blob_length, 0);
238
+ }
239
+
240
+