rubyfb 0.5.5 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
data/ext/TypeMap.c CHANGED
@@ -72,169 +72,149 @@ void populateTimestampField(VALUE, XSQLVAR *);
72
72
  */
73
73
  VALUE toValue(XSQLVAR *entry,
74
74
  isc_db_handle *database,
75
- isc_tr_handle *transaction)
76
- {
77
- VALUE value = rb_ary_new();
78
-
79
- /* Check for NULL values. */
80
- if(!((entry->sqltype & 1) && (*entry->sqlind < 0)))
81
- {
82
- int type = (entry->sqltype & ~1);
83
- char *array = NULL,
84
- column[256],
85
- table[256];
86
- struct tm datetime;
87
- short length;
88
- double actual;
89
- BlobHandle *blob = NULL;
90
- VALUE setting = getFireRubySetting("DATE_AS_DATE"),
91
- working = Qnil;
92
-
93
- switch(type)
94
- {
95
- case SQL_ARRAY : /* Type: ARRAY */
96
- /* TO BE DONE! */
97
- break;
98
-
99
- case SQL_BLOB: /* Type: BLOB */
100
- memset(column, 0, 256);
101
- memset(table, 0, 256);
102
- memcpy(column, entry->sqlname, entry->sqlname_length);
103
- memcpy(table, entry->relname, entry->relname_length);
104
- blob = openBlob(*(ISC_QUAD *)entry->sqldata, column, table, database,
105
- transaction);
106
- working = Data_Wrap_Struct(cBlob, NULL, blobFree, blob);
107
- rb_ary_push(value, initializeBlob(working));
108
- rb_ary_push(value, getColumnType(entry));
109
- break;
110
-
111
- case SQL_TYPE_DATE : /* Type: DATE */
112
- memset(&datetime, 0, sizeof(struct tm));
113
- isc_decode_sql_date((ISC_DATE *)entry->sqldata, &datetime);
114
- datetime.tm_sec = 0;
115
- datetime.tm_min = 0;
116
- datetime.tm_hour = 0;
117
- if(setting == Qtrue)
118
- {
119
- rb_ary_push(value, createDate(&datetime));
120
- }
121
- else
122
- {
123
- rb_ary_push(value, createSafeTime(&datetime));
124
- }
125
- rb_ary_push(value, getColumnType(entry));
126
- break;
127
-
128
- case SQL_DOUBLE : /* Type: DOUBLE PRECISION, DECIMAL, NUMERIC */
129
- rb_ary_push(value, rb_float_new(*((double *)entry->sqldata)));
130
- rb_ary_push(value, getColumnType(entry));
131
- break;
132
-
133
- case SQL_FLOAT : /* Type: FLOAT */
134
- rb_ary_push(value, rb_float_new(*((float *)entry->sqldata)));
135
- rb_ary_push(value, getColumnType(entry));
136
- break;
137
-
138
- case SQL_INT64 : /* Type: DECIMAL, NUMERIC */
139
- if(entry->sqlscale != 0)
140
- {
141
- double divisor = pow(10, abs(entry->sqlscale));
142
-
143
- actual = *((long long *)entry->sqldata);
144
- rb_ary_push(value, rb_float_new(actual / divisor));
145
- }
146
- else
147
- {
148
- rb_ary_push(value, LL2NUM(*((long long *)entry->sqldata)));
149
- }
150
- rb_ary_push(value, getColumnType(entry));
151
- break;
152
-
153
- case SQL_LONG : /* Type: INTEGER, DECIMAL, NUMERIC */
154
- if(entry->sqlscale != 0)
155
- {
156
- double divisor = pow(10, abs(entry->sqlscale));
157
-
158
- actual = *((int32_t *)entry->sqldata);
159
- rb_ary_push(value, rb_float_new(actual / divisor));
160
- }
161
- else
162
- {
163
- rb_ary_push(value, LONG2NUM(*((int32_t *)entry->sqldata)));
164
- }
165
- rb_ary_push(value, getColumnType(entry));
166
- break;
167
-
168
- case SQL_SHORT : /* Type: SMALLINT, DECIMAL, NUMERIC */
169
- if(entry->sqlscale != 0)
170
- {
171
- double divisor = pow(10, abs(entry->sqlscale));
172
-
173
- actual = *((short *)entry->sqldata);
174
- rb_ary_push(value, rb_float_new(actual / divisor));
175
- }
176
- else
177
- {
178
- rb_ary_push(value, INT2NUM(*((short *)entry->sqldata)));
179
- }
180
- rb_ary_push(value, getColumnType(entry));
181
- break;
182
-
183
- case SQL_TEXT : /* Type: CHAR */
184
- array = ALLOC_N(char, entry->sqllen + 1);
185
- if(array != NULL)
186
- {
187
- memset(array, 0, entry->sqllen + 1);
188
- memcpy(array, entry->sqldata, entry->sqllen);
189
- rb_ary_push(value, rb_str_new2(array));
190
- rb_ary_push(value, getColumnType(entry));
191
- free(array);
192
- }
193
- break;
194
-
195
- case SQL_TYPE_TIME : /* Type: TIME */
196
- isc_decode_sql_time((ISC_TIME *)entry->sqldata, &datetime);
197
- datetime.tm_year = 70;
198
- datetime.tm_mon = 0;
199
- datetime.tm_mday = 1;
200
- rb_ary_push(value, createSafeTime(&datetime));
201
- rb_ary_push(value, getColumnType(entry));
202
- break;
203
-
204
- case SQL_TIMESTAMP : /* Type: TIMESTAMP */
205
- isc_decode_timestamp((ISC_TIMESTAMP *)entry->sqldata, &datetime);
206
- rb_ary_push(value, createSafeTime(&datetime));
207
- rb_ary_push(value, getColumnType(entry));
208
- break;
209
-
210
- case SQL_VARYING :
211
- memcpy(&length, entry->sqldata, 2);
212
- if(length >= 0)
213
- {
214
- array = ALLOC_N(char, length + 1);
215
- if(array != NULL)
216
- {
217
- memset(array, 0, length + 1);
218
- memcpy(array, &entry->sqldata[2], length);
219
- rb_ary_push(value, rb_str_new2(array));
220
- rb_ary_push(value, getColumnType(entry));
221
- free(array);
222
- }
223
- }
224
- break;
225
-
226
- default :
227
- rb_ary_push(value, Qnil);
228
- rb_ary_push(value, Qnil);
229
- } /* End of switch. */
230
- }
231
- else
232
- {
75
+ isc_tr_handle *transaction) {
76
+ VALUE value = rb_ary_new();
77
+
78
+ /* Check for NULL values. */
79
+ if(!((entry->sqltype & 1) && (*entry->sqlind < 0))) {
80
+ int type = (entry->sqltype & ~1);
81
+ char *array = NULL,
82
+ column[256],
83
+ table[256];
84
+ struct tm datetime;
85
+ short length;
86
+ double actual;
87
+ BlobHandle *blob = NULL;
88
+ VALUE setting = getFireRubySetting("DATE_AS_DATE"),
89
+ working = Qnil;
90
+
91
+ switch(type) {
92
+ case SQL_ARRAY: /* Type: ARRAY */
93
+ /* TO BE DONE! */
94
+ break;
95
+
96
+ case SQL_BLOB: /* Type: BLOB */
97
+ memset(column, 0, 256);
98
+ memset(table, 0, 256);
99
+ memcpy(column, entry->sqlname, entry->sqlname_length);
100
+ memcpy(table, entry->relname, entry->relname_length);
101
+ blob = openBlob(*(ISC_QUAD *)entry->sqldata, column, table, database,
102
+ transaction);
103
+ working = Data_Wrap_Struct(cBlob, NULL, blobFree, blob);
104
+ rb_ary_push(value, initializeBlob(working));
105
+ rb_ary_push(value, getColumnType(entry));
106
+ break;
107
+
108
+ case SQL_TYPE_DATE: /* Type: DATE */
109
+ memset(&datetime, 0, sizeof(struct tm));
110
+ isc_decode_sql_date((ISC_DATE *)entry->sqldata, &datetime);
111
+ datetime.tm_sec = 0;
112
+ datetime.tm_min = 0;
113
+ datetime.tm_hour = 0;
114
+ if(setting == Qtrue) {
115
+ rb_ary_push(value, createDate(&datetime));
116
+ } else {
117
+ rb_ary_push(value, createSafeTime(&datetime));
118
+ }
119
+ rb_ary_push(value, getColumnType(entry));
120
+ break;
121
+
122
+ case SQL_DOUBLE: /* Type: DOUBLE PRECISION, DECIMAL, NUMERIC */
123
+ rb_ary_push(value, rb_float_new(*((double *)entry->sqldata)));
124
+ rb_ary_push(value, getColumnType(entry));
125
+ break;
126
+
127
+ case SQL_FLOAT: /* Type: FLOAT */
128
+ rb_ary_push(value, rb_float_new(*((float *)entry->sqldata)));
129
+ rb_ary_push(value, getColumnType(entry));
130
+ break;
131
+
132
+ case SQL_INT64: /* Type: DECIMAL, NUMERIC */
133
+ if(entry->sqlscale != 0) {
134
+ double divisor = pow(10, abs(entry->sqlscale));
135
+
136
+ actual = *((long long *)entry->sqldata);
137
+ rb_ary_push(value, rb_float_new(actual / divisor));
138
+ } else {
139
+ rb_ary_push(value, LL2NUM(*((long long *)entry->sqldata)));
140
+ }
141
+ rb_ary_push(value, getColumnType(entry));
142
+ break;
143
+
144
+ case SQL_LONG: /* Type: INTEGER, DECIMAL, NUMERIC */
145
+ if(entry->sqlscale != 0) {
146
+ double divisor = pow(10, abs(entry->sqlscale));
147
+
148
+ actual = *((int32_t *)entry->sqldata);
149
+ rb_ary_push(value, rb_float_new(actual / divisor));
150
+ } else {
151
+ rb_ary_push(value, LONG2NUM(*((int32_t *)entry->sqldata)));
152
+ }
153
+ rb_ary_push(value, getColumnType(entry));
154
+ break;
155
+
156
+ case SQL_SHORT: /* Type: SMALLINT, DECIMAL, NUMERIC */
157
+ if(entry->sqlscale != 0) {
158
+ double divisor = pow(10, abs(entry->sqlscale));
159
+
160
+ actual = *((short *)entry->sqldata);
161
+ rb_ary_push(value, rb_float_new(actual / divisor));
162
+ } else {
163
+ rb_ary_push(value, INT2NUM(*((short *)entry->sqldata)));
164
+ }
165
+ rb_ary_push(value, getColumnType(entry));
166
+ break;
167
+
168
+ case SQL_TEXT: /* Type: CHAR */
169
+ array = ALLOC_N(char, entry->sqllen + 1);
170
+ if(array != NULL) {
171
+ memset(array, 0, entry->sqllen + 1);
172
+ memcpy(array, entry->sqldata, entry->sqllen);
173
+ rb_ary_push(value, rb_str_new2(array));
174
+ rb_ary_push(value, getColumnType(entry));
175
+ free(array);
176
+ }
177
+ break;
178
+
179
+ case SQL_TYPE_TIME: /* Type: TIME */
180
+ isc_decode_sql_time((ISC_TIME *)entry->sqldata, &datetime);
181
+ datetime.tm_year = 70;
182
+ datetime.tm_mon = 0;
183
+ datetime.tm_mday = 1;
184
+ rb_ary_push(value, createSafeTime(&datetime));
185
+ rb_ary_push(value, getColumnType(entry));
186
+ break;
187
+
188
+ case SQL_TIMESTAMP: /* Type: TIMESTAMP */
189
+ isc_decode_timestamp((ISC_TIMESTAMP *)entry->sqldata, &datetime);
190
+ rb_ary_push(value, createSafeTime(&datetime));
191
+ rb_ary_push(value, getColumnType(entry));
192
+ break;
193
+
194
+ case SQL_VARYING:
195
+ memcpy(&length, entry->sqldata, 2);
196
+ if(length >= 0) {
197
+ array = ALLOC_N(char, length + 1);
198
+ if(array != NULL) {
199
+ memset(array, 0, length + 1);
200
+ memcpy(array, &entry->sqldata[2], length);
201
+ rb_ary_push(value, rb_str_new2(array));
202
+ rb_ary_push(value, getColumnType(entry));
203
+ free(array);
204
+ }
205
+ }
206
+ break;
207
+
208
+ default:
209
+ rb_ary_push(value, Qnil);
233
210
  rb_ary_push(value, Qnil);
234
- rb_ary_push(value, getColumnType(entry));
235
- }
211
+ } /* End of switch. */
212
+ } else {
213
+ rb_ary_push(value, Qnil);
214
+ rb_ary_push(value, getColumnType(entry));
215
+ }
236
216
 
237
- return(value);
217
+ return(value);
238
218
  }
