rubyfb 0.6.4 → 0.6.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -55,5 +55,6 @@ VALUE rb_statement_new(VALUE, VALUE);
55
55
  VALUE rb_execute_sql(VALUE, VALUE, VALUE, VALUE);
56
56
  void Init_Statement(VALUE);
57
57
  short isCursorStatement(StatementHandle*);
58
+ VALUE getStatementMetadata(VALUE);
58
59
 
59
60
  #endif /* FIRERUBY_STATEMENT_H */
@@ -27,7 +27,6 @@
27
27
  #include "Transaction.h"
28
28
  #include "Common.h"
29
29
  #include "Connection.h"
30
- #include "ResultSet.h"
31
30
  #include "Statement.h"
32
31
 
33
32
  /* Function prototypes. */
@@ -28,10 +28,10 @@
28
28
  #include <time.h>
29
29
  #include <math.h>
30
30
  #include <limits.h>
31
+ #include "Common.h"
31
32
  #include "Blob.h"
32
33
  #include "Connection.h"
33
34
  #include "Transaction.h"
34
- #include "ResultSet.h"
35
35
  #include "Statement.h"
36
36
  #include "FireRuby.h"
37
37
  #include "rfbint.h"
@@ -42,7 +42,6 @@ VALUE createDate(const struct tm *);
42
42
  VALUE createDateTime(VALUE dt);
43
43
  VALUE createTime(VALUE dt);
44
44
  VALUE createSafeTime(const struct tm*);
45
- VALUE getConstant(const char *, VALUE);
46
45
  VALUE toDateTime(VALUE);
47
46
  VALUE rescueConvert(VALUE, VALUE);
48
47
  void storeBlob(VALUE, XSQLVAR *, ConnectionHandle *, TransactionHandle *);
@@ -57,18 +56,24 @@ void populateDateField(VALUE, XSQLVAR *);
57
56
  void populateTimeField(VALUE, XSQLVAR *);
58
57
  void populateTimestampField(VALUE, XSQLVAR *);
59
58
 
60
- ID NEW_ID, TO_F_ID, ROUND_ID, ASTERISK_ID, CLASS_ID, TRANSACTION_ID,
61
- CONNECTION_ID, STATEMENT_ID, NAME_ID, AT_VALUE_ID, AT_TYPE_ID,
62
- AT_COLUMN_ID;
59
+ static ID
60
+ RB_INTERN_NEW,
61
+ RB_INTERN_TO_F,
62
+ RB_INTERN_ROUND,
63
+ RB_INTERN_ASTERISK,
64
+ RB_INTERN_CLASS,
65
+ RB_INTERN_NAME;
66
+
67
+ static VALUE cDate, cDateTime;
63
68
 
64
69
  long long sql_scale(VALUE value, XSQLVAR *field) {
65
- value = rb_funcall(value, TO_F_ID, 0);
70
+ value = rb_funcall(value, RB_INTERN_TO_F, 0);
66
71
  if(field->sqlscale) {
67
72
  // this requires special care - decimal point shift can cause type overflow
68
73
  // the easyest way is to use ruby arithmetics (although it's not the fastes)
69
- value = rb_funcall(value, ASTERISK_ID, 1, LONG2NUM((long)pow(10, abs(field->sqlscale))));
74
+ value = rb_funcall(value, RB_INTERN_ASTERISK, 1, LONG2NUM((long)pow(10, abs(field->sqlscale))));
70
75
  }
71
- return NUM2LL(rb_funcall(value, ROUND_ID, 0));
76
+ return NUM2LL(rb_funcall(value, RB_INTERN_ROUND, 0));
72
77
  }
73
78
 
74
79
  VALUE sql_unscale(VALUE value, XSQLVAR *field) {
@@ -76,7 +81,7 @@ VALUE sql_unscale(VALUE value, XSQLVAR *field) {
76
81
  return value;
77
82
  }
78
83
  return rb_float_new(
79
- NUM2DBL(rb_funcall(value, TO_F_ID, 0)) / pow(10, abs(field->sqlscale))
84
+ NUM2DBL(rb_funcall(value, RB_INTERN_TO_F, 0)) / pow(10, abs(field->sqlscale))
80
85
  );
81
86
  }
82
87
 
