rubyfb 0.5.9 → 0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +36 -0
- data/Manifest +1 -0
- data/README +75 -175
- data/Rakefile +1 -1
- data/ext/Blob.c +1 -1
- data/ext/Connection.c +40 -126
- data/ext/FireRubyException.c +27 -41
- data/ext/Generator.c +61 -339
- data/ext/Generator.h +0 -5
- data/ext/ResultSet.c +201 -381
- data/ext/ResultSet.h +8 -9
- data/ext/Statement.c +495 -426
- data/ext/Statement.h +8 -11
- data/ext/Transaction.c +3 -2
- data/ext/TypeMap.c +44 -43
- data/ext/TypeMap.h +1 -1
- data/lib/active_record/connection_adapters/rubyfb_adapter.rb +370 -120
- data/lib/arel/visitors/rubyfb.rb +7 -3
- data/lib/arel/visitors/rubyfb_15compat.rb +8 -4
- data/lib/rubyfb_lib.so +0 -0
- data/lib/src.rb +76 -39
- data/rubyfb.gemspec +3 -3
- data/test/AddRemoveUserTest.rb +7 -0
- data/test/BackupRestoreTest.rb +1 -1
- data/test/BlobTest.rb +5 -5
- data/test/GeneratorTest.rb +8 -8
- data/test/KeyTest.rb +1 -2
- data/test/ResultSetTest.rb +14 -16
- data/test/RoleTest.rb +2 -2
- data/test/RowCountTest.rb +19 -19
- data/test/RowTest.rb +7 -8
- data/test/SQLTest.rb +7 -8
- data/test/StatementTest.rb +18 -24
- data/test/StoredProcedureTest.rb +80 -0
- data/test/TransactionTest.rb +1 -1
- data/test/TypeTest.rb +4 -5
- metadata +5 -5
data/ext/Connection.c
CHANGED
@@ -41,14 +41,12 @@ static VALUE getConnectionDatabase(VALUE);
|
|
41
41
|
static VALUE startConnectionTransaction(VALUE);
|
42
42
|
static VALUE connectionToString(VALUE);
|
43
43
|
static VALUE executeOnConnection(VALUE, VALUE, VALUE);
|
44
|
+
static VALUE executeOnConnectionWithParams(VALUE, VALUE, VALUE, VALUE);
|
44
45
|
static VALUE executeOnConnectionImmediate(VALUE, VALUE);
|
46
|
+
static VALUE createStatement(VALUE, VALUE);
|
45
47
|
static VALUE getConnectionUser(VALUE);
|
46
48
|
VALUE startTransactionBlock(VALUE);
|
47
49
|
VALUE startTransactionRescue(VALUE, VALUE);
|
48
|
-
VALUE executeBlock(VALUE);
|
49
|
-
VALUE executeRescue(VALUE, VALUE);
|
50
|
-
VALUE executeImmediateBlock(VALUE);
|
51
|
-
VALUE executeImmediateRescue(VALUE, VALUE);
|
52
50
|
char *createDPB(VALUE, VALUE, VALUE, short *);
|
53
51
|
|
54
52
|
/* Globals. */
|
@@ -300,8 +298,26 @@ static VALUE connectionToString(VALUE self) {
|
|
300
298
|
* non-query statement.
|
301
299
|
*
|
302
300
|
*/
|
303
|
-
|
304
|
-
return
|
301
|
+
VALUE executeOnConnection(VALUE self, VALUE sql, VALUE transaction) {
|
302
|
+
return executeOnConnectionWithParams(self, sql, rb_ary_new(), transaction);
|
303
|
+
}
|
304
|
+
|
305
|
+
/**
|
306
|
+
* This function provides the execute_for method for the Connection class.
|
307
|
+
*
|
308
|
+
* @param self A reference to the connection object to perform the
|
309
|
+
* execution through.
|
310
|
+
* @param sql A reference to the SQL statement to be executed.
|
311
|
+
* @param params Array containing parameter values for the statement.
|
312
|
+
* @param transaction A reference to the transction that the statement will
|
313
|
+
* be executed under.
|
314
|
+
*
|
315
|
+
* @return Either a ResultSet object for a query statement or nil for a
|
316
|
+
* non-query statement.
|
317
|
+
*
|
318
|
+
*/
|
319
|
+
VALUE executeOnConnectionWithParams(VALUE self, VALUE sql, VALUE params, VALUE transaction) {
|
320
|
+
return rb_execute_sql(self, sql, params, transaction);
|
305
321
|
}
|
306
322
|
|
307
323
|
/**
|
@@ -314,41 +330,23 @@ static VALUE connectionToString(VALUE self) {
|
|
314
330
|
* @return Always returns nil.
|
315
331
|
*
|
316
332
|
*/
|
317
|
-
|
318
|
-
|
319
|
-
set = Qnil,
|
320
|
-
results = Qnil,
|
321
|
-
array = rb_ary_new(),
|
322
|
-
dialect = INT2FIX(3),
|
323
|
-
statement = rb_statement_new(self, transaction, sql, dialect);
|
324
|
-
|
325
|
-
rb_ary_push(array, self);
|
326
|
-
rb_ary_push(array, transaction);
|
327
|
-
rb_ary_push(array, sql);
|
328
|
-
rb_ary_push(array, statement);
|
329
|
-
|
330
|
-
set = rb_rescue(executeBlock, array, executeRescue, array);
|
331
|
-
if(set != Qnil) {
|
332
|
-
if(TYPE(set) == T_DATA &&
|
333
|
-
RDATA(set)->dfree == (RUBY_DATA_FUNC)resultSetFree) {
|
334
|
-
rb_assign_transaction(set, transaction);
|
335
|
-
if(rb_block_given_p()) {
|
336
|
-
results = rb_rescue(executeImmediateBlock, set,
|
337
|
-
executeImmediateRescue, set);
|
338
|
-
} else {
|
339
|
-
results = set;
|
340
|
-
}
|
341
|
-
} else {
|
342
|
-
rb_funcall(transaction, rb_intern("commit"), 0);
|
343
|
-
results = set;
|
344
|
-
}
|
345
|
-
} else {
|
346
|
-
rb_funcall(transaction, rb_intern("commit"), 0);
|
347
|
-
}
|
348
|
-
|
349
|
-
return(results);
|
333
|
+
VALUE executeOnConnectionImmediate(VALUE self, VALUE sql) {
|
334
|
+
return executeOnConnection(self, sql, Qnil);
|
350
335
|
}
|
351
336
|
|
337
|
+
/**
|
338
|
+
* Create statement object
|
339
|
+
*
|
340
|
+
* @param self A reference to the connection object to perform the execution
|
341
|
+
* through.
|
342
|
+
* @param sql A reference to the SQL statement to be executed.
|
343
|
+
*
|
344
|
+
* @return Reference to the statement object.
|
345
|
+
*
|
346
|
+
*/
|
347
|
+
VALUE createStatement(VALUE self, VALUE sql) {
|
348
|
+
return rb_statement_new(self, sql);
|
349
|
+
}
|
352
350
|
|
353
351
|
/**
|
354
352
|
* This function provides the user accessor method for the Connection object.
|
@@ -398,93 +396,6 @@ VALUE startTransactionRescue(VALUE transaction, VALUE error) {
|
|
398
396
|
return(Qnil);
|
399
397
|
}
|
400
398
|
|
401
|
-
|
402
|
-
/**
|
403
|
-
* This function is used to wrap the call to the executeOnConnection() function
|
404
|
-
* made by the executeOnConnectionImmediate() function to help insure that the
|
405
|
-
* transaction is rolled back in case of an error.
|
406
|
-
*
|
407
|
-
* @param array An array of the parameters for the function to use.
|
408
|
-
*
|
409
|
-
* @return The ResultSet object generated by execution or nil if it wasn't a
|
410
|
-
* query.
|
411
|
-
*
|
412
|
-
*/
|
413
|
-
VALUE executeBlock(VALUE array) {
|
414
|
-
VALUE result = Qnil,
|
415
|
-
connection = rb_ary_entry(array, 0),
|
416
|
-
transaction = rb_ary_entry(array, 1),
|
417
|
-
sql = rb_ary_entry(array, 2),
|
418
|
-
statement = rb_ary_entry(array, 3);
|
419
|
-
|
420
|
-
result = rb_execute_statement(statement);
|
421
|
-
rb_statement_close(statement);
|
422
|
-
|
423
|
-
return(result);
|
424
|
-
}
|
425
|
-
|
426
|
-
|
427
|
-
/**
|
428
|
-
* This function provides clean up for the execution of a block associated
|
429
|
-
* with the execute method.
|
430
|
-
*
|
431
|
-
* @param array An array of the parameters for the function to use.
|
432
|
-
* @param error A reference to details relating to the exception raised.
|
433
|
-
*
|
434
|
-
* @return Would always returns nil except that it always raises an exception.
|
435
|
-
*
|
436
|
-
*/
|
437
|
-
VALUE executeRescue(VALUE array, VALUE error) {
|
438
|
-
VALUE transaction = rb_ary_entry(array, 1),
|
439
|
-
statement = rb_ary_entry(array, 3);
|
440
|
-
|
441
|
-
rb_funcall(transaction, rb_intern("rollback"), 0);
|
442
|
-
rb_statement_close(statement);
|
443
|
-
rb_exc_raise(error);
|
444
|
-
return(Qnil);
|
445
|
-
}
|
446
|
-
|
447
|
-
|
448
|
-
/**
|
449
|
-
* This function is executed to process a block passed to the execute_immedate
|
450
|
-
* method.
|
451
|
-
*
|
452
|
-
* @param set A reference to the ResultSet to be processed by the block.
|
453
|
-
*
|
454
|
-
* @return A reference to the return value generated by the block.
|
455
|
-
*
|
456
|
-
*/
|
457
|
-
VALUE executeImmediateBlock(VALUE set) {
|
458
|
-
VALUE result = Qnil,
|
459
|
-
row = rb_funcall(set, rb_intern("fetch"), 0);
|
460
|
-
|
461
|
-
while(row != Qnil) {
|
462
|
-
result = rb_yield(row);
|
463
|
-
row = rb_funcall(set, rb_intern("fetch"), 0);
|
464
|
-
}
|
465
|
-
rb_funcall(set, rb_intern("close"), 0);
|
466
|
-
|
467
|
-
return(result);
|
468
|
-
}
|
469
|
-
|
470
|
-
|
471
|
-
/**
|
472
|
-
* This function provides clean up for the execution of a block associated
|
473
|
-
* with the execute_immediate method.
|
474
|
-
*
|
475
|
-
* @param set A reference to the ResultSet object for the block.
|
476
|
-
* @param error A reference to details relating to the exception raised.
|
477
|
-
*
|
478
|
-
* @return Would always returns nil except that it always raises an exception.
|
479
|
-
*
|
480
|
-
*/
|
481
|
-
VALUE executeImmediateRescue(VALUE set, VALUE error) {
|
482
|
-
rb_funcall(set, rb_intern("close"), 0);
|
483
|
-
rb_exc_raise(error);
|
484
|
-
return(Qnil);
|
485
|
-
}
|
486
|
-
|
487
|
-
|
488
399
|
/**
|
489
400
|
* This method creates a database parameter buffer to be used in creating a
|
490
401
|
* database connection.
|
@@ -676,6 +587,7 @@ VALUE rb_connection_new(VALUE database, VALUE user, VALUE password, VALUE option
|
|
676
587
|
}
|
677
588
|
|
678
589
|
|
590
|
+
|
679
591
|
/**
|
680
592
|
* This function is called to record the beginnings of a transactions against
|
681
593
|
* a related connection.
|
@@ -760,7 +672,9 @@ void Init_Connection(VALUE module) {
|
|
760
672
|
rb_define_method(cConnection, "start_transaction", startConnectionTransaction, 0);
|
761
673
|
rb_define_method(cConnection, "to_s", connectionToString, 0);
|
762
674
|
rb_define_method(cConnection, "execute", executeOnConnection, 2);
|
675
|
+
rb_define_method(cConnection, "execute_for", executeOnConnectionWithParams, 3);
|
763
676
|
rb_define_method(cConnection, "execute_immediate", executeOnConnectionImmediate, 1);
|
677
|
+
rb_define_method(cConnection, "create_statement", createStatement, 1);
|
764
678
|
|
765
679
|
rb_define_const(cConnection, "MARK_DATABASE_DAMAGED", INT2FIX(isc_dpb_damaged));
|
766
680
|
rb_define_const(cConnection, "WRITE_POLICY", INT2FIX(isc_dpb_force_write));
|
data/ext/FireRubyException.c
CHANGED
@@ -55,8 +55,8 @@ static VALUE initializeFireRubyException(VALUE self, VALUE message) {
|
|
55
55
|
}
|
56
56
|
|
57
57
|
rb_iv_set(self, "@message", message);
|
58
|
-
rb_iv_set(self, "@sql_code", 0);
|
59
|
-
rb_iv_set(self, "@db_code", 0);
|
58
|
+
rb_iv_set(self, "@sql_code", INT2NUM(0));
|
59
|
+
rb_iv_set(self, "@db_code", INT2NUM(0));
|
60
60
|
|
61
61
|
return(self);
|
62
62
|
}
|
@@ -104,19 +104,31 @@ static VALUE getFireRubyExceptionMessage(VALUE self) {
|
|
104
104
|
|
105
105
|
|
106
106
|
/**
|
107
|
-
* This function
|
108
|
-
*
|
107
|
+
* This function provides a means to programmatically create a new instance of
|
108
|
+
* the FireRubyException class.
|
109
|
+
*
|
110
|
+
* @param message A string containing the error message for the exception.
|
111
|
+
*
|
112
|
+
* @return A reference to a newly created FireRubyException object.
|
109
113
|
*
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
+
*/
|
115
|
+
VALUE rb_fireruby_exception_new(const char *message) {
|
116
|
+
return rb_funcall(cFireRubyException, rb_intern("new"), 1, rb_str_new2(message));
|
117
|
+
}
|
118
|
+
|
119
|
+
|
120
|
+
/**
|
121
|
+
* This function raises a new FireRuby exception.
|
114
122
|
*
|
115
|
-
* @
|
123
|
+
* @param status A pointer to the Firebird status vector containing the error
|
124
|
+
* details.
|
125
|
+
* @param message A string containing a message to be prefixed to the error
|
126
|
+
* text generated by the decoding.
|
116
127
|
*
|
117
128
|
*/
|
118
|
-
|
119
|
-
VALUE
|
129
|
+
void rb_fireruby_raise(const ISC_STATUS *status, const char *prefix) {
|
130
|
+
VALUE exception = rb_exc_new2(cFireRubyException, ""),
|
131
|
+
message = rb_str_new2(""),
|
120
132
|
eol = rb_str_new2("\n");
|
121
133
|
char text[512];
|
122
134
|
int sqlCode = isc_sqlcode(status),
|
@@ -149,36 +161,10 @@ VALUE decodeException(const ISC_STATUS *status, const char *prefix) {
|
|
149
161
|
rb_str_concat(message, rb_str_new2(text));
|
150
162
|
}
|
151
163
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
/**
|
157
|
-
* This function provides a means to programmatically create a new instance of
|
158
|
-
* the FireRubyException class.
|
159
|
-
*
|
160
|
-
* @param message A string containing the error message for the exception.
|
161
|
-
*
|
162
|
-
* @return A reference to a newly created FireRubyException object.
|
163
|
-
*
|
164
|
-
*/
|
165
|
-
VALUE rb_fireruby_exception_new(const char *message) {
|
166
|
-
return rb_funcall(cFireRubyException, rb_intern("new"), 1, rb_str_new2(message));
|
167
|
-
}
|
168
|
-
|
169
|
-
|
170
|
-
/**
|
171
|
-
* This function raises a new FireRuby exception.
|
172
|
-
*
|
173
|
-
* @param status A pointer to the Firebird status vector containing the error
|
174
|
-
* details.
|
175
|
-
* @param message A string containing a message to be prefixed to the error
|
176
|
-
* text generated by the decoding.
|
177
|
-
*
|
178
|
-
*/
|
179
|
-
void rb_fireruby_raise(const ISC_STATUS *status, const char *message) {
|
180
|
-
VALUE text = decodeException(status, message);
|
181
|
-
rb_raise(cFireRubyException, "%s", StringValuePtr(text));
|
164
|
+
rb_iv_set(exception, "@message", message);
|
165
|
+
rb_iv_set(exception, "@sql_code", INT2NUM(sqlCode));
|
166
|
+
rb_iv_set(exception, "@db_code", INT2NUM(dbCode));
|
167
|
+
rb_exc_raise(exception);
|
182
168
|
}
|
183
169
|
|
184
170
|
|