239
219
 
240
220
 
@@ -248,29 +228,27 @@ VALUE toValue(XSQLVAR *entry,
248
228
  * @return A reference to the array containing the row data from the XSQLDA.
249
229
  *
250
230
  */
251
- VALUE toArray(VALUE results)
252
- {
253
- VALUE array = rb_ary_new(),
254
- transaction = rb_iv_get(results, "@transaction"),
255
- connection = rb_iv_get(results, "@connection");
256
- XSQLVAR *entry = NULL;
257
- ConnectionHandle *cHandle = NULL;
258
- ResultsHandle *rHandle = NULL;
259
- TransactionHandle *tHandle = NULL;
260
- int i;
261
-
262
- Data_Get_Struct(connection, ConnectionHandle, cHandle);
263
- Data_Get_Struct(results, ResultsHandle, rHandle);
264
- Data_Get_Struct(transaction, TransactionHandle, tHandle);
265
- entry = rHandle->output->sqlvar;
266
- for(i = 0; i < rHandle->output->sqln; i++, entry++)
267
- {
268
- VALUE value = toValue(entry, &cHandle->handle, &tHandle->handle);
269
-
270
- rb_ary_push(array, value);
271
- }
272
-
273
- return(array);
231
+ VALUE toArray(VALUE results) {
232
+ VALUE array = rb_ary_new(),
233
+ transaction = rb_iv_get(results, "@transaction"),
234
+ connection = rb_iv_get(results, "@connection");
235
+ XSQLVAR *entry = NULL;
236
+ ConnectionHandle *cHandle = NULL;
237
+ ResultsHandle *rHandle = NULL;
238
+ TransactionHandle *tHandle = NULL;
239
+ int i;
240
+
241
+ Data_Get_Struct(connection, ConnectionHandle, cHandle);
242
+ Data_Get_Struct(results, ResultsHandle, rHandle);
243
+ Data_Get_Struct(transaction, TransactionHandle, tHandle);
244
+ entry = rHandle->output->sqlvar;
245
+ for(i = 0; i < rHandle->output->sqln; i++, entry++) {
246
+ VALUE value = toValue(entry, &cHandle->handle, &tHandle->handle);
247
+
248
+ rb_ary_push(array, value);
249
+ }
250
+
251
+ return(array);
274
252
  }
275
253
 
276
254
 
@@ -288,102 +266,95 @@ VALUE toArray(VALUE results)
288
266
  * to get connection and transaction details.
289
267
  *
290
268
  */
291
- void setParameters(XSQLDA *parameters, VALUE array, VALUE source)
292
- {
293
- VALUE value;
294
- int index,
295
- size;
296
- XSQLVAR *parameter = NULL;
297
-
298
- /* Check that sufficient parameters have been provided. */
299
- value = rb_funcall(array, rb_intern("size"), 0);
300
- size = (TYPE(value) == T_FIXNUM ? FIX2INT(value) : NUM2INT(value));
301
- parameter = parameters->sqlvar;
302
- if(size != parameters->sqld)
303
- {
304
- rb_raise(rb_eException,
305
- "Parameter set mismatch. Too many or too few parameters "\
306
- "specified for a SQL statement.");
307
- }
308
- parameters->sqln = parameters->sqld;
309
- parameters->version = 1;
310
-
311
- /* Populate the parameters from the array's contents. */
312
- for(index = 0; index < size; index++, parameter++)
313
- {
314
- int type = (parameter->sqltype & ~1);
315
-
316
- value = rb_ary_entry(array, index);
317
- /* Check for nils to indicate null values. */
318
- if(value != Qnil)
319
- {
320
- VALUE name = rb_funcall(value, rb_intern("class"), 0);
321
-
322
- parameter->sqlind = 0;
323
- name = rb_funcall(name, rb_intern("name"), 0);
324
- switch(type)
325
- {
326
- case SQL_ARRAY : /* Type: ARRAY */
327
- /* TO BE DONE! */
328
- break;
329
-
330
- case SQL_BLOB: /* Type: BLOB */
331
- populateBlobField(value, parameter, source);
332
- break;
333
-
334
- case SQL_DOUBLE : /* Type: DOUBLE PRECISION, DECIMAL, NUMERIC */
335
- populateDoubleField(value, parameter);
336
- break;
337
-
338
- case SQL_FLOAT : /* Type: FLOAT */
339
- populateFloatField(value, parameter);
340
- break;
341
-
342
- case SQL_INT64 : /* Type: DECIMAL, NUMERIC */
343
- populateInt64Field(value, parameter);
344
- break;
345
-
346
- case SQL_LONG : /* Type: INTEGER, DECIMAL, NUMERIC */
347
- populateLongField(value, parameter);
348
- break;
349
-
350
- case SQL_SHORT : /* Type: SMALLINT, DECIMAL, NUMERIC */
351
- populateShortField(value, parameter);
352
- break;
353
-
354
- case SQL_TEXT : /* Type: CHAR */
355
- populateTextField(value, parameter);
356
- break;
357
-
358
- case SQL_TYPE_DATE : /* Type: DATE */
359
- populateDateField(value, parameter);
360
- break;
361
-
362
- case SQL_TYPE_TIME : /* Type: TIME */
363
- populateTimeField(value, parameter);
364
- break;
365
-
366
- case SQL_TIMESTAMP : /* Type: TIMESTAMP */
367
- populateTimestampField(value, parameter);
368
- break;
369
-
370
- case SQL_VARYING : /* Type: VARCHAR */
371
- populateTextField(value, parameter);
372
- break;
373
-
374
- default :
375
- rb_raise(rb_eException,
376
- "Unknown SQL type encountered in statement parameter "\
377
- "set.");
378
- } /* End of the switch statement. */
379
- }
380
- else
381
- {
382
- /* Mark the field as a NULL value. */
383
- memset(parameter->sqldata, 0, parameter->sqllen);
384
- *parameter->sqlind = -1;
385
- }
386
- }
269
+ void setParameters(XSQLDA *parameters, VALUE array, VALUE source) {
270
+ VALUE value;
271
+ int index,
272
+ size;
273
+ XSQLVAR *parameter = NULL;
274
+
275
+ /* Check that sufficient parameters have been provided. */
276
+ value = rb_funcall(array, rb_intern("size"), 0);
277
+ size = (TYPE(value) == T_FIXNUM ? FIX2INT(value) : NUM2INT(value));
278
+ parameter = parameters->sqlvar;
279
+ if(size != parameters->sqld) {
280
+ rb_raise(rb_eException,
281
+ "Parameter set mismatch. Too many or too few parameters " \
282
+ "specified for a SQL statement.");
283
+ }
284
+ parameters->sqln = parameters->sqld;
285
+ parameters->version = 1;
286
+
287
+ /* Populate the parameters from the array's contents. */
288
+ for(index = 0; index < size; index++, parameter++) {
289
+ int type = (parameter->sqltype & ~1);
290
+
291
+ value = rb_ary_entry(array, index);
292
+ /* Check for nils to indicate null values. */
293
+ if(value != Qnil) {
294
+ VALUE name = rb_funcall(value, rb_intern("class"), 0);
295
+
296
+ parameter->sqlind = 0;
297
+ name = rb_funcall(name, rb_intern("name"), 0);
298
+ switch(type) {
299
+ case SQL_ARRAY: /* Type: ARRAY */
300
+ /* TO BE DONE! */
301
+ break;
302
+
303
+ case SQL_BLOB: /* Type: BLOB */
304
+ populateBlobField(value, parameter, source);
305
+ break;
306
+
307
+ case SQL_DOUBLE: /* Type: DOUBLE PRECISION, DECIMAL, NUMERIC */
308
+ populateDoubleField(value, parameter);
309
+ break;
310
+
311
+ case SQL_FLOAT: /* Type: FLOAT */
312
+ populateFloatField(value, parameter);
313
+ break;
314
+
315
+ case SQL_INT64: /* Type: DECIMAL, NUMERIC */
316
+ populateInt64Field(value, parameter);
317
+ break;
318
+
319
+ case SQL_LONG: /* Type: INTEGER, DECIMAL, NUMERIC */
320
+ populateLongField(value, parameter);
321
+ break;
322
+
323
+ case SQL_SHORT: /* Type: SMALLINT, DECIMAL, NUMERIC */
324
+ populateShortField(value, parameter);
325
+ break;
326
+
327
+ case SQL_TEXT: /* Type: CHAR */
328
+ populateTextField(value, parameter);
329
+ break;
330
+
331
+ case SQL_TYPE_DATE: /* Type: DATE */
332
+ populateDateField(value, parameter);
333
+ break;
334
+
335
+ case SQL_TYPE_TIME: /* Type: TIME */
336
+ populateTimeField(value, parameter);
337
+ break;
338
+
339
+ case SQL_TIMESTAMP: /* Type: TIMESTAMP */
340
+ populateTimestampField(value, parameter);
341
+ break;
342
+
343
+ case SQL_VARYING: /* Type: VARCHAR */
344
+ populateTextField(value, parameter);
345
+ break;
346
+
347
+ default:
348
+ rb_raise(rb_eException,
349
+ "Unknown SQL type encountered in statement parameter " \
350
+ "set.");
351
+ } /* End of the switch statement. */
352
+ } else {
353
+ /* Mark the field as a NULL value. */
354
+ memset(parameter->sqldata, 0, parameter->sqllen);
355
+ *parameter->sqlind = -1;
356
+ }
357
+ }
387
358
  }
388
359
 
389
360
 
@@ -395,36 +366,33 @@ void setParameters(XSQLDA *parameters, VALUE array, VALUE source)
395
366
  * @return A Ruby Date object.
396
367
  *
397
368
  */
398
- VALUE createDate(const struct tm *date)
399
- {
400
- VALUE result = Qnil,
401
- klass = Qnil;
369
+ VALUE createDate(const struct tm *date) {
370
+ VALUE result = Qnil,
371
+ klass = Qnil;
402
372
 
403
- klass = getClass("Date");
373
+ klass = getClass("Date");
404
374
 
405
- /* Check if we need to require date. */
406
- if(klass == Qnil)
407
- {
408
- rb_require("date");
409
- klass = getClass("Date");
410
- }
375
+ /* Check if we need to require date. */
376
+ if(klass == Qnil) {
377
+ rb_require("date");
378
+ klass = getClass("Date");
379
+ }
411
380
 
412
- /* Check that we got the Date class. */
413
- if(klass != Qnil)
414
- {
415
- VALUE arguments[3];
381
+ /* Check that we got the Date class. */
382
+ if(klass != Qnil) {
383
+ VALUE arguments[3];
416
384
 
417
- /* Prepare the arguments. */
418
- arguments[0] = INT2FIX(date->tm_year + 1900);
419
- arguments[1] = INT2FIX(date->tm_mon + 1);
420
- arguments[2] = INT2FIX(date->tm_mday);
385
+ /* Prepare the arguments. */
386
+ arguments[0] = INT2FIX(date->tm_year + 1900);
387
+ arguments[1] = INT2FIX(date->tm_mon + 1);
388
+ arguments[2] = INT2FIX(date->tm_mday);
421
389
 
422
- /* Create the class instance. */
423
- result = rb_funcall2(klass, rb_intern("new"), 3, arguments);
424
- }
390
+ /* Create the class instance. */
391
+ result = rb_funcall2(klass, rb_intern("new"), 3, arguments);
392
+ }
425
393
 
426
394
 
427
- return(result);
395
+ return(result);
428
396
  }
429
397
 
430
398
 
@@ -436,42 +404,39 @@ VALUE createDate(const struct tm *date)
436
404
  * @return A Ruby DateTime object.
437
405
  *
438
406
  */
439
- VALUE createDateTime(VALUE dt)
440
- {
441
- VALUE result = Qnil,
442
- klass = Qnil;
443
-
444
- struct tm *datetime;
445
- Data_Get_Struct(dt, struct tm, datetime);
446
-
447
- klass = getClass("DateTime");
448
-
449
- /* Check if we need to require date. */
450
- if(klass == Qnil)
451
- {
452
- rb_require("date");
453
- klass = getClass("DateTime");
454
- }
455
-
456
- /* Check that we got the DateTime class. */
457
- if(klass != Qnil)
458
- {
459
- VALUE arguments[7];
460
-
461
- /* Prepare the arguments. */
462
- arguments[0] = INT2FIX(datetime->tm_year + 1900);
463
- arguments[1] = INT2FIX(datetime->tm_mon + 1);
464
- arguments[2] = INT2FIX(datetime->tm_mday);
465
- arguments[3] = INT2FIX(datetime->tm_hour);
466
- arguments[4] = INT2FIX(datetime->tm_min);
467
- arguments[5] = INT2FIX(datetime->tm_sec);
468
- arguments[6] = rb_funcall(rb_funcall(klass, rb_intern("now"), 0), rb_intern("offset"), 0);
469
-
470
- /* Create the class instance. */
471
- result = rb_funcall2(klass, rb_intern("new"), 7, arguments);
472
- }
473
-
474
- return(result);
407
+ VALUE createDateTime(VALUE dt) {
408
+ VALUE result = Qnil,
409
+ klass = Qnil;
410
+
411
+ struct tm *datetime;
412
+ Data_Get_Struct(dt, struct tm, datetime);
413
+
414
+ klass = getClass("DateTime");
415
+
416
+ /* Check if we need to require date. */
417
+ if(klass == Qnil) {
418
+ rb_require("date");
419
+ klass = getClass("DateTime");
420
+ }
421
+
422
+ /* Check that we got the DateTime class. */
423
+ if(klass != Qnil) {
424
+ VALUE arguments[7];
425
+
426
+ /* Prepare the arguments. */
427
+ arguments[0] = INT2FIX(datetime->tm_year + 1900);
428
+ arguments[1] = INT2FIX(datetime->tm_mon + 1);
429
+ arguments[2] = INT2FIX(datetime->tm_mday);
430
+ arguments[3] = INT2FIX(datetime->tm_hour);
431
+ arguments[4] = INT2FIX(datetime->tm_min);
432
+ arguments[5] = INT2FIX(datetime->tm_sec);
433
+ arguments[6] = rb_funcall(rb_funcall(klass, rb_intern("now"), 0), rb_intern("offset"), 0);
434
+
435
+ /* Create the class instance. */
436
+ result = rb_funcall2(klass, rb_intern("new"), 7, arguments);
437
+ }
438
+
439
+ return(result);
475
440
  }
476
441
 
477
442
 
@@ -483,54 +448,51 @@ VALUE createDateTime(VALUE dt)
483
448
  * @return A Ruby Time object.
484
449
  *
485
450
  */
486
- VALUE createTime(VALUE dt)
487
- {
488
- VALUE result = Qnil,
489
- klass = Qnil;
490
-
491
- struct tm *datetime;
492
- Data_Get_Struct(dt, struct tm, datetime);
493
-
494
- klass = getClass("Time");
495
-
496
- /* Check that we got the Time class. */
497
- if(klass != Qnil)
498
- {
499
- VALUE arguments[6];
500
-
501
- /* Prepare the arguments. */
502
- /*fprintf(stderr, "%d-%d-%d %d:%d:%d\n", datetime->tm_year + 1900,
503
- datetime->tm_mon + 1, datetime->tm_mday, datetime->tm_hour,
504
- datetime->tm_min, datetime->tm_sec);*/
505
- arguments[0] = INT2FIX(datetime->tm_year + 1900);
506
- arguments[1] = INT2FIX(datetime->tm_mon + 1);
507
- arguments[2] = INT2FIX(datetime->tm_mday);
508
- arguments[3] = INT2FIX(datetime->tm_hour);
509
- arguments[4] = INT2FIX(datetime->tm_min);
510
- arguments[5] = INT2FIX(datetime->tm_sec);
511
-
512
- /* Create the class instance. */
513
- result = rb_funcall2(klass, rb_intern("local"), 6, arguments);
514
- }
515
-
516
- return(result);
451
+ VALUE createTime(VALUE dt) {
452
+ VALUE result = Qnil,
453
+ klass = Qnil;
454
+
455
+ struct tm *datetime;
456
+ Data_Get_Struct(dt, struct tm, datetime);
457
+
458
+ klass = getClass("Time");
459
+
460
+ /* Check that we got the Time class. */
461
+ if(klass != Qnil) {
462
+ VALUE arguments[6];
463
+
464
+ /* Prepare the arguments. */
465
+ /*fprintf(stderr, "%d-%d-%d %d:%d:%d\n", datetime->tm_year + 1900,
466
+ datetime->tm_mon + 1, datetime->tm_mday, datetime->tm_hour,
467
+ datetime->tm_min, datetime->tm_sec);*/
468
+ arguments[0] = INT2FIX(datetime->tm_year + 1900);
469
+ arguments[1] = INT2FIX(datetime->tm_mon + 1);
470
+ arguments[2] = INT2FIX(datetime->tm_mday);
471
+ arguments[3] = INT2FIX(datetime->tm_hour);
472
+ arguments[4] = INT2FIX(datetime->tm_min);
473
+ arguments[5] = INT2FIX(datetime->tm_sec);
474
+
475
+ /* Create the class instance. */
476
+ result = rb_funcall2(klass, rb_intern("local"), 6, arguments);
477
+ }
478
+
479
+ return(result);
517
480
  }
518
481
 
519
482
  /**
520
- * This function converts a struct tm to a Ruby Time instance.
483
+ * This function converts a struct tm to a Ruby Time instance.
521
484
  * If the conversion process results in an out of range error then
522
485
  * it will convert the struct to a DateTime instance.
523
486
  *
524
487
  * @param datetime A structure containing the date/time details.
525
488
  *
526
- * @return A Ruby Time object if the arguments are in range, otherwise
489
+ * @return A Ruby Time object if the arguments are in range, otherwise
527
490
  * a Ruby DateTime object.
528
491
  *
529
492
  */
530
- VALUE createSafeTime(const struct tm *datetime)
531
- {
532
- VALUE dt = Data_Wrap_Struct(rb_cObject, NULL, NULL, datetime);
533
- return rb_rescue(createTime, dt, createDateTime, dt);
493
+ VALUE createSafeTime(const struct tm *datetime) {
494
+ VALUE dt = Data_Wrap_Struct(rb_cObject, NULL, NULL, (void*)datetime);
495
+ return rb_rescue(createTime, dt, createDateTime, dt);
534
496
  }
535
497
 
536
498
  /**
@@ -544,29 +506,25 @@ VALUE createSafeTime(const struct tm *datetime)
544
506
  * @return A Ruby VALUE representing the constant.
545
507
  *
546
508
  */
547
- VALUE getConstant(const char *name, VALUE module)
548
- {
509
+ VALUE getConstant(const char *name, VALUE module) {
549
510
  VALUE owner = module,
550
- constants,
551
- exists,
552
- entry = Qnil,
553
- symbol = ID2SYM(rb_intern(name));
511
+ constants,
512
+ exists,
513
+ entry = Qnil,
514
+ symbol = ID2SYM(rb_intern(name));
554
515
 
555
516
  /* Check that we've got somewhere to look. */
556
- if(owner == Qnil)
557
- {
517
+ if(owner == Qnil) {
558
518
  owner = rb_cModule;
559
519
  }
560
520
 
561
521
  constants = rb_funcall(owner, rb_intern("constants"), 0),
562
522
  exists = rb_funcall(constants, rb_intern("include?"), 1, symbol);
563
- if(exists == Qfalse)
564
- {
523
+ if(exists == Qfalse) {
565
524
  /* 1.8 style lookup */
566
525
  exists = rb_funcall(constants, rb_intern("include?"), 1, rb_str_new2(name));
567
526
  }
568
- if(exists != Qfalse)
569
- {
527
+ if(exists != Qfalse) {
570
528
  entry = rb_funcall(owner, rb_intern("const_get"), 1, symbol);
571
529
  }
572
530
  return(entry);
@@ -581,21 +539,18 @@ VALUE getConstant(const char *name, VALUE module)
581
539
  * module could not be located.
582
540
  *
583
541
  */
584
- VALUE getModule(const char *name)
585
- {
586
- VALUE module = getConstant(name, Qnil);
542
+ VALUE getModule(const char *name) {
543
+ VALUE module = getConstant(name, Qnil);
587
544
 
588
- if(module != Qnil)
589
- {
590
- VALUE type = rb_funcall(module, rb_intern("class"), 0);
545
+ if(module != Qnil) {
546
+ VALUE type = rb_funcall(module, rb_intern("class"), 0);
591
547
 
592
- if(type != rb_cModule)
593
- {
594
- module = Qnil;
595
- }
596
- }
548
+ if(type != rb_cModule) {
549
+ module = Qnil;
550
+ }
551
+ }
597
552
 
598
- return(module);
553
+ return(module);
599
554
  }
600
555
 
601
556
 
@@ -607,21 +562,18 @@ VALUE getModule(const char *name)
607
562
  * could not be found.
608
563
  *
609
564
  */
610
- VALUE getClass(const char *name)
611
- {
612
- VALUE klass = getConstant(name, Qnil);
565
+ VALUE getClass(const char *name) {
566
+ VALUE klass = getConstant(name, Qnil);
613
567
 
614
- if(klass != Qnil)
615
- {
616
- VALUE type = rb_funcall(klass, rb_intern("class"), 0);
568
+ if(klass != Qnil) {
569
+ VALUE type = rb_funcall(klass, rb_intern("class"), 0);
617
570
 
618
- if(type != rb_cClass)
619
- {
620
- klass = Qnil;
621
- }
622
- }
571
+ if(type != rb_cClass) {
572
+ klass = Qnil;
573
+ }
574
+ }
623
575
 
624
- return(klass);
576
+ return(klass);
625
577
  }
626
578
 
627
579
 
@@ -635,21 +587,18 @@ VALUE getClass(const char *name)
635
587
  * not be located.
636
588
  *
637
589
  */
638
- VALUE getModuleInModule(const char *name, VALUE owner)
639
- {
640
- VALUE module = getConstant(name, owner);
590
+ VALUE getModuleInModule(const char *name, VALUE owner) {
591
+ VALUE module = getConstant(name, owner);
641
592
 
642
- if(module != Qnil)
643
- {
644
- VALUE type = rb_funcall(module, rb_intern("class"), 0);
593
+ if(module != Qnil) {
594
+ VALUE type = rb_funcall(module, rb_intern("class"), 0);
645
595
 
646
- if(type != rb_cModule)
647
- {
648
- module = Qnil;
649
- }
650
- }
596
+ if(type != rb_cModule) {
597
+ module = Qnil;
598
+ }
599
+ }
651
600
 
652
- return(module);
601
+ return(module);
653
602
  }
654
603
 
655
604
 
@@ -663,21 +612,18 @@ VALUE getModuleInModule(const char *name, VALUE owner)
663
612
  * not be located.
664
613
  *
665
614
  */
666
- VALUE getClassInModule(const char *name, VALUE owner)
667
- {
668
- VALUE klass = getConstant(name, owner);
615
+ VALUE getClassInModule(const char *name, VALUE owner) {
616
+ VALUE klass = getConstant(name, owner);
669
617
 
670
- if(klass != Qnil)
671
- {
672
- VALUE type = rb_funcall(klass, rb_intern("class"), 0);
618
+ if(klass != Qnil) {
619
+ VALUE type = rb_funcall(klass, rb_intern("class"), 0);
673
620
 
674
- if(type != rb_cClass)
675
- {
676
- klass = Qnil;
677
- }
678
- }
621
+ if(type != rb_cClass) {
622
+ klass = Qnil;
623
+ }
624
+ }
679
625
 
680
- return(klass);
626
+ return(klass);
681
627
  }
682
628
 
683
629
 
@@ -690,47 +636,41 @@ VALUE getClassInModule(const char *name, VALUE owner)
690
636
  * in the order year, month, day of month, hours, minutes and seconds.
691
637
  *
692
638
  */
693
- VALUE toDateTime(VALUE value)
694
- {
695
- VALUE result,
696
- klass = rb_funcall(value, rb_intern("class"), 0);
697
-
698
- if(klass == rb_cTime)
699
- {
700
- VALUE data;
701
-
702
- result = rb_ary_new();
703
-
704
- data = rb_funcall(value, rb_intern("year"), 0);
705
- rb_ary_push(result, INT2FIX(FIX2INT(data) - 1900));
706
- data = rb_funcall(value, rb_intern("month"), 0);
707
- rb_ary_push(result, INT2FIX(FIX2INT(data) - 1));
708
- rb_ary_push(result, rb_funcall(value, rb_intern("day"), 0));
709
- rb_ary_push(result, rb_funcall(value, rb_intern("hour"), 0));
710
- rb_ary_push(result, rb_funcall(value, rb_intern("min"), 0));
711
- rb_ary_push(result, rb_funcall(value, rb_intern("sec"), 0));
712
- }
713
- else if(klass == getClass("Date"))
714
- {
715
- VALUE data;
716
-
717
- result = rb_ary_new();
718
-
719
- data = rb_funcall(value, rb_intern("year"), 0);
720
- rb_ary_push(result, INT2FIX(FIX2INT(data) - 1900));
721
- data = rb_funcall(value, rb_intern("month"), 0);
722
- rb_ary_push(result, INT2FIX(FIX2INT(data) - 1));
723
- rb_ary_push(result, rb_funcall(value, rb_intern("mday"), 0));
724
- rb_ary_push(result, INT2FIX(0));
725
- rb_ary_push(result, INT2FIX(0));
726
- rb_ary_push(result, INT2FIX(0));
727
- }
728
- else
729
- {
730
- rb_raise(rb_eException, "Value conversion error.");
731
- }
732
-
733
- return(result);
639
+ VALUE toDateTime(VALUE value) {
640
+ VALUE result,
641
+ klass = rb_funcall(value, rb_intern("class"), 0);
642
+
643
+ if(klass == rb_cTime) {
644
+ VALUE data;
645
+
646
+ result = rb_ary_new();
647
+
648
+ data = rb_funcall(value, rb_intern("year"), 0);
649
+ rb_ary_push(result, INT2FIX(FIX2INT(data) - 1900));
650
+ data = rb_funcall(value, rb_intern("month"), 0);
651
+ rb_ary_push(result, INT2FIX(FIX2INT(data) - 1));
652
+ rb_ary_push(result, rb_funcall(value, rb_intern("day"), 0));
653
+ rb_ary_push(result, rb_funcall(value, rb_intern("hour"), 0));
654
+ rb_ary_push(result, rb_funcall(value, rb_intern("min"), 0));
655
+ rb_ary_push(result, rb_funcall(value, rb_intern("sec"), 0));
656
+ } else if(klass == getClass("Date")) {
657
+ VALUE data;
658
+
659
+ result = rb_ary_new();
660
+
661
+ data = rb_funcall(value, rb_intern("year"), 0);
662
+ rb_ary_push(result, INT2FIX(FIX2INT(data) - 1900));
663
+ data = rb_funcall(value, rb_intern("month"), 0);
664
+ rb_ary_push(result, INT2FIX(FIX2INT(data) - 1));
665
+ rb_ary_push(result, rb_funcall(value, rb_intern("mday"), 0));
666
+ rb_ary_push(result, INT2FIX(0));
667
+ rb_ary_push(result, INT2FIX(0));
668
+ rb_ary_push(result, INT2FIX(0));
669
+ } else {
670
+ rb_raise(rb_eException, "Value conversion error.");
671
+ }
672
+
673
+ return(result);
734
674
  }
735
675
 
736
676
 
@@ -746,22 +686,21 @@ VALUE toDateTime(VALUE value)
746
686
  * raised.
747
687
  *
748
688
  */
749
- VALUE rescueConvert(VALUE arguments, VALUE error)
750
- {
751
- VALUE message,
752
- tmp_str1 = Qnil,
753
- tmp_str2 = Qnil;
754
- char text[512];
755
-
756
- tmp_str1 = rb_ary_entry(arguments, 1);
757
- tmp_str2 = rb_ary_entry(arguments, 2);
758
- sprintf(text, "Error converting input column %d from a %s to a %s.",
759
- FIX2INT(rb_ary_entry(arguments, 0)),
760
- StringValuePtr(tmp_str1),
761
- StringValuePtr(tmp_str2));
762
- message = rb_str_new2(text);
763
-
764
- return(rb_funcall(rb_eException, rb_intern("exception"), 1, &message));
689
+ VALUE rescueConvert(VALUE arguments, VALUE error) {
690
+ VALUE message,
691
+ tmp_str1 = Qnil,
692
+ tmp_str2 = Qnil;
693
+ char text[512];
694
+
695
+ tmp_str1 = rb_ary_entry(arguments, 1);
696
+ tmp_str2 = rb_ary_entry(arguments, 2);
697
+ sprintf(text, "Error converting input column %d from a %s to a %s.",
698
+ FIX2INT(rb_ary_entry(arguments, 0)),
699
+ StringValuePtr(tmp_str1),
700
+ StringValuePtr(tmp_str2));
701
+ message = rb_str_new2(text);
702
+
703
+ return(rb_funcall(rb_eException, rb_intern("exception"), 1, &message));
765
704
  }
766
705
 
767
706
 
@@ -782,48 +721,41 @@ VALUE rescueConvert(VALUE arguments, VALUE error)
782
721
  void storeBlob(VALUE info,
783
722
  XSQLVAR *field,
784
723
  ConnectionHandle *connection,
785
- TransactionHandle *transaction)
786
- {
787
- ISC_STATUS status[20];
788
- isc_blob_handle handle = 0;
789
- ISC_QUAD *blobId = (ISC_QUAD *)field->sqldata;
790
- VALUE number = rb_funcall(info, rb_intern("length"), 0);
791
- long length = 0;
792
- char *data = StringValuePtr(info);
793
-
794
- length = TYPE(number) == T_FIXNUM ? FIX2INT(number) : NUM2INT(number);
795
- field->sqltype = SQL_BLOB;
796
- if(isc_create_blob(status, &connection->handle, &transaction->handle,
797
- &handle, blobId) == 0)
798
- {
799
- long offset = 0;
800
- unsigned short size = 0;
801
-
802
- while(offset < length)
803
- {
804
- char *buffer = &data[offset];
805
-
806
- size = (length - offset) > USHRT_MAX ? USHRT_MAX : length - offset;
807
- if(isc_put_segment(status, &handle, size, buffer) != 0)
808
- {
809
- ISC_STATUS other[20];
810
-
811
- isc_close_blob(other, &handle);
812
- rb_fireruby_raise(status, "Error writing blob data.");
813
- }
814
-
815
- offset = offset + size;
724
+ TransactionHandle *transaction) {
725
+ ISC_STATUS status[ISC_STATUS_LENGTH];
726
+ isc_blob_handle handle = 0;
727
+ ISC_QUAD *blobId = (ISC_QUAD *)field->sqldata;
728
+ VALUE number = rb_funcall(info, rb_intern("length"), 0);
729
+ long length = 0;
730
+ char *data = StringValuePtr(info);
731
+
732
+ length = TYPE(number) == T_FIXNUM ? FIX2INT(number) : NUM2INT(number);
733
+ field->sqltype = SQL_BLOB;
734
+ if(isc_create_blob(status, &connection->handle, &transaction->handle,
735
+ &handle, blobId) == 0) {
736
+ long offset = 0;
737
+ unsigned short size = 0;
738
+
739
+ while(offset < length) {
740
+ char *buffer = &data[offset];
741
+
742
+ size = (length - offset) > USHRT_MAX ? USHRT_MAX : length - offset;
743
+ if(isc_put_segment(status, &handle, size, buffer) != 0) {
744
+ ISC_STATUS other[20];
745
+
746
+ isc_close_blob(other, &handle);
747
+ rb_fireruby_raise(status, "Error writing blob data.");
816
748
  }
817
749
 
818
- if(isc_close_blob(status, &handle) != 0)
819
- {
820
- rb_fireruby_raise(status, "Error closing blob.");
821
- }
822
- }
823
- else
824
- {
825
- rb_fireruby_raise(status, "Error storing blob data.");
826
- }
750
+ offset = offset + size;
751
+ }
752
+
753
+ if(isc_close_blob(status, &handle) != 0) {
754
+ rb_fireruby_raise(status, "Error closing blob.");
755
+ }
756
+ } else {
757
+ rb_fireruby_raise(status, "Error storing blob data.");
758
+ }
827
759
  }
828
760
 
829
761
 
@@ -836,24 +768,22 @@ void storeBlob(VALUE info,
836
768
  * contains the connection and transaction details.
837
769
  *
838
770
  */
839
- void populateBlobField(VALUE value, XSQLVAR *field, VALUE source)
840
- {
841
- VALUE attribute;
842
- ConnectionHandle *connection = NULL;
843
- TransactionHandle *transaction = NULL;
844
-
845
- if(TYPE(value) != T_STRING)
846
- {
847
- rb_fireruby_raise(NULL, "Error converting input parameter to blob.");
848
- }
849
-
850
- /* Fetch the connection and transaction details. */
851
- attribute = rb_iv_get(source, "@connection");
852
- Data_Get_Struct(attribute, ConnectionHandle, connection);
853
- attribute = rb_iv_get(source, "@transaction");
854
- Data_Get_Struct(attribute, TransactionHandle, transaction);
855
- storeBlob(value, field, connection, transaction);
856
- field->sqltype = SQL_BLOB;
771
+ void populateBlobField(VALUE value, XSQLVAR *field, VALUE source) {
772
+ VALUE attribute;
773
+ ConnectionHandle *connection = NULL;
774
+ TransactionHandle *transaction = NULL;
775
+
776
+ if(TYPE(value) != T_STRING) {
777
+ rb_fireruby_raise(NULL, "Error converting input parameter to blob.");
778
+ }
779
+
780
+ /* Fetch the connection and transaction details. */
781
+ attribute = rb_iv_get(source, "@connection");
782
+ Data_Get_Struct(attribute, ConnectionHandle, connection);
783
+ attribute = rb_iv_get(source, "@transaction");
784
+ Data_Get_Struct(attribute, TransactionHandle, transaction);
785
+ storeBlob(value, field, connection, transaction);
786
+ field->sqltype = SQL_BLOB;
857
787
  }
858
788
 
859
789
 
@@ -864,23 +794,21 @@ void populateBlobField(VALUE value, XSQLVAR *field, VALUE source)
864
794
  * @param field A pointer to the output field to be populated.
865
795
  *
866
796
  */
867
- void populateDateField(VALUE value, XSQLVAR *field)
868
- {
869
- struct tm datetime;
870
- VALUE arguments = rb_ary_new();
871
-
872
- rb_ary_push(arguments, rb_str_new2("date"));
873
- value = rb_rescue(toDateTime, value, rescueConvert, arguments);
874
- if(TYPE(value) != T_ARRAY)
875
- {
876
- VALUE message = rb_funcall(value, rb_intern("message"), 0);
877
- rb_fireruby_raise(NULL, StringValuePtr(message));
878
- }
879
- datetime.tm_year = FIX2INT(rb_ary_entry(value, 0));
880
- datetime.tm_mon = FIX2INT(rb_ary_entry(value, 1));
881
- datetime.tm_mday = FIX2INT(rb_ary_entry(value, 2));
882
- isc_encode_sql_date(&datetime, (ISC_DATE *)field->sqldata);
883
- field->sqltype = SQL_TYPE_DATE;
797
+ void populateDateField(VALUE value, XSQLVAR *field) {
798
+ struct tm datetime;
799
+ VALUE arguments = rb_ary_new();
800
+
801
+ rb_ary_push(arguments, rb_str_new2("date"));
802
+ value = rb_rescue(toDateTime, value, rescueConvert, arguments);
803
+ if(TYPE(value) != T_ARRAY) {
804
+ VALUE message = rb_funcall(value, rb_intern("message"), 0);
805
+ rb_fireruby_raise(NULL, StringValuePtr(message));
806
+ }
807
+ datetime.tm_year = FIX2INT(rb_ary_entry(value, 0));
808
+ datetime.tm_mon = FIX2INT(rb_ary_entry(value, 1));
809
+ datetime.tm_mday = FIX2INT(rb_ary_entry(value, 2));
810
+ isc_encode_sql_date(&datetime, (ISC_DATE *)field->sqldata);
811
+ field->sqltype = SQL_TYPE_DATE;
884
812
  }
885
813
 
886
814
 
@@ -891,27 +819,22 @@ void populateDateField(VALUE value, XSQLVAR *field)
891
819
  * @param field A pointer to the output field to be populated.
892
820
  *
893
821
  */
894
- void populateDoubleField(VALUE value, XSQLVAR *field)
895
- {
896
- double store;
897
- VALUE actual;
898
-
899
- if(TYPE(value) != T_FLOAT)
900
- {
901
- if(rb_obj_is_kind_of(value, rb_cNumeric) || TYPE(value) == T_STRING)
902
- {
903
- actual = rb_funcall(value, rb_intern("to_f"), 0);
904
- }
905
- else
906
- {
907
- rb_fireruby_raise(NULL,
908
- "Error converting input parameter to double.");
909
- }
910
- }
822
+ void populateDoubleField(VALUE value, XSQLVAR *field) {
823
+ double store;
824
+ VALUE actual;
825
+
826
+ if(TYPE(value) != T_FLOAT) {
827
+ if(rb_obj_is_kind_of(value, rb_cNumeric) || TYPE(value) == T_STRING) {
828
+ actual = rb_funcall(value, rb_intern("to_f"), 0);
829
+ } else {
830
+ rb_fireruby_raise(NULL,
831
+ "Error converting input parameter to double.");
832
+ }
833
+ }
911
834
 
912
- store = NUM2DBL(value);
913
- memcpy(field->sqldata, &store, field->sqllen);
914
- field->sqltype = SQL_DOUBLE;
835
+ store = NUM2DBL(value);
836
+ memcpy(field->sqldata, &store, field->sqllen);
837
+ field->sqltype = SQL_DOUBLE;
915
838
  }
916
839
 
917
840
 
@@ -922,29 +845,24 @@ void populateDoubleField(VALUE value, XSQLVAR *field)
922
845
  * @param field A pointer to the output field to be populated.
923
846
  *
924
847
  */
925
- void populateFloatField(VALUE value, XSQLVAR *field)
926
- {
927
- double full = 0.0;
928
- float store = 0.0;
929
- VALUE actual;
930
-
931
- if(TYPE(value) != T_FLOAT)
932
- {
933
- if(rb_obj_is_kind_of(value, rb_cNumeric) || TYPE(value) == T_STRING)
934
- {
935
- actual = rb_funcall(value, rb_intern("to_f"), 0);
936
- }
937
- else
938
- {
939
- rb_fireruby_raise(NULL,
940
- "Error converting input parameter to double.");
941
- }
942
- }
848
+ void populateFloatField(VALUE value, XSQLVAR *field) {
849
+ double full = 0.0;
850
+ float store = 0.0;
851
+ VALUE actual;
852
+
853
+ if(TYPE(value) != T_FLOAT) {
854
+ if(rb_obj_is_kind_of(value, rb_cNumeric) || TYPE(value) == T_STRING) {
855
+ actual = rb_funcall(value, rb_intern("to_f"), 0);
856
+ } else {
857
+ rb_fireruby_raise(NULL,
858
+ "Error converting input parameter to double.");
859
+ }
860
+ }
943
861
 
944
- full = NUM2DBL(value);
945
- store = (float)full;
946
- memcpy(field->sqldata, &store, field->sqllen);
947
- field->sqltype = SQL_FLOAT;
862
+ full = NUM2DBL(value);
863
+ store = (float)full;
864
+ memcpy(field->sqldata, &store, field->sqllen);
865
+ field->sqltype = SQL_FLOAT;
948
866
  }
949
867
 
950
868
 
@@ -956,38 +874,29 @@ void populateFloatField(VALUE value, XSQLVAR *field)
956
874
  * @param field A pointer to the XSQLVAR field that the value will go into.
957
875
  *
958
876
  */
959
- void populateInt64Field(VALUE value, XSQLVAR *field)
960
- {
961
- VALUE actual = Qnil;
962
- long long store = 0;
963
-
964
- if(rb_obj_is_kind_of(value, rb_cInteger))
965
- {
966
- actual = value;
967
- }
968
- else if(TYPE(value) == T_FLOAT)
969
- {
970
- double number = NUM2DBL(value);
971
-
972
- if(field->sqlscale != 0)
973
- {
974
- number = number * pow(10, abs(field->sqlscale));
975
- actual = INT2NUM((long)number);
976
- }
977
- }
978
- else if(TYPE(value) == T_STRING)
979
- {
980
- actual = rb_funcall(value, rb_intern("to_i"), 0);
981
- }
982
- else
983
- {
984
- rb_fireruby_raise(NULL,
985
- "Error converting input parameter to 64 bit integer.");
986
- }
877
+ void populateInt64Field(VALUE value, XSQLVAR *field) {
878
+ VALUE actual = Qnil;
879
+ long long store = 0;
880
+
881
+ if(rb_obj_is_kind_of(value, rb_cInteger)) {
882
+ actual = value;
883
+ } else if(TYPE(value) == T_FLOAT) {
884
+ double number = NUM2DBL(value);
885
+
886
+ if(field->sqlscale != 0) {
887
+ number = number * pow(10, abs(field->sqlscale));
888
+ actual = INT2NUM((long)number);
889
+ }
890
+ } else if(TYPE(value) == T_STRING) {
891
+ actual = rb_funcall(value, rb_intern("to_i"), 0);
892
+ } else {
893
+ rb_fireruby_raise(NULL,
894
+ "Error converting input parameter to 64 bit integer.");
895
+ }
987
896
 
988
- store = TYPE(actual) == T_FIXNUM ? FIX2INT(actual) : NUM2INT(actual);
989
- memcpy(field->sqldata, &store, field->sqllen);
990
- field->sqltype = SQL_INT64;
897
+ store = TYPE(actual) == T_FIXNUM ? FIX2INT(actual) : NUM2INT(actual);
898
+ memcpy(field->sqldata, &store, field->sqllen);
899
+ field->sqltype = SQL_INT64;
991
900
  }
992
901
 
993
902
 
@@ -999,40 +908,31 @@ void populateInt64Field(VALUE value, XSQLVAR *field)
999
908
  * @param field A pointer to the XSQLVAR field that the value will go into.
1000
909
  *
1001
910
  */
1002
- void populateLongField(VALUE value, XSQLVAR *field)
1003
- {
1004
- VALUE actual = Qnil;
1005
- long long full = 0;
1006
- long store = 0;
1007
-
1008
- if(rb_obj_is_kind_of(value, rb_cInteger))
1009
- {
1010
- actual = value;
1011
- }
1012
- else if(TYPE(value) == T_FLOAT)
1013
- {
1014
- double number = NUM2DBL(value);
1015
-
1016
- if(field->sqlscale != 0)
1017
- {
1018
- number = number * pow(10, abs(field->sqlscale));
1019
- actual = INT2NUM((long)number);
1020
- }
1021
- }
1022
- else if(TYPE(value) == T_STRING)
1023
- {
1024
- actual = rb_funcall(value, rb_intern("to_i"), 0);
1025
- }
1026
- else
1027
- {
1028
- rb_fireruby_raise(NULL,
1029
- "Error converting input parameter to long integer.");
1030
- }
911
+ void populateLongField(VALUE value, XSQLVAR *field) {
912
+ VALUE actual = Qnil;
913
+ long long full = 0;
914
+ long store = 0;
915
+
916
+ if(rb_obj_is_kind_of(value, rb_cInteger)) {
917
+ actual = value;
918
+ } else if(TYPE(value) == T_FLOAT) {
919
+ double number = NUM2DBL(value);
920
+
921
+ if(field->sqlscale != 0) {
922
+ number = number * pow(10, abs(field->sqlscale));
923
+ actual = INT2NUM((long)number);
924
+ }
925
+ } else if(TYPE(value) == T_STRING) {
926
+ actual = rb_funcall(value, rb_intern("to_i"), 0);
927
+ } else {
928
+ rb_fireruby_raise(NULL,
929
+ "Error converting input parameter to long integer.");
930
+ }
1031
931
 
1032
- full = TYPE(actual) == T_FIXNUM ? FIX2INT(actual) : NUM2INT(actual);
1033
- store = (long)full;
1034
- memcpy(field->sqldata, &store, field->sqllen);
1035
- field->sqltype = SQL_LONG;
932
+ full = TYPE(actual) == T_FIXNUM ? FIX2INT(actual) : NUM2INT(actual);
933
+ store = (long)full;
934
+ memcpy(field->sqldata, &store, field->sqllen);
935
+ field->sqltype = SQL_LONG;
1036
936
  }
1037
937
 
1038
938
 
@@ -1044,40 +944,31 @@ void populateLongField(VALUE value, XSQLVAR *field)
1044
944
  * @param field A pointer to the XSQLVAR field that the value will go into.
1045
945
  *
1046
946
  */
1047
- void populateShortField(VALUE value, XSQLVAR *field)
1048
- {
1049
- VALUE actual = Qnil;
1050
- long long full = 0;
1051
- short store = 0;
1052
-
1053
- if(rb_obj_is_kind_of(value, rb_cInteger))
1054
- {
1055
- actual = value;
1056
- }
1057
- else if(TYPE(value) == T_FLOAT)
1058
- {
1059
- double number = NUM2DBL(value);
1060
-
1061
- if(field->sqlscale != 0)
1062
- {
1063
- number = number * pow(10, abs(field->sqlscale));
1064
- actual = INT2NUM((long)number);
1065
- }
1066
- }
1067
- else if(TYPE(value) == T_STRING)
1068
- {
1069
- actual = rb_funcall(value, rb_intern("to_i"), 0);
1070
- }
1071
- else
1072
- {
1073
- rb_fireruby_raise(NULL,
1074
- "Error converting input parameter to short integer.");
1075
- }
947
+ void populateShortField(VALUE value, XSQLVAR *field) {
948
+ VALUE actual = Qnil;
949
+ long long full = 0;
950
+ short store = 0;
951
+
952
+ if(rb_obj_is_kind_of(value, rb_cInteger)) {
953
+ actual = value;
954
+ } else if(TYPE(value) == T_FLOAT) {
955
+ double number = NUM2DBL(value);
956
+
957
+ if(field->sqlscale != 0) {
958
+ number = number * pow(10, abs(field->sqlscale));
959
+ actual = INT2NUM((long)number);
960
+ }
961
+ } else if(TYPE(value) == T_STRING) {
962
+ actual = rb_funcall(value, rb_intern("to_i"), 0);
963
+ } else {
964
+ rb_fireruby_raise(NULL,
965
+ "Error converting input parameter to short integer.");
966
+ }
1076
967
 
1077
- full = TYPE(actual) == T_FIXNUM ? FIX2INT(actual) : NUM2INT(actual);
1078
- store = (short)full;
1079
- memcpy(field->sqldata, &store, field->sqllen);
1080
- field->sqltype = SQL_SHORT;
968
+ full = TYPE(actual) == T_FIXNUM ? FIX2INT(actual) : NUM2INT(actual);
969
+ store = (short)full;
970
+ memcpy(field->sqldata, &store, field->sqllen);
971
+ field->sqltype = SQL_SHORT;
1081
972
  }
1082
973
 
1083
974
 
@@ -1089,36 +980,29 @@ void populateShortField(VALUE value, XSQLVAR *field)
1089
980
  * @param field A pointer to the XSQLVAR field that the value will go into.
1090
981
  *
1091
982
  */
1092
- void populateTextField(VALUE value, XSQLVAR *field)
1093
- {
1094
- VALUE actual;
1095
- char *text = NULL;
1096
- short length = 0;
1097
-
1098
- if(TYPE(value) != T_STRING)
1099
- {
1100
- actual = value;
1101
- }
1102
- else
1103
- {
1104
- actual = rb_funcall(value, rb_intern("to_s"), 0);
1105
- }
1106
-
1107
- text = StringValuePtr(actual);
1108
- length = strlen(text) > field->sqllen ? field->sqllen : strlen(text);
1109
-
1110
- if((field->sqltype & ~1) == SQL_TEXT)
1111
- {
1112
- memcpy(field->sqldata, text, length);
1113
- field->sqltype = SQL_TEXT;
1114
- }
1115
- else
1116
- {
1117
- memcpy(field->sqldata, &length, sizeof(short));
1118
- memcpy(&field->sqldata[sizeof(short)], text, length);
1119
- field->sqltype = SQL_VARYING;
1120
- }
1121
- field->sqllen = length;
983
+ void populateTextField(VALUE value, XSQLVAR *field) {
984
+ VALUE actual;
985
+ char *text = NULL;
986
+ short length = 0;
987
+
988
+ if(TYPE(value) != T_STRING) {
989
+ actual = value;
990
+ } else {
991
+ actual = rb_funcall(value, rb_intern("to_s"), 0);
992
+ }
993
+
994
+ text = StringValuePtr(actual);
995
+ length = strlen(text) > field->sqllen ? field->sqllen : strlen(text);
996
+
997
+ if((field->sqltype & ~1) == SQL_TEXT) {
998
+ memcpy(field->sqldata, text, length);
999
+ field->sqltype = SQL_TEXT;
1000
+ } else {
1001
+ memcpy(field->sqldata, &length, sizeof(short));
1002
+ memcpy(&field->sqldata[sizeof(short)], text, length);
1003
+ field->sqltype = SQL_VARYING;
1004
+ }
1005
+ field->sqllen = length;
1122
1006
  }
1123
1007
 
1124
1008
 
@@ -1129,23 +1013,21 @@ void populateTextField(VALUE value, XSQLVAR *field)
1129
1013
  * @param field A pointer to the output field to be populated.
1130
1014
  *
1131
1015
  */
1132
- void populateTimeField(VALUE value, XSQLVAR *field)
1133
- {
1134
- struct tm datetime;
1135
- VALUE arguments = rb_ary_new();
1136
-
1137
- rb_ary_push(arguments, rb_str_new2("time"));
1138
- value = rb_rescue(toDateTime, value, rescueConvert, arguments);
1139
- if(TYPE(value) != T_ARRAY)
1140
- {
1141
- VALUE message = rb_funcall(value, rb_intern("message"), 0);
1142
- rb_fireruby_raise(NULL, StringValuePtr(message));
1143
- }
1144
- datetime.tm_hour = FIX2INT(rb_ary_entry(value, 3));
1145
- datetime.tm_min = FIX2INT(rb_ary_entry(value, 4));
1146
- datetime.tm_sec = FIX2INT(rb_ary_entry(value, 5));
1147
- isc_encode_sql_time(&datetime, (ISC_TIME *)field->sqldata);
1148
- field->sqltype = SQL_TYPE_TIME;
1016
+ void populateTimeField(VALUE value, XSQLVAR *field) {
1017
+ struct tm datetime;
1018
+ VALUE arguments = rb_ary_new();
1019
+
1020
+ rb_ary_push(arguments, rb_str_new2("time"));
1021
+ value = rb_rescue(toDateTime, value, rescueConvert, arguments);
1022
+ if(TYPE(value) != T_ARRAY) {
1023
+ VALUE message = rb_funcall(value, rb_intern("message"), 0);
1024
+ rb_fireruby_raise(NULL, StringValuePtr(message));
1025
+ }
1026
+ datetime.tm_hour = FIX2INT(rb_ary_entry(value, 3));
1027
+ datetime.tm_min = FIX2INT(rb_ary_entry(value, 4));
1028
+ datetime.tm_sec = FIX2INT(rb_ary_entry(value, 5));
1029
+ isc_encode_sql_time(&datetime, (ISC_TIME *)field->sqldata);
1030
+ field->sqltype = SQL_TYPE_TIME;
1149
1031
  }
1150
1032
 
1151
1033
 
@@ -1156,24 +1038,22 @@ void populateTimeField(VALUE value, XSQLVAR *field)
1156
1038
  * @param field A pointer to the output field to be populated.
1157
1039
  *
1158
1040
  */
1159
- void populateTimestampField(VALUE value, XSQLVAR *field)
1160
- {
1161
- struct tm datetime;
1162
- VALUE arguments = rb_ary_new();
1163
-
1164
- rb_ary_push(arguments, rb_str_new2("timestamp"));
1165
- value = rb_rescue(toDateTime, value, rescueConvert, arguments);
1166
- if(TYPE(value) != T_ARRAY)
1167
- {
1168
- VALUE message = rb_funcall(value, rb_intern("message"), 0);
1169
- rb_fireruby_raise(NULL, StringValuePtr(message));
1170
- }
1171
- datetime.tm_year = FIX2INT(rb_ary_entry(value, 0));
1172
- datetime.tm_mon = FIX2INT(rb_ary_entry(value, 1));
1173
- datetime.tm_mday = FIX2INT(rb_ary_entry(value, 2));
1174
- datetime.tm_hour = FIX2INT(rb_ary_entry(value, 3));
1175
- datetime.tm_min = FIX2INT(rb_ary_entry(value, 4));
1176
- datetime.tm_sec = FIX2INT(rb_ary_entry(value, 5));
1177
- isc_encode_timestamp(&datetime, (ISC_TIMESTAMP *)field->sqldata);
1178
- field->sqltype = SQL_TIMESTAMP;
1041
+ void populateTimestampField(VALUE value, XSQLVAR *field) {
1042
+ struct tm datetime;
1043
+ VALUE arguments = rb_ary_new();
1044
+
1045
+ rb_ary_push(arguments, rb_str_new2("timestamp"));
1046
+ value = rb_rescue(toDateTime, value, rescueConvert, arguments);
1047
+ if(TYPE(value) != T_ARRAY) {
1048
+ VALUE message = rb_funcall(value, rb_intern("message"), 0);
1049
+ rb_fireruby_raise(NULL, StringValuePtr(message));
1050
+ }
1051
+ datetime.tm_year = FIX2INT(rb_ary_entry(value, 0));
1052
+ datetime.tm_mon = FIX2INT(rb_ary_entry(value, 1));
1053
+ datetime.tm_mday = FIX2INT(rb_ary_entry(value, 2));
1054
+ datetime.tm_hour = FIX2INT(rb_ary_entry(value, 3));
1055
+ datetime.tm_min = FIX2INT(rb_ary_entry(value, 4));
1056
+ datetime.tm_sec = FIX2INT(rb_ary_entry(value, 5));
1057
+ isc_encode_timestamp(&datetime, (ISC_TIMESTAMP *)field->sqldata);
1058
+ field->sqltype = SQL_TIMESTAMP;
1179
1059
  }