amalgalite 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/HISTORY +4 -0
- data/LICENSE +31 -0
- data/README +28 -0
- data/ext/amalgalite3.c +191 -0
- data/ext/amalgalite3.h +97 -0
- data/ext/amalgalite3_constants.c +179 -0
- data/ext/amalgalite3_database.c +458 -0
- data/ext/amalgalite3_statement.c +546 -0
- data/ext/gen_constants.rb +114 -0
- data/ext/mkrf_conf.rb +6 -0
- data/ext/sqlite3.c +87003 -0
- data/ext/sqlite3.h +5638 -0
- data/ext/sqlite3_options.h +4 -0
- data/ext/sqlite3ext.h +362 -0
- data/gemspec.rb +50 -0
- data/lib/amalgalite.rb +28 -0
- data/lib/amalgalite/blob.rb +14 -0
- data/lib/amalgalite/boolean.rb +42 -0
- data/lib/amalgalite/column.rb +83 -0
- data/lib/amalgalite/database.rb +505 -0
- data/lib/amalgalite/index.rb +27 -0
- data/lib/amalgalite/paths.rb +70 -0
- data/lib/amalgalite/profile_tap.rb +130 -0
- data/lib/amalgalite/schema.rb +90 -0
- data/lib/amalgalite/sqlite3.rb +4 -0
- data/lib/amalgalite/sqlite3/constants.rb +48 -0
- data/lib/amalgalite/sqlite3/version.rb +38 -0
- data/lib/amalgalite/statement.rb +307 -0
- data/lib/amalgalite/table.rb +34 -0
- data/lib/amalgalite/taps/console.rb +27 -0
- data/lib/amalgalite/taps/io.rb +71 -0
- data/lib/amalgalite/trace_tap.rb +35 -0
- data/lib/amalgalite/type_map.rb +60 -0
- data/lib/amalgalite/type_maps/default_map.rb +153 -0
- data/lib/amalgalite/type_maps/storage_map.rb +41 -0
- data/lib/amalgalite/type_maps/text_map.rb +23 -0
- data/lib/amalgalite/version.rb +32 -0
- data/lib/amalgalite/view.rb +24 -0
- data/spec/amalgalite_spec.rb +4 -0
- data/spec/boolean_spec.rb +26 -0
- data/spec/database_spec.rb +222 -0
- data/spec/default_map_spec.rb +85 -0
- data/spec/integeration_spec.rb +111 -0
- data/spec/paths_spec.rb +28 -0
- data/spec/schema_spec.rb +46 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/sqlite3/constants_spec.rb +25 -0
- data/spec/sqlite3/version_spec.rb +14 -0
- data/spec/sqlite3_spec.rb +34 -0
- data/spec/statement_spec.rb +116 -0
- data/spec/storage_map_spec.rb +41 -0
- data/spec/tap_spec.rb +59 -0
- data/spec/text_map_spec.rb +23 -0
- data/spec/type_map_spec.rb +17 -0
- data/spec/version_spec.rb +9 -0
- data/tasks/announce.rake +38 -0
- data/tasks/config.rb +108 -0
- data/tasks/distribution.rake +38 -0
- data/tasks/documentation.rake +31 -0
- data/tasks/extension.rake +45 -0
- data/tasks/rspec.rake +32 -0
- data/tasks/rubyforge.rake +48 -0
- data/tasks/utils.rb +80 -0
- metadata +165 -0
@@ -0,0 +1,546 @@
|
|
1
|
+
#include "amalgalite3.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
|
+
VALUE cAS_Statement; /* class Amalgliate::SQLite3::Statement */
|
10
|
+
|
11
|
+
/**
|
12
|
+
* call-seq:
|
13
|
+
* stmt.bind_null( position ) -> nil
|
14
|
+
*
|
15
|
+
* bind a null value to the variable at postion.
|
16
|
+
*
|
17
|
+
*/
|
18
|
+
VALUE am_sqlite3_statement_bind_null(VALUE self, VALUE position )
|
19
|
+
{
|
20
|
+
am_sqlite3_stmt *am_stmt;
|
21
|
+
int pos = FIX2INT( position );
|
22
|
+
int rc;
|
23
|
+
|
24
|
+
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
|
25
|
+
rc = sqlite3_bind_null( am_stmt->stmt, pos );
|
26
|
+
if ( SQLITE_OK != rc ) {
|
27
|
+
rb_raise(eAS_Error, "Error binding NULL at position %d in statement: [SQLITE_ERROR %d] : %s\n",
|
28
|
+
pos,
|
29
|
+
rc, sqlite3_errmsg( sqlite3_db_handle( am_stmt->stmt) ));
|
30
|
+
}
|
31
|
+
|
32
|
+
return INT2FIX(rc);
|
33
|
+
}
|
34
|
+
/**
|
35
|
+
* call-seq:
|
36
|
+
* stmt.bind_double( position, value ) -> nil
|
37
|
+
*
|
38
|
+
* bind a double value to the variable at postion.
|
39
|
+
*
|
40
|
+
*/
|
41
|
+
VALUE am_sqlite3_statement_bind_double(VALUE self, VALUE position, VALUE value)
|
42
|
+
{
|
43
|
+
am_sqlite3_stmt *am_stmt;
|
44
|
+
int pos = FIX2INT( position );
|
45
|
+
double v = NUM2DBL( value );
|
46
|
+
int rc;
|
47
|
+
|
48
|
+
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
|
49
|
+
rc = sqlite3_bind_double( am_stmt->stmt, pos, v );
|
50
|
+
if ( SQLITE_OK != rc ) {
|
51
|
+
rb_raise(eAS_Error, "Error binding [%s] to double at position %d in statement: [SQLITE_ERROR %d] : %s\n",
|
52
|
+
value, pos,
|
53
|
+
rc, sqlite3_errmsg( sqlite3_db_handle( am_stmt->stmt) ));
|
54
|
+
}
|
55
|
+
|
56
|
+
return INT2FIX(rc);
|
57
|
+
}
|
58
|
+
|
59
|
+
/**
|
60
|
+
* call-seq:
|
61
|
+
* stmt.bind_int( position, value ) -> nil
|
62
|
+
*
|
63
|
+
* bind a int value to the variable at postion.
|
64
|
+
*
|
65
|
+
*/
|
66
|
+
VALUE am_sqlite3_statement_bind_int(VALUE self, VALUE position, VALUE value)
|
67
|
+
{
|
68
|
+
am_sqlite3_stmt *am_stmt;
|
69
|
+
int pos = FIX2INT( position );
|
70
|
+
int v = NUM2INT( value );
|
71
|
+
int rc;
|
72
|
+
|
73
|
+
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
|
74
|
+
rc = sqlite3_bind_int( am_stmt->stmt, pos, v );
|
75
|
+
if ( SQLITE_OK != rc ) {
|
76
|
+
rb_raise(eAS_Error, "Error binding [%s] to int at position %d in statement: [SQLITE_ERROR %d] : %s\n",
|
77
|
+
v, pos,
|
78
|
+
rc, sqlite3_errmsg( sqlite3_db_handle( am_stmt->stmt) ));
|
79
|
+
}
|
80
|
+
|
81
|
+
return INT2FIX(rc);
|
82
|
+
}
|
83
|
+
|
84
|
+
/**
|
85
|
+
* call-seq:
|
86
|
+
* stmt.bind_int64( position, value ) -> nil
|
87
|
+
*
|
88
|
+
* bind a int64 value to the variable at postion.
|
89
|
+
*
|
90
|
+
*/
|
91
|
+
VALUE am_sqlite3_statement_bind_int64(VALUE self, VALUE position, VALUE value)
|
92
|
+
{
|
93
|
+
am_sqlite3_stmt *am_stmt;
|
94
|
+
int pos = FIX2INT( position );
|
95
|
+
sqlite3_int64 v = NUM2SQLINT64( value );
|
96
|
+
int rc;
|
97
|
+
|
98
|
+
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
|
99
|
+
rc = sqlite3_bind_int64( am_stmt->stmt, pos, v );
|
100
|
+
if ( SQLITE_OK != rc ) {
|
101
|
+
rb_raise(eAS_Error, "Error binding [%s] to int64 at position %d in statement: [SQLITE_ERROR %d] : %s\n",
|
102
|
+
v, pos,
|
103
|
+
rc, sqlite3_errmsg( sqlite3_db_handle( am_stmt->stmt) ));
|
104
|
+
}
|
105
|
+
|
106
|
+
return INT2FIX(rc);
|
107
|
+
}
|
108
|
+
|
109
|
+
/**
|
110
|
+
* call-seq:
|
111
|
+
* stmt.bind_text( position, value ) -> nil
|
112
|
+
*
|
113
|
+
* bind a string value to the variable at postion.
|
114
|
+
*
|
115
|
+
*/
|
116
|
+
VALUE am_sqlite3_statement_bind_text(VALUE self, VALUE position, VALUE value)
|
117
|
+
{
|
118
|
+
am_sqlite3_stmt *am_stmt;
|
119
|
+
int pos = FIX2INT( position );
|
120
|
+
VALUE str = StringValue( value );
|
121
|
+
int rc;
|
122
|
+
|
123
|
+
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
|
124
|
+
rc = sqlite3_bind_text( am_stmt->stmt, pos, RSTRING(str)->ptr, RSTRING(str)->len, NULL );
|
125
|
+
if ( SQLITE_OK != rc ) {
|
126
|
+
rb_raise(eAS_Error, "Error binding [%s] to text at position %d in statement: [SQLITE_ERROR %d] : %s\n",
|
127
|
+
RSTRING(str)->ptr, pos,
|
128
|
+
rc, sqlite3_errmsg( sqlite3_db_handle( am_stmt->stmt) ));
|
129
|
+
}
|
130
|
+
|
131
|
+
return INT2FIX(rc);
|
132
|
+
}
|
133
|
+
/**
|
134
|
+
* call-seq:
|
135
|
+
* stmt.remaining_sql -> String
|
136
|
+
*
|
137
|
+
* returns the remainging SQL leftover from the initialization sql, or nil if
|
138
|
+
* there is no remaining SQL
|
139
|
+
*/
|
140
|
+
VALUE am_sqlite3_statement_remaining_sql(VALUE self)
|
141
|
+
{
|
142
|
+
am_sqlite3_stmt *am_stmt;
|
143
|
+
|
144
|
+
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
|
145
|
+
return am_stmt->remaining_sql;
|
146
|
+
}
|
147
|
+
/**
|
148
|
+
* call-seq:
|
149
|
+
* stmt.parameter_index( name ) -> Integer
|
150
|
+
*
|
151
|
+
* returns the index of the named parameter from the statement. Used to help
|
152
|
+
* with the :VVV, @VVV and $VVV pareamter replacement styles.
|
153
|
+
*/
|
154
|
+
VALUE am_sqlite3_statement_bind_parameter_index(VALUE self, VALUE parameter_name)
|
155
|
+
{
|
156
|
+
am_sqlite3_stmt *am_stmt;
|
157
|
+
int idx;
|
158
|
+
|
159
|
+
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
|
160
|
+
idx = sqlite3_bind_parameter_index( am_stmt->stmt, StringValuePtr( parameter_name ));
|
161
|
+
return INT2FIX( idx );
|
162
|
+
}
|
163
|
+
|
164
|
+
/**
|
165
|
+
* call-seq:
|
166
|
+
* stmt.parameter_count -> Integer
|
167
|
+
*
|
168
|
+
* return the index of the largest parameter in the in the statement. For all
|
169
|
+
* forms except ?NNN this is the number of unique parameters. Using ?NNN can
|
170
|
+
* create gaps in the list of parameters.
|
171
|
+
*
|
172
|
+
*/
|
173
|
+
VALUE am_sqlite3_statement_bind_parameter_count(VALUE self)
|
174
|
+
{
|
175
|
+
am_sqlite3_stmt *am_stmt;
|
176
|
+
|
177
|
+
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
|
178
|
+
return INT2FIX(sqlite3_bind_parameter_count( am_stmt->stmt ) );
|
179
|
+
}
|
180
|
+
|
181
|
+
/**
|
182
|
+
* call-seq:
|
183
|
+
* stmt.reset! -> nil
|
184
|
+
*
|
185
|
+
* reset the SQLite3 statement back to its initial state.
|
186
|
+
*/
|
187
|
+
VALUE am_sqlite3_statement_reset(VALUE self)
|
188
|
+
{
|
189
|
+
am_sqlite3_stmt *am_stmt;
|
190
|
+
int rc;
|
191
|
+
|
192
|
+
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
|
193
|
+
rc = sqlite3_reset( am_stmt->stmt );
|
194
|
+
if ( rc != SQLITE_OK ) {
|
195
|
+
rb_raise(eAS_Error, "Error resetting statement: [SQLITE_ERROR %d] : %s\n",
|
196
|
+
rc, sqlite3_errmsg( sqlite3_db_handle( am_stmt->stmt) ));
|
197
|
+
}
|
198
|
+
return Qnil;
|
199
|
+
}
|
200
|
+
|
201
|
+
/**
|
202
|
+
* call-seq:
|
203
|
+
* stmt.clear_bindings! -> nil
|
204
|
+
*
|
205
|
+
* reset the SQLite3 statement back to its initial state.
|
206
|
+
*/
|
207
|
+
VALUE am_sqlite3_statement_clear_bindings(VALUE self)
|
208
|
+
{
|
209
|
+
am_sqlite3_stmt *am_stmt;
|
210
|
+
int rc;
|
211
|
+
|
212
|
+
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
|
213
|
+
rc = sqlite3_clear_bindings( am_stmt->stmt );
|
214
|
+
if ( rc != SQLITE_OK ) {
|
215
|
+
rb_raise(eAS_Error, "Error resetting statement: [SQLITE_ERROR %d] : %s\n",
|
216
|
+
rc, sqlite3_errmsg( sqlite3_db_handle( am_stmt->stmt) ));
|
217
|
+
}
|
218
|
+
return Qnil;
|
219
|
+
}
|
220
|
+
|
221
|
+
|
222
|
+
/**
|
223
|
+
* call-seq:
|
224
|
+
* stmt.step -> int
|
225
|
+
*
|
226
|
+
* Step through the next piece of the SQLite3 statement
|
227
|
+
*
|
228
|
+
*/
|
229
|
+
VALUE am_sqlite3_statement_step(VALUE self)
|
230
|
+
{
|
231
|
+
am_sqlite3_stmt *am_stmt;
|
232
|
+
|
233
|
+
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
|
234
|
+
return INT2FIX( sqlite3_step( am_stmt->stmt ) );
|
235
|
+
}
|
236
|
+
|
237
|
+
/**
|
238
|
+
* call-seq:
|
239
|
+
* stmt.column_count -> Fixnum
|
240
|
+
*
|
241
|
+
* return the number of columns in the result set.
|
242
|
+
*
|
243
|
+
*/
|
244
|
+
VALUE am_sqlite3_statement_column_count(VALUE self)
|
245
|
+
{
|
246
|
+
am_sqlite3_stmt *am_stmt;
|
247
|
+
|
248
|
+
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
|
249
|
+
return INT2FIX( sqlite3_column_count( am_stmt->stmt ) );
|
250
|
+
}
|
251
|
+
|
252
|
+
/**
|
253
|
+
* call-seq:
|
254
|
+
* stmt.column_name( index ) -> String
|
255
|
+
*
|
256
|
+
* Return the column name at the ith column in the result set. The left-most column
|
257
|
+
* is number 0.
|
258
|
+
*
|
259
|
+
*/
|
260
|
+
VALUE am_sqlite3_statement_column_name(VALUE self, VALUE v_idx)
|
261
|
+
{
|
262
|
+
am_sqlite3_stmt *am_stmt;
|
263
|
+
int idx = FIX2INT( v_idx );
|
264
|
+
|
265
|
+
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
|
266
|
+
|
267
|
+
return rb_str_new2( sqlite3_column_name( am_stmt->stmt, idx ) );
|
268
|
+
}
|
269
|
+
|
270
|
+
|
271
|
+
/**
|
272
|
+
* call-seq:
|
273
|
+
* stmt.column_declared_type( index ) -> String
|
274
|
+
*
|
275
|
+
* Return the declared type of the ith column in the result set. This is the
|
276
|
+
* value that was in the original CREATE TABLE statement.
|
277
|
+
*
|
278
|
+
*/
|
279
|
+
VALUE am_sqlite3_statement_column_decltype(VALUE self, VALUE v_idx)
|
280
|
+
{
|
281
|
+
am_sqlite3_stmt *am_stmt;
|
282
|
+
int idx = FIX2INT( v_idx );
|
283
|
+
const char *decltype;
|
284
|
+
|
285
|
+
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
|
286
|
+
decltype = sqlite3_column_decltype( am_stmt->stmt, idx ) ;
|
287
|
+
if ( NULL == decltype) {
|
288
|
+
return Qnil;
|
289
|
+
} else {
|
290
|
+
return rb_str_new2( decltype );
|
291
|
+
}
|
292
|
+
}
|
293
|
+
|
294
|
+
/**
|
295
|
+
* call-seq:
|
296
|
+
* stmt.column_type( index ) -> SQLite3::DataType constant
|
297
|
+
*
|
298
|
+
* Return the column type at the ith column in the result set. The left-most column
|
299
|
+
* is number 0.
|
300
|
+
*
|
301
|
+
*/
|
302
|
+
VALUE am_sqlite3_statement_column_type(VALUE self, VALUE v_idx)
|
303
|
+
{
|
304
|
+
am_sqlite3_stmt *am_stmt;
|
305
|
+
int idx = FIX2INT( v_idx );
|
306
|
+
|
307
|
+
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
|
308
|
+
return INT2FIX( sqlite3_column_type( am_stmt->stmt, idx ) );
|
309
|
+
}
|
310
|
+
|
311
|
+
/**
|
312
|
+
* call-seq:
|
313
|
+
* stmt.column_text( index ) -> String
|
314
|
+
*
|
315
|
+
* Return the data in ith column of the result as a String.
|
316
|
+
*
|
317
|
+
*/
|
318
|
+
VALUE am_sqlite3_statement_column_text(VALUE self, VALUE v_idx)
|
319
|
+
{
|
320
|
+
am_sqlite3_stmt *am_stmt;
|
321
|
+
int idx = FIX2INT( v_idx );
|
322
|
+
|
323
|
+
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
|
324
|
+
return rb_str_new2( (const char*)sqlite3_column_text( am_stmt->stmt, idx ) );
|
325
|
+
}
|
326
|
+
|
327
|
+
/**
|
328
|
+
* call-seq:
|
329
|
+
* stmt.column_double( index ) -> Float
|
330
|
+
*
|
331
|
+
* Return the data in ith column of the result as an Float
|
332
|
+
*
|
333
|
+
*/
|
334
|
+
VALUE am_sqlite3_statement_column_double(VALUE self, VALUE v_idx)
|
335
|
+
{
|
336
|
+
am_sqlite3_stmt *am_stmt;
|
337
|
+
int idx = FIX2INT( v_idx );
|
338
|
+
|
339
|
+
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
|
340
|
+
return rb_float_new( sqlite3_column_double( am_stmt->stmt, idx )) ;
|
341
|
+
}
|
342
|
+
|
343
|
+
|
344
|
+
/**
|
345
|
+
* call-seq:
|
346
|
+
* stmt.column_int( index ) -> Integer
|
347
|
+
*
|
348
|
+
* Return the data in ith column of the result as an Integer
|
349
|
+
*
|
350
|
+
*/
|
351
|
+
VALUE am_sqlite3_statement_column_int(VALUE self, VALUE v_idx)
|
352
|
+
{
|
353
|
+
am_sqlite3_stmt *am_stmt;
|
354
|
+
int idx = FIX2INT( v_idx );
|
355
|
+
|
356
|
+
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
|
357
|
+
return INT2NUM( sqlite3_column_int( am_stmt->stmt, idx )) ;
|
358
|
+
}
|
359
|
+
|
360
|
+
|
361
|
+
/**
|
362
|
+
* call-seq:
|
363
|
+
* stmt.column_int64( index ) -> Integer
|
364
|
+
*
|
365
|
+
* Return the data in ith column of the result as an Integer
|
366
|
+
*
|
367
|
+
*/
|
368
|
+
VALUE am_sqlite3_statement_column_int64(VALUE self, VALUE v_idx)
|
369
|
+
{
|
370
|
+
am_sqlite3_stmt *am_stmt;
|
371
|
+
int idx = FIX2INT( v_idx );
|
372
|
+
|
373
|
+
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
|
374
|
+
return SQLINT64_2NUM( sqlite3_column_int64( am_stmt->stmt, idx )) ;
|
375
|
+
}
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
/**
|
380
|
+
* call-seq:
|
381
|
+
* stmt.column_database_name( index ) -> String
|
382
|
+
*
|
383
|
+
* Return the database name where the data in the ith column of the result set
|
384
|
+
* comes from.
|
385
|
+
*
|
386
|
+
*/
|
387
|
+
VALUE am_sqlite3_statement_column_database_name(VALUE self, VALUE v_idx)
|
388
|
+
{
|
389
|
+
am_sqlite3_stmt *am_stmt;
|
390
|
+
int idx = FIX2INT( v_idx );
|
391
|
+
const char *n ;
|
392
|
+
|
393
|
+
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
|
394
|
+
n = sqlite3_column_database_name( am_stmt->stmt, idx ) ;
|
395
|
+
return ( n == NULL ? Qnil : rb_str_new2( n ) );
|
396
|
+
}
|
397
|
+
|
398
|
+
/**
|
399
|
+
* call-seq:
|
400
|
+
* stmt.column_table_name( index ) -> String
|
401
|
+
*
|
402
|
+
* Return the table name where the data in the ith column of the result set
|
403
|
+
* comes from.
|
404
|
+
*
|
405
|
+
*/
|
406
|
+
VALUE am_sqlite3_statement_column_table_name(VALUE self, VALUE v_idx)
|
407
|
+
{
|
408
|
+
am_sqlite3_stmt *am_stmt;
|
409
|
+
int idx = FIX2INT( v_idx );
|
410
|
+
const char *n ;
|
411
|
+
|
412
|
+
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
|
413
|
+
n = sqlite3_column_table_name( am_stmt->stmt, idx );
|
414
|
+
return ( n == NULL ? Qnil : rb_str_new2( n ) );
|
415
|
+
}
|
416
|
+
|
417
|
+
|
418
|
+
/**
|
419
|
+
* call-seq:
|
420
|
+
* stmt.column_origin_name( index ) -> String
|
421
|
+
*
|
422
|
+
* Return the column name where the data in the ith column of the result set
|
423
|
+
* comes from.
|
424
|
+
*
|
425
|
+
*/
|
426
|
+
VALUE am_sqlite3_statement_column_origin_name(VALUE self, VALUE v_idx)
|
427
|
+
{
|
428
|
+
am_sqlite3_stmt *am_stmt;
|
429
|
+
int idx = FIX2INT( v_idx );
|
430
|
+
const char *n ;
|
431
|
+
|
432
|
+
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
|
433
|
+
n = sqlite3_column_origin_name( am_stmt->stmt, idx );
|
434
|
+
return ( n == NULL ? Qnil : rb_str_new2( n ) );
|
435
|
+
}
|
436
|
+
|
437
|
+
|
438
|
+
/**
|
439
|
+
* call-seq:
|
440
|
+
* stmt.sql -> String
|
441
|
+
*
|
442
|
+
* Return a copy of the original string used to create the prepared statement.
|
443
|
+
*/
|
444
|
+
VALUE am_sqlite3_statement_sql(VALUE self)
|
445
|
+
{
|
446
|
+
|
447
|
+
am_sqlite3_stmt *am_stmt;
|
448
|
+
|
449
|
+
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
|
450
|
+
return rb_str_new2( sqlite3_sql( am_stmt->stmt ) );
|
451
|
+
|
452
|
+
}
|
453
|
+
|
454
|
+
/**
|
455
|
+
* call-seq:
|
456
|
+
* stmt.close -> nil
|
457
|
+
*
|
458
|
+
* Closes the statement. If there is a problem closing the statement then an
|
459
|
+
* error is raised.
|
460
|
+
*/
|
461
|
+
VALUE am_sqlite3_statement_close( VALUE self )
|
462
|
+
{
|
463
|
+
|
464
|
+
am_sqlite3_stmt *am_stmt;
|
465
|
+
int rc;
|
466
|
+
|
467
|
+
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
|
468
|
+
rc = sqlite3_finalize( am_stmt->stmt );
|
469
|
+
if ( SQLITE_OK != rc ) {
|
470
|
+
rb_raise(eAS_Error, "Failure to close statment : [SQLITE_ERROR %d] : %s\n",
|
471
|
+
rc, sqlite3_errmsg( sqlite3_db_handle( am_stmt->stmt) ));
|
472
|
+
}
|
473
|
+
}
|
474
|
+
|
475
|
+
/***********************************************************************
|
476
|
+
* Ruby life cycle methods
|
477
|
+
***********************************************************************/
|
478
|
+
|
479
|
+
|
480
|
+
/*
|
481
|
+
* garbage collector free method for the am_sqlite3_statement structure
|
482
|
+
*/
|
483
|
+
void am_sqlite3_statement_free(am_sqlite3_stmt* wrapper)
|
484
|
+
{
|
485
|
+
|
486
|
+
free(wrapper);
|
487
|
+
return;
|
488
|
+
}
|
489
|
+
|
490
|
+
/*
|
491
|
+
* allocate the am_data structure
|
492
|
+
*/
|
493
|
+
VALUE am_sqlite3_statement_alloc(VALUE klass)
|
494
|
+
{
|
495
|
+
am_sqlite3_stmt *wrapper = ALLOC(am_sqlite3_stmt);
|
496
|
+
VALUE obj = (VALUE)NULL;
|
497
|
+
|
498
|
+
obj = Data_Wrap_Struct(klass, NULL, am_sqlite3_statement_free, wrapper);
|
499
|
+
return obj;
|
500
|
+
}
|
501
|
+
|
502
|
+
|
503
|
+
void Init_amalgalite3_statement( )
|
504
|
+
{
|
505
|
+
|
506
|
+
/** :stopdoc:
|
507
|
+
* These calls are here just to allow for rdoc generation
|
508
|
+
* :startdoc:
|
509
|
+
*/
|
510
|
+
VALUE ma = rb_define_module("Amalgalite");
|
511
|
+
VALUE mas = rb_define_module_under(ma, "SQLite3");
|
512
|
+
|
513
|
+
/*
|
514
|
+
* Encapsulate the SQLite3 Statement handle in a class
|
515
|
+
*/
|
516
|
+
cAS_Statement = rb_define_class_under( mas, "Statement", rb_cObject );
|
517
|
+
rb_define_alloc_func(cAS_Statement, am_sqlite3_statement_alloc);
|
518
|
+
rb_define_method(cAS_Statement, "sql", am_sqlite3_statement_sql, 0);
|
519
|
+
rb_define_method(cAS_Statement, "close", am_sqlite3_statement_close, 0);
|
520
|
+
rb_define_method(cAS_Statement, "step", am_sqlite3_statement_step, 0);
|
521
|
+
|
522
|
+
rb_define_method(cAS_Statement, "column_count", am_sqlite3_statement_column_count, 0);
|
523
|
+
rb_define_method(cAS_Statement, "column_name", am_sqlite3_statement_column_name, 1);
|
524
|
+
rb_define_method(cAS_Statement, "column_declared_type", am_sqlite3_statement_column_decltype, 1);
|
525
|
+
rb_define_method(cAS_Statement, "column_type", am_sqlite3_statement_column_type, 1);
|
526
|
+
rb_define_method(cAS_Statement, "column_text", am_sqlite3_statement_column_text, 1);
|
527
|
+
rb_define_method(cAS_Statement, "column_int", am_sqlite3_statement_column_int, 1);
|
528
|
+
rb_define_method(cAS_Statement, "column_int64", am_sqlite3_statement_column_int64, 1);
|
529
|
+
rb_define_method(cAS_Statement, "column_double", am_sqlite3_statement_column_double, 1);
|
530
|
+
|
531
|
+
rb_define_method(cAS_Statement, "column_database_name", am_sqlite3_statement_column_database_name, 1);
|
532
|
+
rb_define_method(cAS_Statement, "column_table_name", am_sqlite3_statement_column_table_name, 1);
|
533
|
+
rb_define_method(cAS_Statement, "column_origin_name", am_sqlite3_statement_column_origin_name, 1);
|
534
|
+
rb_define_method(cAS_Statement, "reset!", am_sqlite3_statement_reset, 0);
|
535
|
+
rb_define_method(cAS_Statement, "clear_bindings!", am_sqlite3_statement_clear_bindings, 0);
|
536
|
+
rb_define_method(cAS_Statement, "parameter_count", am_sqlite3_statement_bind_parameter_count, 0);
|
537
|
+
rb_define_method(cAS_Statement, "parameter_index", am_sqlite3_statement_bind_parameter_index, 1);
|
538
|
+
rb_define_method(cAS_Statement, "remaining_sql", am_sqlite3_statement_remaining_sql, 0);
|
539
|
+
rb_define_method(cAS_Statement, "bind_text", am_sqlite3_statement_bind_text, 2);
|
540
|
+
rb_define_method(cAS_Statement, "bind_int", am_sqlite3_statement_bind_int, 2);
|
541
|
+
rb_define_method(cAS_Statement, "bind_int64", am_sqlite3_statement_bind_int64, 2);
|
542
|
+
rb_define_method(cAS_Statement, "bind_double", am_sqlite3_statement_bind_double, 2);
|
543
|
+
rb_define_method(cAS_Statement, "bind_null", am_sqlite3_statement_bind_null, 1);
|
544
|
+
}
|
545
|
+
|
546
|
+
|