@@ -92,11 +97,10 @@ VALUE sql_unscale(VALUE value, XSQLVAR *field) {
92
97
  * the field type referenced.
93
98
  *
94
99
  */
95
- VALUE toColumn(XSQLVAR *entry,
96
- VALUE metadata,
100
+ VALUE toValue(XSQLVAR *entry,
97
101
  VALUE connection,
98
102
  VALUE transaction) {
99
- VALUE column, value = Qnil;
103
+ VALUE value = Qnil;
100
104
 
101
105
  /* Check for NULL values. */
102
106
  if(!((entry->sqltype & 1) && (*entry->sqlind < 0))) {
@@ -108,8 +112,7 @@ VALUE toColumn(XSQLVAR *entry,
108
112
  short length;
109
113
  double actual;
110
114
  BlobHandle *blob = NULL;
111
- VALUE setting = getFireRubySetting("DATE_AS_DATE"),
112
- working = Qnil;
115
+ VALUE working = Qnil;
113
116
 
114
117
  switch(type) {
115
118
  case SQL_BLOB: /* Type: BLOB */
@@ -129,7 +132,7 @@ VALUE toColumn(XSQLVAR *entry,
129
132
  datetime.tm_sec = 0;
130
133
  datetime.tm_min = 0;
131
134
  datetime.tm_hour = 0;
132
- if(setting == Qtrue) {
135
+ if(getFireRubySetting("DATE_AS_DATE") == Qtrue) {
133
136
  value = createDate(&datetime);
134
137
  } else {
135
138
  value = createSafeTime(&datetime);
@@ -180,41 +183,7 @@ VALUE toColumn(XSQLVAR *entry,
180
183
  } /* End of switch. */
181
184
  }
182
185
 
183
- column = rb_funcall(rb_cObject, NEW_ID, 0);
184
- rb_ivar_set(column, AT_COLUMN_ID, metadata);
185
- rb_ivar_set(column, AT_VALUE_ID, value);
186
- return(column);
187
- }
188
-
189
-
190
- /**
191
- * This function attempts to convert the data contents of a XSQLDA to a Ruby
192
- * array of values.
193
- *
194
- * @param results A reference to the ResultSet object to extract the data row
195
- * from.
196
- *
197
- * @return A reference to the array containing the row data from the XSQLDA.
198
- *
199
- */
200
- VALUE toRowColumns(VALUE results) {
201
- VALUE array, transaction, connection, columns;
202
- XSQLVAR *entry = NULL;
203
- StatementHandle *hStatement = NULL;
204
- int i;
205
-
206
- Data_Get_Struct(rb_funcall(results, STATEMENT_ID, 0), StatementHandle, hStatement);
207
- transaction = rb_funcall(results, TRANSACTION_ID, 0);
208
- connection = rb_funcall(results, CONNECTION_ID, 0);
209
- array = rb_ary_new2(hStatement->output->sqln);
210
-
211
- entry = hStatement->output->sqlvar;
212
- columns = getResultsColumns(results);
213
- for(i = 0; i < hStatement->output->sqln; i++, entry++) {
214
- rb_ary_store(array, i, toColumn(entry, rb_ary_entry(columns, i), connection, transaction));
215
- }
216
-
217
- return(array);
186
+ return(value);
218
187
  }
219
188
 
220
189
 
@@ -255,10 +224,10 @@ void setParameters(XSQLDA *parameters, VALUE array, VALUE transaction, VALUE con
255
224
 
256
225
  /* Check for nils to indicate null values. */
257
226
  if(value != Qnil) {
258
- VALUE name = rb_funcall(value, CLASS_ID, 0);
227
+ VALUE name = rb_funcall(value, RB_INTERN_CLASS, 0);
259
228
 
260
229
  *parameter->sqlind = 0;
261
- name = rb_funcall(name, NAME_ID, 0);
230
+ name = rb_funcall(name, RB_INTERN_NAME, 0);
262
231
  switch(type) {
263
232
  case SQL_ARRAY: /* Type: ARRAY */
264
233
  /* TO BE DONE! */
@@ -331,32 +300,7 @@ void setParameters(XSQLDA *parameters, VALUE array, VALUE transaction, VALUE con
331
300
  *
332
301
  */
333
302
  VALUE createDate(const struct tm *date) {
334
- VALUE result = Qnil,
335
- klass = Qnil;
336
-
337
- klass = getClass("Date");
338
-
339
- /* Check if we need to require date. */
340
- if(klass == Qnil) {
341
- rb_require("date");
342
- klass = getClass("Date");
343
- }
344
-
345
- /* Check that we got the Date class. */
346
- if(klass != Qnil) {
347
- VALUE arguments[3];
348
-
349
- /* Prepare the arguments. */
350
- arguments[0] = INT2FIX(date->tm_year + 1900);
351
- arguments[1] = INT2FIX(date->tm_mon + 1);
352
- arguments[2] = INT2FIX(date->tm_mday);
353
-
354
- /* Create the class instance. */
355
- result = rb_funcall2(klass, NEW_ID, 3, arguments);
356
- }
357
-
358
-
359
- return(result);
303
+ return rb_funcall(cDate, RB_INTERN_NEW, 3, INT2FIX(date->tm_year + 1900), INT2FIX(date->tm_mon + 1), INT2FIX(date->tm_mday));
360
304
  }
361
305
 
362
306
 
@@ -369,38 +313,18 @@ VALUE createDate(const struct tm *date) {
369
313
  *
370
314
  */
371
315
  VALUE createDateTime(VALUE dt) {
372
- VALUE result = Qnil,
373
- klass = Qnil;
374
-
375
316
  struct tm *datetime;
376
317
  Data_Get_Struct(dt, struct tm, datetime);
377
318
 
378
- klass = getClass("DateTime");
379
-
380
- /* Check if we need to require date. */
381
- if(klass == Qnil) {
382
- rb_require("date");
383
- klass = getClass("DateTime");
384
- }
385
-
386
- /* Check that we got the DateTime class. */
387
- if(klass != Qnil) {
388
- VALUE arguments[7];
389
-
390
- /* Prepare the arguments. */
391
- arguments[0] = INT2FIX(datetime->tm_year + 1900);
392
- arguments[1] = INT2FIX(datetime->tm_mon + 1);
393
- arguments[2] = INT2FIX(datetime->tm_mday);
394
- arguments[3] = INT2FIX(datetime->tm_hour);
395
- arguments[4] = INT2FIX(datetime->tm_min);
396
- arguments[5] = INT2FIX(datetime->tm_sec);
397
- arguments[6] = rb_funcall(rb_funcall(klass, rb_intern("now"), 0), rb_intern("offset"), 0);
398
-
399
- /* Create the class instance. */
400
- result = rb_funcall2(klass, NEW_ID, 7, arguments);
401
- }
402
-
403
- return(result);
319
+ return rb_funcall(cDateTime, RB_INTERN_NEW, 7,
320
+ INT2FIX(datetime->tm_year + 1900),
321
+ INT2FIX(datetime->tm_mon + 1),
322
+ INT2FIX(datetime->tm_mday),
323
+ INT2FIX(datetime->tm_hour),
324
+ INT2FIX(datetime->tm_min),
325
+ INT2FIX(datetime->tm_sec),
326
+ rb_funcall(rb_funcall(cDateTime, rb_intern("now"), 0), rb_intern("offset"), 0)
327
+ );
404
328
  }
405
329
 
406
330
 
@@ -413,34 +337,22 @@ VALUE createDateTime(VALUE dt) {
413
337
  *
414
338
  */
415
339
  VALUE createTime(VALUE dt) {
416
- VALUE result = Qnil,
417
- klass = Qnil;
418
-
419
340
  struct tm *datetime;
420
341
  Data_Get_Struct(dt, struct tm, datetime);
421
342
 
422
- klass = getClass("Time");
423
-
424
- /* Check that we got the Time class. */
425
- if(klass != Qnil) {
426
- VALUE arguments[6];
427
-
428
- /* Prepare the arguments. */
429
- /*fprintf(stderr, "%d-%d-%d %d:%d:%d\n", datetime->tm_year + 1900,
430
- datetime->tm_mon + 1, datetime->tm_mday, datetime->tm_hour,
431
- datetime->tm_min, datetime->tm_sec);*/
432
- arguments[0] = INT2FIX(datetime->tm_year + 1900);
433
- arguments[1] = INT2FIX(datetime->tm_mon + 1);
434
- arguments[2] = INT2FIX(datetime->tm_mday);
435
- arguments[3] = INT2FIX(datetime->tm_hour);
436
- arguments[4] = INT2FIX(datetime->tm_min);
437
- arguments[5] = INT2FIX(datetime->tm_sec);
438
-
439
- /* Create the class instance. */
440
- result = rb_funcall2(klass, rb_intern("local"), 6, arguments);
441
- }
442
-
443
- return(result);
343
+ /*fprintf(stderr, "%d-%d-%d %d:%d:%d\n", datetime->tm_year + 1900,
344
+ datetime->tm_mon + 1, datetime->tm_mday, datetime->tm_hour,
345
+ datetime->tm_min, datetime->tm_sec);*/
346
+
347
+ /* Create the class instance. */
348
+ return rb_funcall(rb_cTime, rb_intern("local"), 6,
349
+ INT2FIX(datetime->tm_year + 1900),
350
+ INT2FIX(datetime->tm_mon + 1),
351
+ INT2FIX(datetime->tm_mday),
352
+ INT2FIX(datetime->tm_hour),
353
+ INT2FIX(datetime->tm_min),
354
+ INT2FIX(datetime->tm_sec)
355
+ );
444
356
  }
445
357
 
446
358
  /**
@@ -459,138 +371,6 @@ VALUE createSafeTime(const struct tm *datetime) {
459
371
  return rb_rescue(createTime, dt, createDateTime, dt);
460
372
  }
461
373
 
462
- /**
463
- * This method fetches a Ruby constant definition. If the module specified to
464
- * the function is nil then the top level is assume
465
- *
466
- * @param name The name of the constant to be retrieved.
467
- * @param module A reference to the Ruby module that should contain the
468
- * constant.
469
- *
470
- * @return A Ruby VALUE representing the constant.
471
- *
472
- */
473
- VALUE getConstant(const char *name, VALUE module) {
474
- VALUE owner = module,
475
- constants,
476
- exists,
477
- entry = Qnil,
478
- symbol = ID2SYM(rb_intern(name));
479
-
480
- /* Check that we've got somewhere to look. */
481
- if(owner == Qnil) {
482
- owner = rb_cModule;
483
- }
484
-
485
- constants = rb_funcall(owner, rb_intern("constants"), 0),
486
- exists = rb_funcall(constants, rb_intern("include?"), 1, symbol);
487
- if(exists == Qfalse) {
488
- /* 1.8 style lookup */
489
- exists = rb_funcall(constants, rb_intern("include?"), 1, rb_str_new2(name));
490
- }
491
- if(exists != Qfalse) {
492
- entry = rb_funcall(owner, rb_intern("const_get"), 1, symbol);
493
- }
494
- return(entry);
495
- }
496
-
497
-
498
- /**
499
- * This method fetches a Ruby module definition object based on a class name.
500
- * The method is assumed to have been defined at the top level.
501
- *
502
- * @return A Ruby VALUE representing the Module requested, or nil if the
503
- * module could not be located.
504
- *
505
- */
506
- VALUE getModule(const char *name) {
507
- VALUE module = getConstant(name, Qnil);
508
-
509
- if(module != Qnil) {
510
- VALUE type = rb_funcall(module, CLASS_ID, 0);
511
-
512
- if(type != rb_cModule) {
513
- module = Qnil;
514
- }
515
- }
516
-
517
- return(module);
518
- }
519
-
520
-
521
- /**
522
- * This method fetches a Ruby class definition object based on a class name.
523
- * The class is assumed to have been defined at the top level.
524
- *
525
- * @return A Ruby VALUE representing the requested class, or nil if the class
526
- * could not be found.
527
- *
528
- */
529
- VALUE getClass(const char *name) {
530
- VALUE klass = getConstant(name, Qnil);
531
-
532
- if(klass != Qnil) {
533
- VALUE type = rb_funcall(klass, CLASS_ID, 0);
534
-
535
- if(type != rb_cClass) {
536
- klass = Qnil;
537
- }
538
- }
539
-
540
- return(klass);
541
- }
542
-
543
-
544
- /**
545
- * This method fetches a module from a specified module.
546
- *
547
- * @param name The name of the class to fetch.
548
- * @param owner The module to search for the module in.
549
- *
550
- * @return A Ruby VALUE representing the requested module, or nil if it could
551
- * not be located.
552
- *
553
- */
554
- VALUE getModuleInModule(const char *name, VALUE owner) {
555
- VALUE module = getConstant(name, owner);
556
-
557
- if(module != Qnil) {
558
- VALUE type = rb_funcall(module, CLASS_ID, 0);
559
-
560
- if(type != rb_cModule) {
561
- module = Qnil;
562
- }
563
- }
564
-
565
- return(module);
566
- }
567
-
568
-
569
- /**
570
- * This function fetches a class from a specified module.
571
- *
572
- * @param name The name of the class to be retrieved.
573
- * @param owner The module to search for the class in.
574
- *
575
- * @return A Ruby VALUE representing the requested module, or nil if it could
576
- * not be located.
577
- *
578
- */
579
- VALUE getClassInModule(const char *name, VALUE owner) {
580
- VALUE klass = getConstant(name, owner);
581
-
582
- if(klass != Qnil) {
583
- VALUE type = rb_funcall(klass, CLASS_ID, 0);
584
-
585
- if(type != rb_cClass) {
586
- klass = Qnil;
587
- }
588
- }
589
-
590
- return(klass);
591
- }
592
-
593
-
594
374
  /**
595
375
  * This function attempts to convert a VALUE to a series of date/time values.
596
376
  *
@@ -602,13 +382,12 @@ VALUE getClassInModule(const char *name, VALUE owner) {
602
382
  */
603
383
  VALUE toDateTime(VALUE value) {
604
384
  VALUE result,
605
- klass = rb_funcall(value, CLASS_ID, 0),
606
- date_time_class = getClass("DateTime");
385
+ klass = rb_funcall(value, RB_INTERN_CLASS, 0);
607
386
 
608
- if((klass == rb_cTime) || (klass == date_time_class)) {
387
+ if((klass == rb_cTime) || (klass == cDateTime)) {
609
388
  VALUE data;
610
389
 
611
- if (klass == date_time_class) {
390
+ if (klass == cDateTime) {
612
391
  value = rb_funcall(value, rb_intern("to_time"), 0);
613
392
  }
614
393
  result = rb_ary_new();
@@ -621,7 +400,7 @@ VALUE toDateTime(VALUE value) {
621
400
  rb_ary_push(result, rb_funcall(value, rb_intern("hour"), 0));
622
401
  rb_ary_push(result, rb_funcall(value, rb_intern("min"), 0));
623
402
  rb_ary_push(result, rb_funcall(value, rb_intern("sec"), 0));
624
- } else if(klass == getClass("Date")) {
403
+ } else if(klass == cDate) {
625
404
  VALUE data;
626
405
 
627
406
  result = rb_ary_new();
@@ -798,7 +577,7 @@ void populateDoubleField(VALUE value, XSQLVAR *field) {
798
577
 
799
578
  if(TYPE(value) != T_FLOAT) {
800
579
  if(rb_obj_is_kind_of(value, rb_cNumeric) || TYPE(value) == T_STRING) {
801
- actual = rb_funcall(value, TO_F_ID, 0);
580
+ actual = rb_funcall(value, RB_INTERN_TO_F, 0);
802
581
  } else {
803
582
  rb_fireruby_raise(NULL,
804
583
  "Error converting input parameter to double.");
@@ -825,7 +604,7 @@ void populateFloatField(VALUE value, XSQLVAR *field) {
825
604
 
826
605
  if(TYPE(value) != T_FLOAT) {
827
606
  if(rb_obj_is_kind_of(value, rb_cNumeric) || TYPE(value) == T_STRING) {
828
- actual = rb_funcall(value, TO_F_ID, 0);
607
+ actual = rb_funcall(value, RB_INTERN_TO_F, 0);
829
608
  } else {
830
609
  rb_fireruby_raise(NULL,
831
610
  "Error converting input parameter to double.");
@@ -939,7 +718,6 @@ void populateTimeField(VALUE value, XSQLVAR *field) {
939
718
  field->sqltype = SQL_TYPE_TIME;
940
719
  }
941
720
 
942
-
943
721
  /**
944
722
  * This method populates a date output field.
945
723
  *
@@ -967,17 +745,14 @@ void populateTimestampField(VALUE value, XSQLVAR *field) {
967
745
  field->sqltype = SQL_TIMESTAMP;
968
746
  }
969
747
 
970
- void Init_TypeMap() {
971
- NEW_ID = rb_intern("new");
972
- TO_F_ID = rb_intern("to_f");
973
- ROUND_ID = rb_intern("round");
974
- ASTERISK_ID = rb_intern("*");
975
- CLASS_ID = rb_intern("class");
976
- CONNECTION_ID = rb_intern("connection");
977
- TRANSACTION_ID = rb_intern("transaction");
978
- STATEMENT_ID = rb_intern("statement");
979
- NAME_ID = rb_intern("name");
980
- AT_VALUE_ID = rb_intern("@value");
981
- AT_TYPE_ID = rb_intern("@type");
982
- AT_COLUMN_ID = rb_intern("@column");
748
+ void Init_TypeMap(VALUE module) {
749
+ RB_INTERN_NEW = rb_intern("new");
750
+ RB_INTERN_TO_F = rb_intern("to_f");
751
+ RB_INTERN_ROUND = rb_intern("round");
752
+ RB_INTERN_ASTERISK = rb_intern("*");
753
+ RB_INTERN_CLASS = rb_intern("class");
754
+ RB_INTERN_NAME = rb_intern("name");
755
+
756
+ cDate = getClass("Date");
757
+ cDateTime = getClass("DateTime");
983
758
  }