do_sqlite3 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +1 -0
- data/Manifest.txt +17 -0
- data/{README → README.txt} +1 -2
- data/Rakefile +21 -32
- data/ext/do_sqlite3_ext.c +96 -90
- data/lib/do_sqlite3/version.rb +5 -0
- data/spec/integration/do_sqlite3_spec.rb +9 -5
- data/spec/integration/logging_spec.rb +4 -0
- data/spec/spec.opts +2 -0
- metadata +36 -18
data/History.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
|
data/Manifest.txt
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
History.txt
|
2
|
+
LICENSE
|
3
|
+
Manifest.txt
|
4
|
+
README.txt
|
5
|
+
Rakefile
|
6
|
+
TODO
|
7
|
+
ext/do_sqlite3_ext.c
|
8
|
+
ext/extconf.rb
|
9
|
+
lib/do_sqlite3.rb
|
10
|
+
lib/do_sqlite3/transaction.rb
|
11
|
+
lib/do_sqlite3/version.rb
|
12
|
+
spec/integration/do_sqlite3_spec.rb
|
13
|
+
spec/integration/logging_spec.rb
|
14
|
+
spec/integration/quoting_spec.rb
|
15
|
+
spec/spec.opts
|
16
|
+
spec/spec_helper.rb
|
17
|
+
spec/unit/transaction_spec.rb
|
data/{README → README.txt}
RENAMED
data/Rakefile
CHANGED
@@ -1,14 +1,10 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require 'rake/clean'
|
3
|
-
require 'rake/gempackagetask'
|
4
2
|
require 'spec/rake/spectask'
|
5
3
|
require 'pathname'
|
6
|
-
require Pathname(__FILE__).dirname.expand_path.parent + 'tasks/ext_helper'
|
7
4
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
'ext/Makefile', '**/*.db'
|
5
|
+
ROOT = Pathname(__FILE__).dirname.expand_path
|
6
|
+
|
7
|
+
require "lib/do_sqlite3/version"
|
12
8
|
|
13
9
|
JRUBY = (RUBY_PLATFORM =~ /java/) rescue nil
|
14
10
|
WINDOWS = (RUBY_PLATFORM =~ /mswin|mingw|cygwin/) rescue nil
|
@@ -16,38 +12,31 @@ WINDOWS = (RUBY_PLATFORM =~ /mswin|mingw|cygwin/) rescue nil
|
|
16
12
|
# is not entirely correct.
|
17
13
|
SUDO = (WINDOWS || JRUBY) ? '' : ('sudo' unless ENV['SUDOLESS'])
|
18
14
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
s.description = s.summary
|
27
|
-
s.author = 'Yehuda Katz'
|
28
|
-
s.email = 'wycats@gmail.com'
|
29
|
-
s.homepage = 'http://rubyforge.org/projects/dorb'
|
30
|
-
s.rubyforge_project = 'dorb'
|
31
|
-
s.require_path = 'lib'
|
32
|
-
s.extensions = %w[ ext/extconf.rb ]
|
33
|
-
s.files = FileList[ '{ext,lib,spec}/**/*.{c,rb}', 'Rakefile', *s.extra_rdoc_files ]
|
34
|
-
s.add_dependency('data_objects', "=#{s.version}")
|
35
|
-
end
|
15
|
+
AUTHOR = "Bernerd Schaefer"
|
16
|
+
EMAIL = "bj.schaefer@gmail.com"
|
17
|
+
GEM_NAME = "do_sqlite3"
|
18
|
+
GEM_VERSION = DataObjects::Sqlite3::VERSION
|
19
|
+
GEM_DEPENDENCIES = [["data_objects", GEM_VERSION]]
|
20
|
+
GEM_CLEAN = ['**/*.{o,so,bundle,log,a,gem,dSYM,obj,pdb,lib,def,exp,DS_Store}', 'ext/Makefile']
|
21
|
+
GEM_EXTRAS = { :extensions => %w[ ext/extconf.rb ], :has_rdoc => false }
|
36
22
|
|
37
|
-
|
38
|
-
|
39
|
-
|
23
|
+
PROJECT_NAME = "dorb"
|
24
|
+
PROJECT_URL = "http://rubyforge.org/projects/dorb"
|
25
|
+
PROJECT_DESCRIPTION = PROJECT_SUMMARY = "A DataObject.rb driver for MySQL"
|
26
|
+
|
27
|
+
DRIVER = true
|
28
|
+
|
29
|
+
require ROOT.parent + 'tasks/hoe'
|
40
30
|
|
41
|
-
#
|
42
|
-
setup_extension "#{spec.name}_ext", spec
|
31
|
+
# Installation
|
43
32
|
|
44
33
|
task :install => [ :package ] do
|
45
|
-
sh %{#{SUDO} gem install --local pkg/#{
|
34
|
+
sh %{#{SUDO} gem install --local pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources}, :verbose => false
|
46
35
|
end
|
47
36
|
|
48
|
-
desc "Uninstall #{
|
37
|
+
desc "Uninstall #{GEM_NAME} #{GEM_VERSION} (default ruby)"
|
49
38
|
task :uninstall => [ :clobber ] do
|
50
|
-
sh "#{SUDO} gem uninstall #{
|
39
|
+
sh "#{SUDO} gem uninstall #{GEM_NAME} -v#{GEM_VERSION} -I -x", :verbose => false
|
51
40
|
end
|
52
41
|
|
53
42
|
desc 'Run specifications'
|
data/ext/do_sqlite3_ext.c
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
#include <string.h>
|
4
4
|
#include <math.h>
|
5
5
|
#include <time.h>
|
6
|
+
#include <locale.h>
|
6
7
|
#include <sqlite3.h>
|
7
8
|
|
8
9
|
#define ID_CONST_GET rb_intern("const_get")
|
@@ -53,7 +54,7 @@ static VALUE eSqlite3Error;
|
|
53
54
|
/****** Typecasting ******/
|
54
55
|
static VALUE native_typecast(sqlite3_value *value, int type) {
|
55
56
|
VALUE ruby_value = Qnil;
|
56
|
-
|
57
|
+
|
57
58
|
switch(type) {
|
58
59
|
case SQLITE_NULL: {
|
59
60
|
ruby_value = Qnil;
|
@@ -83,7 +84,7 @@ static void reduce( do_int64 *numerator, do_int64 *denominator ) {
|
|
83
84
|
b = *denominator;
|
84
85
|
while ( a != 0 ) {
|
85
86
|
c = a; a = b % a; b = c;
|
86
|
-
}
|
87
|
+
}
|
87
88
|
*numerator = *numerator / b;
|
88
89
|
*denominator = *denominator / b;
|
89
90
|
}
|
@@ -103,7 +104,7 @@ static int jd_from_date(int year, int month, int day) {
|
|
103
104
|
static void data_objects_debug(VALUE string) {
|
104
105
|
VALUE logger = rb_funcall(mSqlite3, ID_LOGGER, 0);
|
105
106
|
int log_level = NUM2INT(rb_funcall(logger, ID_LEVEL, 0));
|
106
|
-
|
107
|
+
|
107
108
|
if (0 == log_level) {
|
108
109
|
rb_funcall(logger, ID_DEBUG, 1, string);
|
109
110
|
}
|
@@ -115,32 +116,28 @@ static VALUE parse_date(char *date) {
|
|
115
116
|
VALUE rational;
|
116
117
|
|
117
118
|
sscanf(date, "%4d-%2d-%2d", &year, &month, &day);
|
118
|
-
|
119
|
+
|
119
120
|
jd = jd_from_date(year, month, day);
|
120
|
-
|
121
|
+
|
121
122
|
// Math from Date.jd_to_ajd
|
122
123
|
ajd = jd * 2 - 1;
|
123
124
|
rational = rb_funcall(rb_cRational, rb_intern("new!"), 2, INT2NUM(ajd), INT2NUM(2));
|
124
|
-
return rb_funcall(rb_cDate, ID_NEW_DATE, 3, rational, INT2NUM(0), INT2NUM(2299161));
|
125
|
+
return rb_funcall(rb_cDate, ID_NEW_DATE, 3, rational, INT2NUM(0), INT2NUM(2299161));
|
125
126
|
}
|
126
127
|
|
127
128
|
// Creates a Rational for use as a Timezone offset to be passed to DateTime.new!
|
128
129
|
static VALUE seconds_to_offset(do_int64 num) {
|
129
|
-
do_int64 den = 86400;
|
130
|
+
do_int64 den = 86400;
|
130
131
|
reduce(&num, &den);
|
131
|
-
return rb_funcall(rb_cRational, rb_intern("new!"), 2, rb_ll2inum(num), rb_ll2inum(den));
|
132
|
+
return rb_funcall(rb_cRational, rb_intern("new!"), 2, rb_ll2inum(num), rb_ll2inum(den));
|
132
133
|
}
|
133
134
|
|
134
|
-
static VALUE timezone_to_offset(
|
135
|
+
static VALUE timezone_to_offset(int hour_offset, int minute_offset) {
|
135
136
|
do_int64 seconds = 0;
|
136
137
|
|
137
138
|
seconds += hour_offset * 3600;
|
138
139
|
seconds += minute_offset * 60;
|
139
140
|
|
140
|
-
if ('-' == sign) {
|
141
|
-
seconds *= -1;
|
142
|
-
}
|
143
|
-
|
144
141
|
return seconds_to_offset(seconds);
|
145
142
|
}
|
146
143
|
|
@@ -149,77 +146,86 @@ static VALUE parse_date_time(char *date) {
|
|
149
146
|
|
150
147
|
int year, month, day, hour, min, sec, usec, hour_offset, minute_offset;
|
151
148
|
int jd;
|
152
|
-
char sign, seperator;
|
153
149
|
do_int64 num, den;
|
154
150
|
|
151
|
+
long int gmt_offset;
|
152
|
+
int is_dst;
|
153
|
+
|
155
154
|
time_t rawtime;
|
156
155
|
struct tm * timeinfo;
|
157
156
|
|
158
157
|
int tokens_read, max_tokens;
|
159
|
-
|
158
|
+
|
160
159
|
if (0 != strchr(date, '.')) {
|
161
|
-
// This is a datetime with sub-second precision
|
162
|
-
tokens_read = sscanf(date, "%4d-%2d-%2d%
|
163
|
-
max_tokens =
|
160
|
+
// This is a datetime with sub-second precision
|
161
|
+
tokens_read = sscanf(date, "%4d-%2d-%2d%*c%2d:%2d:%2d.%d%3d:%2d", &year, &month, &day, &hour, &min, &sec, &usec, &hour_offset, &minute_offset);
|
162
|
+
max_tokens = 9;
|
164
163
|
} else {
|
165
|
-
// This is a datetime
|
166
|
-
tokens_read = sscanf(date, "%4d-%2d-%2d%
|
167
|
-
max_tokens =
|
164
|
+
// This is a datetime second precision
|
165
|
+
tokens_read = sscanf(date, "%4d-%2d-%2d%*c%2d:%2d:%2d%3d:%2d", &year, &month, &day, &hour, &min, &sec, &hour_offset, &minute_offset);
|
166
|
+
max_tokens = 8;
|
168
167
|
}
|
169
168
|
|
170
169
|
if (max_tokens == tokens_read) {
|
171
170
|
// We read the Date, Time, and Timezone info
|
171
|
+
minute_offset *= hour_offset < 0 ? -1 : 1;
|
172
172
|
} else if ((max_tokens - 1) == tokens_read) {
|
173
173
|
// We read the Date and Time, but no Minute Offset
|
174
174
|
minute_offset = 0;
|
175
|
+
} else if (tokens_read == 3) {
|
176
|
+
return parse_date(date);
|
175
177
|
} else if (tokens_read >= (max_tokens - 3)) {
|
176
|
-
// We read the Date and Time,
|
178
|
+
// We read the Date and Time, default to the current locale's offset
|
177
179
|
|
178
180
|
// Get localtime
|
179
181
|
time(&rawtime);
|
180
182
|
timeinfo = localtime(&rawtime);
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
183
|
+
|
184
|
+
is_dst = timeinfo->tm_isdst * 3600;
|
185
|
+
|
186
|
+
// Reset to GM Time
|
187
|
+
timeinfo = gmtime(&rawtime);
|
188
|
+
|
189
|
+
gmt_offset = mktime(timeinfo) - rawtime;
|
190
|
+
|
191
|
+
if ( is_dst > 0 )
|
192
|
+
gmt_offset -= is_dst;
|
193
|
+
|
194
|
+
hour_offset = -(gmt_offset / 3600);
|
195
|
+
minute_offset = -(gmt_offset % 3600 / 60);
|
196
|
+
|
187
197
|
} else {
|
188
198
|
// Something went terribly wrong
|
189
199
|
rb_raise(eSqlite3Error, "Couldn't parse date: %s", date);
|
190
200
|
}
|
191
|
-
|
201
|
+
|
192
202
|
jd = jd_from_date(year, month, day);
|
193
|
-
|
203
|
+
|
194
204
|
// Generate ajd with fractional days for the time
|
195
205
|
// Extracted from Date#jd_to_ajd, Date#day_fraction_to_time, and Rational#+ and #-
|
196
|
-
num = (
|
197
|
-
|
206
|
+
num = (hour * 1440) + (min * 24);
|
207
|
+
|
198
208
|
// Modify the numerator so when we apply the timezone everything works out
|
199
|
-
|
200
|
-
|
201
|
-
num += (hour_offset * 1440) + (minute_offset * 24);
|
202
|
-
} else {
|
203
|
-
// If the Timezone is ahead of UTC, we need to subtract the time offset
|
204
|
-
num -= (hour_offset * 1440) + (minute_offset * 24);
|
205
|
-
}
|
206
|
-
|
209
|
+
num -= (hour_offset * 1440) + (minute_offset * 24);
|
210
|
+
|
207
211
|
den = (24 * 1440);
|
208
212
|
reduce(&num, &den);
|
209
|
-
|
213
|
+
|
210
214
|
num = (num * 86400) + (sec * den);
|
211
215
|
den = den * 86400;
|
212
216
|
reduce(&num, &den);
|
213
|
-
|
217
|
+
|
214
218
|
num = (jd * den) + num;
|
215
|
-
|
216
|
-
num = num * 2
|
219
|
+
|
220
|
+
num = num * 2;
|
221
|
+
num = num - den;
|
217
222
|
den = den * 2;
|
223
|
+
|
218
224
|
reduce(&num, &den);
|
219
|
-
|
225
|
+
|
220
226
|
ajd = rb_funcall(rb_cRational, rb_intern("new!"), 2, rb_ull2inum(num), rb_ull2inum(den));
|
221
|
-
offset = timezone_to_offset(
|
222
|
-
|
227
|
+
offset = timezone_to_offset(hour_offset, minute_offset);
|
228
|
+
|
223
229
|
return rb_funcall(rb_cDateTime, ID_NEW_DATE, 3, ajd, offset, INT2NUM(2299161));
|
224
230
|
}
|
225
231
|
|
@@ -266,7 +272,7 @@ static VALUE ruby_typecast(sqlite3_value *value, char *type, int original_type)
|
|
266
272
|
} else if ( strcmp(type, "Time") == 0 ) {
|
267
273
|
ruby_value = parse_time((char*)sqlite3_value_text(value));
|
268
274
|
}
|
269
|
-
|
275
|
+
|
270
276
|
return ruby_value;
|
271
277
|
}
|
272
278
|
|
@@ -277,17 +283,17 @@ static VALUE cConnection_initialize(VALUE self, VALUE uri) {
|
|
277
283
|
int ret;
|
278
284
|
VALUE path;
|
279
285
|
sqlite3 *db;
|
280
|
-
|
286
|
+
|
281
287
|
path = rb_funcall(uri, ID_PATH, 0);
|
282
288
|
ret = sqlite3_open(StringValuePtr(path), &db);
|
283
|
-
|
289
|
+
|
284
290
|
if ( ret != SQLITE_OK ) {
|
285
291
|
rb_raise(eSqlite3Error, sqlite3_errmsg(db));
|
286
292
|
}
|
287
|
-
|
293
|
+
|
288
294
|
rb_iv_set(self, "@uri", uri);
|
289
295
|
rb_iv_set(self, "@connection", Data_Wrap_Struct(rb_cObject, 0, 0, db));
|
290
|
-
|
296
|
+
|
291
297
|
return Qtrue;
|
292
298
|
}
|
293
299
|
|
@@ -310,7 +316,7 @@ static VALUE cCommand_quote_boolean(VALUE self, VALUE value) {
|
|
310
316
|
static VALUE cCommand_quote_string(VALUE self, VALUE string) {
|
311
317
|
const char *source = StringValuePtr(string);
|
312
318
|
char *escaped_with_quotes;
|
313
|
-
|
319
|
+
|
314
320
|
// Wrap the escaped string in single-quotes, this is DO's convention
|
315
321
|
escaped_with_quotes = sqlite3_mprintf("%Q", source);
|
316
322
|
|
@@ -329,7 +335,7 @@ static VALUE build_query_from_args(VALUE klass, int count, VALUE *args) {
|
|
329
335
|
}
|
330
336
|
return query;
|
331
337
|
}
|
332
|
-
|
338
|
+
|
333
339
|
static VALUE cCommand_execute_non_query(int argc, VALUE *argv, VALUE self) {
|
334
340
|
sqlite3 *db;
|
335
341
|
char *error_message;
|
@@ -338,22 +344,22 @@ static VALUE cCommand_execute_non_query(int argc, VALUE *argv, VALUE self) {
|
|
338
344
|
int insert_id;
|
339
345
|
VALUE conn_obj;
|
340
346
|
VALUE query;
|
341
|
-
|
347
|
+
|
342
348
|
query = build_query_from_args(self, argc, argv);
|
343
349
|
data_objects_debug(query);
|
344
|
-
|
350
|
+
|
345
351
|
conn_obj = rb_iv_get(self, "@connection");
|
346
352
|
Data_Get_Struct(rb_iv_get(conn_obj, "@connection"), sqlite3, db);
|
347
|
-
|
353
|
+
|
348
354
|
status = sqlite3_exec(db, StringValuePtr(query), 0, 0, &error_message);
|
349
|
-
|
355
|
+
|
350
356
|
if ( status != SQLITE_OK ) {
|
351
357
|
rb_raise(eSqlite3Error, sqlite3_errmsg(db));
|
352
358
|
}
|
353
|
-
|
359
|
+
|
354
360
|
affected_rows = sqlite3_changes(db);
|
355
361
|
insert_id = sqlite3_last_insert_rowid(db);
|
356
|
-
|
362
|
+
|
357
363
|
return rb_funcall(cResult, ID_NEW, 3, self, INT2NUM(affected_rows), INT2NUM(insert_id));
|
358
364
|
}
|
359
365
|
|
@@ -370,29 +376,29 @@ static VALUE cCommand_execute_reader(int argc, VALUE *argv, VALUE self) {
|
|
370
376
|
|
371
377
|
conn_obj = rb_iv_get(self, "@connection");
|
372
378
|
Data_Get_Struct(rb_iv_get(conn_obj, "@connection"), sqlite3, db);
|
373
|
-
|
379
|
+
|
374
380
|
query = build_query_from_args(self, argc, argv);
|
375
381
|
data_objects_debug(query);
|
376
|
-
|
382
|
+
|
377
383
|
status = sqlite3_prepare_v2(db, StringValuePtr(query), -1, &sqlite3_reader, 0);
|
378
|
-
|
384
|
+
|
379
385
|
if ( status != SQLITE_OK ) {
|
380
386
|
rb_raise(eSqlite3Error, sqlite3_errmsg(db));
|
381
387
|
}
|
382
|
-
|
388
|
+
|
383
389
|
field_count = sqlite3_column_count(sqlite3_reader);
|
384
|
-
|
390
|
+
|
385
391
|
reader = rb_funcall(cReader, ID_NEW, 0);
|
386
392
|
rb_iv_set(reader, "@reader", Data_Wrap_Struct(rb_cObject, 0, 0, sqlite3_reader));
|
387
393
|
rb_iv_set(reader, "@field_count", INT2NUM(field_count));
|
388
|
-
|
394
|
+
|
389
395
|
field_names = rb_ary_new();
|
390
396
|
field_types = rb_iv_get(self, "@field_types");
|
391
|
-
|
397
|
+
|
392
398
|
// if ( field_types == Qnil ) {
|
393
399
|
// field_types = rb_ary_new();
|
394
400
|
// }
|
395
|
-
|
401
|
+
|
396
402
|
if ( field_types == Qnil || 0 == RARRAY(field_types)->len ) {
|
397
403
|
field_types = rb_ary_new();
|
398
404
|
} else if (RARRAY(field_types)->len != field_count) {
|
@@ -402,21 +408,21 @@ static VALUE cCommand_execute_reader(int argc, VALUE *argv, VALUE self) {
|
|
402
408
|
rb_raise(eSqlite3Error, "Field-count mismatch. Expected %d fields, but the query yielded %d", RARRAY(field_types)->len, field_count);
|
403
409
|
}
|
404
410
|
|
405
|
-
|
406
|
-
|
411
|
+
|
412
|
+
|
407
413
|
for ( i = 0; i < field_count; i++ ) {
|
408
414
|
rb_ary_push(field_names, rb_str_new2((char *)sqlite3_column_name(sqlite3_reader, i)));
|
409
415
|
}
|
410
|
-
|
416
|
+
|
411
417
|
rb_iv_set(reader, "@fields", field_names);
|
412
418
|
rb_iv_set(reader, "@field_types", field_types);
|
413
|
-
|
419
|
+
|
414
420
|
return reader;
|
415
421
|
}
|
416
422
|
|
417
423
|
static VALUE cReader_close(VALUE self) {
|
418
424
|
VALUE reader_obj = rb_iv_get(self, "@reader");
|
419
|
-
|
425
|
+
|
420
426
|
if ( reader_obj != Qnil ) {
|
421
427
|
sqlite3_stmt *reader;
|
422
428
|
Data_Get_Struct(reader_obj, sqlite3_stmt, reader);
|
@@ -438,21 +444,21 @@ static VALUE cReader_next(VALUE self) {
|
|
438
444
|
VALUE arr = rb_ary_new();
|
439
445
|
VALUE field_types;
|
440
446
|
VALUE value;
|
441
|
-
|
447
|
+
|
442
448
|
Data_Get_Struct(rb_iv_get(self, "@reader"), sqlite3_stmt, reader);
|
443
449
|
field_count = NUM2INT(rb_iv_get(self, "@field_count"));
|
444
|
-
|
450
|
+
|
445
451
|
field_types = rb_iv_get(self, "@field_types");
|
446
452
|
ft_length = RARRAY(field_types)->len;
|
447
453
|
|
448
454
|
result = sqlite3_step(reader);
|
449
|
-
|
455
|
+
|
450
456
|
rb_iv_set(self, "@state", INT2NUM(result));
|
451
|
-
|
457
|
+
|
452
458
|
if ( result != SQLITE_ROW ) {
|
453
459
|
return Qnil;
|
454
460
|
}
|
455
|
-
|
461
|
+
|
456
462
|
for ( i = 0; i < field_count; i++ ) {
|
457
463
|
if ( ft_length == 0 ) {
|
458
464
|
value = native_typecast(sqlite3_column_value(reader, i), sqlite3_column_type(reader, i));
|
@@ -462,9 +468,9 @@ static VALUE cReader_next(VALUE self) {
|
|
462
468
|
}
|
463
469
|
rb_ary_push(arr, value);
|
464
470
|
}
|
465
|
-
|
471
|
+
|
466
472
|
rb_iv_set(self, "@values", arr);
|
467
|
-
|
473
|
+
|
468
474
|
return Qtrue;
|
469
475
|
}
|
470
476
|
|
@@ -483,18 +489,18 @@ static VALUE cReader_fields(VALUE self) {
|
|
483
489
|
}
|
484
490
|
|
485
491
|
void Init_do_sqlite3_ext() {
|
486
|
-
|
492
|
+
|
487
493
|
rb_require("rubygems");
|
488
494
|
rb_require("bigdecimal");
|
489
495
|
rb_require("date");
|
490
|
-
|
491
|
-
// Get references classes needed for Date/Time parsing
|
496
|
+
|
497
|
+
// Get references classes needed for Date/Time parsing
|
492
498
|
rb_cDate = CONST_GET(rb_mKernel, "Date");
|
493
499
|
rb_cDateTime = CONST_GET(rb_mKernel, "DateTime");
|
494
500
|
rb_cTime = CONST_GET(rb_mKernel, "Time");
|
495
501
|
rb_cRational = CONST_GET(rb_mKernel, "Rational");
|
496
502
|
rb_cBigDecimal = CONST_GET(rb_mKernel, "BigDecimal");
|
497
|
-
|
503
|
+
|
498
504
|
rb_funcall(rb_mKernel, rb_intern("require"), 1, rb_str_new2("data_objects"));
|
499
505
|
|
500
506
|
ID_NEW_DATE = RUBY_VERSION_CODE < 186 ? rb_intern("new0") : rb_intern("new!");
|
@@ -509,16 +515,16 @@ void Init_do_sqlite3_ext() {
|
|
509
515
|
cDO_Command = CONST_GET(mDO, "Command");
|
510
516
|
cDO_Result = CONST_GET(mDO, "Result");
|
511
517
|
cDO_Reader = CONST_GET(mDO, "Reader");
|
512
|
-
|
518
|
+
|
513
519
|
// Initialize the DataObjects::Sqlite3 module, and define its classes
|
514
520
|
mSqlite3 = rb_define_module_under(mDO, "Sqlite3");
|
515
|
-
|
521
|
+
|
516
522
|
eSqlite3Error = rb_define_class("Sqlite3Error", rb_eStandardError);
|
517
|
-
|
523
|
+
|
518
524
|
cConnection = SQLITE3_CLASS("Connection", cDO_Connection);
|
519
525
|
rb_define_method(cConnection, "initialize", cConnection_initialize, 1);
|
520
526
|
rb_define_method(cConnection, "dispose", cConnection_dispose, 0);
|
521
|
-
|
527
|
+
|
522
528
|
cCommand = SQLITE3_CLASS("Command", cDO_Command);
|
523
529
|
rb_include_module(cCommand, cDO_Quoting);
|
524
530
|
rb_define_method(cCommand, "set_types", cCommand_set_types, 1);
|
@@ -528,11 +534,11 @@ void Init_do_sqlite3_ext() {
|
|
528
534
|
rb_define_method(cCommand, "quote_string", cCommand_quote_string, 1);
|
529
535
|
|
530
536
|
cResult = SQLITE3_CLASS("Result", cDO_Result);
|
531
|
-
|
537
|
+
|
532
538
|
cReader = SQLITE3_CLASS("Reader", cDO_Reader);
|
533
539
|
rb_define_method(cReader, "close", cReader_close, 0);
|
534
540
|
rb_define_method(cReader, "next!", cReader_next, 0);
|
535
541
|
rb_define_method(cReader, "values", cReader_values, 0);
|
536
542
|
rb_define_method(cReader, "fields", cReader_fields, 0);
|
537
|
-
|
543
|
+
|
538
544
|
}
|
@@ -5,7 +5,7 @@ describe "DataObjects::Sqlite3" do
|
|
5
5
|
include Sqlite3SpecHelpers
|
6
6
|
|
7
7
|
it "should raise error on bad connection string" do
|
8
|
-
lambda { DataObjects::Connection.new("sqlite3:///ac0d9iopalmsdcasd/asdc9pomasd/test.db") }.should raise_error("unable to open database file")
|
8
|
+
# lambda { DataObjects::Connection.new("sqlite3:///ac0d9iopalmsdcasd/asdc9pomasd/test.db") }.should raise_error("unable to open database file")
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
@@ -18,6 +18,10 @@ describe "DataObjects::Sqlite3::Result" do
|
|
18
18
|
@connection = DataObjects::Connection.new("sqlite3://#{File.expand_path(File.dirname(__FILE__))}/test.db")
|
19
19
|
end
|
20
20
|
|
21
|
+
after :all do
|
22
|
+
@connection.close
|
23
|
+
end
|
24
|
+
|
21
25
|
it "should raise an error for a bad query" do
|
22
26
|
command = @connection.create_command("INSER INTO table_which_doesnt_exist (id) VALUES (1)")
|
23
27
|
lambda { command.execute_non_query }.should raise_error('near "INSER": syntax error')
|
@@ -182,6 +186,10 @@ describe "DataObjects::Sqlite3::Result" do
|
|
182
186
|
command.execute_non_query(3, "C", "A", "Spoon", true)
|
183
187
|
end
|
184
188
|
|
189
|
+
after do
|
190
|
+
@connection.create_command("DROP TABLE sail_boats").execute_non_query
|
191
|
+
end
|
192
|
+
|
185
193
|
it "should quote a String" do
|
186
194
|
command = @connection.create_command("INSERT INTO users (name) VALUES (?)")
|
187
195
|
result = command.execute_non_query("John Doe")
|
@@ -236,9 +244,5 @@ describe "DataObjects::Sqlite3::Result" do
|
|
236
244
|
end
|
237
245
|
end
|
238
246
|
|
239
|
-
after do
|
240
|
-
@connection.create_command("DROP TABLE sail_boats").execute_non_query
|
241
|
-
end
|
242
|
-
|
243
247
|
end # describe "quoting"
|
244
248
|
end
|
@@ -7,6 +7,10 @@ describe DataObjects::Sqlite3::Command do
|
|
7
7
|
@connection = DataObjects::Connection.new("sqlite3://#{File.expand_path(File.dirname(__FILE__))}/test.db")
|
8
8
|
end
|
9
9
|
|
10
|
+
after(:each) do
|
11
|
+
@connection.close
|
12
|
+
end
|
13
|
+
|
10
14
|
describe "Executing a Reader" do
|
11
15
|
|
12
16
|
it "should log reader queries when the level is Debug (0)" do
|
data/spec/spec.opts
ADDED
metadata
CHANGED
@@ -1,57 +1,75 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: do_sqlite3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Bernerd Schaefer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-07-24 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: data_objects
|
17
|
+
type: :runtime
|
17
18
|
version_requirement:
|
18
19
|
version_requirements: !ruby/object:Gem::Requirement
|
19
20
|
requirements:
|
20
21
|
- - "="
|
21
22
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0.9.
|
23
|
+
version: 0.9.3
|
23
24
|
version:
|
24
|
-
|
25
|
-
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: hoe
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.7.0
|
34
|
+
version:
|
35
|
+
description: A DataObject.rb driver for MySQL
|
36
|
+
email:
|
37
|
+
- bj.schaefer@gmail.com
|
26
38
|
executables: []
|
27
39
|
|
28
40
|
extensions:
|
29
41
|
- ext/extconf.rb
|
30
42
|
extra_rdoc_files:
|
31
|
-
-
|
43
|
+
- History.txt
|
44
|
+
- Manifest.txt
|
45
|
+
- README.txt
|
46
|
+
files:
|
47
|
+
- History.txt
|
32
48
|
- LICENSE
|
49
|
+
- Manifest.txt
|
50
|
+
- README.txt
|
51
|
+
- Rakefile
|
33
52
|
- TODO
|
34
|
-
files:
|
35
53
|
- ext/do_sqlite3_ext.c
|
36
54
|
- ext/extconf.rb
|
37
|
-
- lib/do_sqlite3/transaction.rb
|
38
55
|
- lib/do_sqlite3.rb
|
56
|
+
- lib/do_sqlite3/transaction.rb
|
57
|
+
- lib/do_sqlite3/version.rb
|
39
58
|
- spec/integration/do_sqlite3_spec.rb
|
40
59
|
- spec/integration/logging_spec.rb
|
41
60
|
- spec/integration/quoting_spec.rb
|
61
|
+
- spec/spec.opts
|
42
62
|
- spec/spec_helper.rb
|
43
63
|
- spec/unit/transaction_spec.rb
|
44
|
-
|
45
|
-
- README
|
46
|
-
- LICENSE
|
47
|
-
- TODO
|
48
|
-
has_rdoc: true
|
64
|
+
has_rdoc: false
|
49
65
|
homepage: http://rubyforge.org/projects/dorb
|
50
66
|
post_install_message:
|
51
|
-
rdoc_options:
|
52
|
-
|
67
|
+
rdoc_options:
|
68
|
+
- --main
|
69
|
+
- README.txt
|
53
70
|
require_paths:
|
54
71
|
- lib
|
72
|
+
- ext
|
55
73
|
required_ruby_version: !ruby/object:Gem::Requirement
|
56
74
|
requirements:
|
57
75
|
- - ">="
|
@@ -67,9 +85,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
85
|
requirements: []
|
68
86
|
|
69
87
|
rubyforge_project: dorb
|
70
|
-
rubygems_version: 1.0
|
88
|
+
rubygems_version: 1.2.0
|
71
89
|
signing_key:
|
72
90
|
specification_version: 2
|
73
|
-
summary: A DataObject.rb driver for
|
91
|
+
summary: A DataObject.rb driver for MySQL
|
74
92
|
test_files: []
|
75
93
|
|