rubyfb 0.5.5 → 0.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ext/Row.c CHANGED
@@ -3,20 +3,20 @@
3
3
  *----------------------------------------------------------------------------*/
4
4
  /**
5
5
  * Copyright � Peter Wood, 2005
6
- *
6
+ *
7
7
  * The contents of this file are subject to the Mozilla Public License Version
8
8
  * 1.1 (the "License"); you may not use this file except in compliance with the
9
- * License. You may obtain a copy of the License at
9
+ * License. You may obtain a copy of the License at
10
10
  *
11
11
  * http://www.mozilla.org/MPL/
12
- *
12
+ *
13
13
  * Software distributed under the License is distributed on an "AS IS" basis,
14
14
  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
15
15
  * the specificlanguage governing rights and limitations under the License.
16
- *
16
+ *
17
17
  * The Original Code is the FireRuby extension for the Ruby language.
18
- *
19
- * The Initial Developer of the Original Code is Peter Wood. All Rights
18
+ *
19
+ * The Initial Developer of the Original Code is Peter Wood. All Rights
20
20
  * Reserved.
21
21
  *
22
22
  * @author Peter Wood
@@ -36,6 +36,7 @@ static VALUE columnsInRow(VALUE);
36
36
  static VALUE getRowNumber(VALUE);
37
37
  static VALUE getColumnName(VALUE, VALUE);
38
38
  static VALUE getColumnAlias(VALUE, VALUE);
39
+ static VALUE getColumnScale(VALUE, VALUE);
39
40
  static VALUE getColumnValue(VALUE, VALUE);
40
41
  static VALUE eachColumn(VALUE);
41
42
  static VALUE eachColumnKey(VALUE);
@@ -67,26 +68,22 @@ VALUE cRow;
67
68
  * @return A reference to the Row class instance allocated.
68
69
  *
69
70
  */
70
- static VALUE allocateRow(VALUE klass)
71
- {
72
- VALUE row;
73
- RowHandle *handle = ALLOC(RowHandle);
74
-
75
- if(handle != NULL)
76
- {
77
- /* Initialise the row fields. */
78
- handle->size = 0;
79
- handle->number = 0;
80
- handle->columns = NULL;
81
- row = Data_Wrap_Struct(klass, NULL, freeRow, handle);
82
- }
83
- else
84
- {
85
- /* Generate an exception. */
86
- rb_raise(rb_eNoMemError, "Memory allocation failure allocating a row.");
87
- }
88
-
89
- return(row);
71
+ static VALUE allocateRow(VALUE klass) {
72
+ VALUE row;
73
+ RowHandle *handle = ALLOC(RowHandle);
74
+
75
+ if(handle != NULL) {
76
+ /* Initialise the row fields. */
77
+ handle->size = 0;
78
+ handle->number = 0;
79
+ handle->columns = NULL;
80
+ row = Data_Wrap_Struct(klass, NULL, freeRow, handle);
81
+ } else {
82
+ /* Generate an exception. */
83
+ rb_raise(rb_eNoMemError, "Memory allocation failure allocating a row.");
84
+ }
85
+
86
+ return(row);
90
87
  }
91
88
 
92
89
 
@@ -106,52 +103,47 @@ static VALUE allocateRow(VALUE klass)
106
103
  * @return A reference to the initialize Row object.
107
104
  *
108
105
  */
109
- static VALUE initializeRow(VALUE self, VALUE results, VALUE data, VALUE number)
110
- {
111
- RowHandle *row = NULL;
112
- VALUE value = rb_funcall(data, rb_intern("size"), 0);
113
-
114
- Data_Get_Struct(self, RowHandle, row);
115
- rb_iv_set(self, "@number", number);
116
- row->size = TYPE(value) == T_FIXNUM ? FIX2INT(value) : NUM2INT(value);
117
- if(row->size > 0)
118
- {
119
- row->columns = ALLOC_N(ColumnHandle, row->size);
120
-
121
- if(row->columns != NULL)
122
- {
123
- int i;
124
-
125
- memset(row->columns, 0, sizeof(ColumnHandle) * row->size);
126
- for(i = 0; i < row->size; i++)
127
- {
128
- VALUE index,
129
- name,
130
- alias,
131
- items;
132
-
133
- index = INT2NUM(i);
134
- name = rb_funcall(results, rb_intern("column_name"), 1, index);
135
- alias = rb_funcall(results, rb_intern("column_alias"), 1, index);
136
- strcpy(row->columns[i].name, StringValuePtr(name));
137
- strcpy(row->columns[i].alias, StringValuePtr(alias));
138
- items = rb_ary_entry(data, i);
139
- row->columns[i].value = rb_ary_entry(items, 0);
140
- row->columns[i].type = rb_ary_entry(items, 1);
141
-
142
- if(TYPE(rb_ary_entry(items, 1)) == T_NIL)
143
- {
144
- fprintf(stderr, "Nil column type encountered.\n");
145
- }
146
- }
147
- }
148
- else
149
- {
150
- rb_raise(rb_eNoMemError, "Memory allocation failure populating row.");
106
+ static VALUE initializeRow(VALUE self, VALUE results, VALUE data, VALUE number) {
107
+ RowHandle *row = NULL;
108
+ VALUE value = rb_funcall(data, rb_intern("size"), 0);
109
+
110
+ Data_Get_Struct(self, RowHandle, row);
111
+ rb_iv_set(self, "@number", number);
112
+ row->size = TYPE(value) == T_FIXNUM ? FIX2INT(value) : NUM2INT(value);
113
+ if(row->size > 0) {
114
+ row->columns = ALLOC_N(ColumnHandle, row->size);
115
+
116
+ if(row->columns != NULL) {
117
+ int i;
118
+
119
+ memset(row->columns, 0, sizeof(ColumnHandle) * row->size);
120
+ for(i = 0; i < row->size; i++) {
121
+ VALUE index,
122
+ name,
123
+ alias,
124
+ scale,
125
+ items;
126
+
127
+ index = INT2NUM(i);
128
+ name = rb_funcall(results, rb_intern("column_name"), 1, index);
129
+ alias = rb_funcall(results, rb_intern("column_alias"), 1, index);
130
+ strcpy(row->columns[i].name, StringValuePtr(name));
131
+ strcpy(row->columns[i].alias, StringValuePtr(alias));
132
+ items = rb_ary_entry(data, i);
133
+ row->columns[i].value = rb_ary_entry(items, 0);
134
+ row->columns[i].type = rb_ary_entry(items, 1);
135
+ row->columns[i].scale = rb_funcall(results, rb_intern("column_scale"), 1, index);
136
+
137
+ if(TYPE(rb_ary_entry(items, 1)) == T_NIL) {
138
+ fprintf(stderr, "Nil column type encountered.\n");
139
+ }
151
140
  }
152
- }
153
-
154
- return(self);
141
+ } else {
142
+ rb_raise(rb_eNoMemError, "Memory allocation failure populating row.");
143
+ }
144
+ }
145
+
146
+ return(self);
155
147
  }
156
148
 
157
149
 
@@ -163,13 +155,12 @@ static VALUE initializeRow(VALUE self, VALUE results, VALUE data, VALUE number)
163
155
  * @return The number of columns that make up the row.
164
156
  *
165
157
  */
166
- static VALUE columnsInRow(VALUE self)
167
- {
168
- RowHandle *row = NULL;
169
-
170
- Data_Get_Struct(self, RowHandle, row);
171
-
172
- return(INT2NUM(row->size));
158
+ static VALUE columnsInRow(VALUE self) {
159
+ RowHandle *row = NULL;
160
+
161
+ Data_Get_Struct(self, RowHandle, row);
162
+
163
+ return(INT2NUM(row->size));
173
164
  }
174
165
 
175
166
 
@@ -181,9 +172,8 @@ static VALUE columnsInRow(VALUE self)
181
172
  * @param A reference to the row number.
182
173
  *
183
174
  */
184
- static VALUE getRowNumber(VALUE self)
185
- {
186
- return(rb_iv_get(self, "@number"));
175
+ static VALUE getRowNumber(VALUE self) {
176
+ return(rb_iv_get(self, "@number"));
187
177
  }
188
178
 
189
179
 
@@ -197,20 +187,18 @@ static VALUE getRowNumber(VALUE self)
197
187
  * specified.
198
188
  *
199
189
  */
200
- static VALUE getColumnName(VALUE self, VALUE index)
201
- {
202
- VALUE name = Qnil;
203
- RowHandle *row = NULL;
204
- int number = 0;
205
-
206
- Data_Get_Struct(self, RowHandle, row);
207
- number = TYPE(index) == T_FIXNUM ? FIX2INT(index) : NUM2INT(index);
208
- if(number >= 0 && number < row->size)
209
- {
210
- name = rb_str_new2(row->columns[number].name);
211
- }
212
-
213
- return(name);
190
+ static VALUE getColumnName(VALUE self, VALUE index) {
191
+ VALUE name = Qnil;
192
+ RowHandle *row = NULL;
193
+ int number = 0;
194
+
195
+ Data_Get_Struct(self, RowHandle, row);
196
+ number = TYPE(index) == T_FIXNUM ? FIX2INT(index) : NUM2INT(index);
197
+ if(number >= 0 && number < row->size) {
198
+ name = rb_str_new2(row->columns[number].name);
199
+ }
200
+
201
+ return(name);
214
202
  }
215
203
 
216
204
 
@@ -224,20 +212,18 @@ static VALUE getColumnName(VALUE self, VALUE index)
224
212
  * specified.
225
213
  *
226
214
  */
227
- static VALUE getColumnAlias(VALUE self, VALUE index)
228
- {
229
- VALUE alias = Qnil;
230
- RowHandle *row = NULL;
231
- int number = 0;
232
-
233
- Data_Get_Struct(self, RowHandle, row);
234
- number = TYPE(index) == T_FIXNUM ? FIX2INT(index) : NUM2INT(index);
235
- if(number >= 0 && number < row->size)
236
- {
237
- alias = rb_str_new2(row->columns[number].alias);
238
- }
239
-
240
- return(alias);
215
+ static VALUE getColumnAlias(VALUE self, VALUE index) {
216
+ VALUE alias = Qnil;
217
+ RowHandle *row = NULL;
218
+ int number = 0;
219
+
220
+ Data_Get_Struct(self, RowHandle, row);
221
+ number = TYPE(index) == T_FIXNUM ? FIX2INT(index) : NUM2INT(index);
222
+ if(number >= 0 && number < row->size) {
223
+ alias = rb_str_new2(row->columns[number].alias);
224
+ }
225
+
226
+ return(alias);
241
227
  }
242
228
 
243
229
 
@@ -252,52 +238,42 @@ static VALUE getColumnAlias(VALUE self, VALUE index)
252
238
  * is specified.
253
239
  *
254
240
  */
255
- static VALUE getColumnValue(VALUE self, VALUE index)
256
- {
257
- VALUE value = Qnil;
258
- RowHandle *row = NULL;
259
-
260
- Data_Get_Struct(self, RowHandle, row);
261
- if(TYPE(index) == T_STRING)
262
- {
263
- char name[32];
264
- int i,
265
- done = 0;
266
- VALUE flag = getFireRubySetting("ALIAS_KEYS");
267
-
268
- strcpy(name, StringValuePtr(index));
269
- for(i = 0; i < row->size && done == 0; i++)
270
- {
271
- int match;
272
-
273
- /* Check whether its column name or column alias to compare on. */
274
- if(flag == Qtrue)
275
- {
276
- match = strcmp(name, row->columns[i].alias);
277
- }
278
- else
279
- {
280
- match = strcmp(name, row->columns[i].name);
281
- }
282
-
283
- if(match == 0)
284
- {
285
- value = row->columns[i].value;
286
- done = 1;
287
- }
241
+ static VALUE getColumnValue(VALUE self, VALUE index) {
242
+ VALUE value = Qnil;
243
+ RowHandle *row = NULL;
244
+
245
+ Data_Get_Struct(self, RowHandle, row);
246
+ if(TYPE(index) == T_STRING) {
247
+ char name[32];
248
+ int i,
249
+ done = 0;
250
+ VALUE flag = getFireRubySetting("ALIAS_KEYS");
251
+
252
+ strcpy(name, StringValuePtr(index));
253
+ for(i = 0; i < row->size && done == 0; i++) {
254
+ int match;
255
+
256
+ /* Check whether its column name or column alias to compare on. */
257
+ if(flag == Qtrue) {
258
+ match = strcmp(name, row->columns[i].alias);
259
+ } else {
260
+ match = strcmp(name, row->columns[i].name);
288
261
  }
289
- }
290
- else
291
- {
292
- int number = TYPE(index) == T_FIXNUM ? FIX2INT(index) : NUM2INT(index);
293
-
294
- if(number >= 0 && number < row->size)
295
- {
296
- value = row->columns[number].value;
262
+
263
+ if(match == 0) {
264
+ value = row->columns[i].value;
265
+ done = 1;
297
266
  }
298
- }
299
-
300
- return(value);
267
+ }
268
+ } else {
269
+ int number = TYPE(index) == T_FIXNUM ? FIX2INT(index) : NUM2INT(index);
270
+
271
+ if(number >= 0 && number < row->size) {
272
+ value = row->columns[number].value;
273
+ }
274
+ }
275
+
276
+ return(value);
301
277
  }
302
278
 
303
279
 
@@ -311,36 +287,30 @@ static VALUE getColumnValue(VALUE self, VALUE index)
311
287
  * block was provided.
312
288
  *
313
289
  */
314
- VALUE eachColumn(VALUE self)
315
- {
316
- VALUE result = Qnil;
317
-
318
- if(rb_block_given_p())
319
- {
320
- RowHandle *row = NULL;
321
- int i;
322
- VALUE flag = getFireRubySetting("ALIAS_KEYS");
323
-
324
- Data_Get_Struct(self, RowHandle, row);
325
- for(i = 0; i < row->size; i++)
326
- {
327
- VALUE parameters = rb_ary_new();
328
-
329
- /* Decide whether we're keying on column name or alias. */
330
- if(flag == Qtrue)
331
- {
332
- rb_ary_push(parameters, rb_str_new2(row->columns[i].alias));
333
- }
334
- else
335
- {
336
- rb_ary_push(parameters, rb_str_new2(row->columns[i].name));
337
- }
338
- rb_ary_push(parameters, row->columns[i].value);
339
- result = rb_yield(parameters);
290
+ VALUE eachColumn(VALUE self) {
291
+ VALUE result = Qnil;
292
+
293
+ if(rb_block_given_p()) {
294
+ RowHandle *row = NULL;
295
+ int i;
296
+ VALUE flag = getFireRubySetting("ALIAS_KEYS");
297
+
298
+ Data_Get_Struct(self, RowHandle, row);
299
+ for(i = 0; i < row->size; i++) {
300
+ VALUE parameters = rb_ary_new();
301
+
302
+ /* Decide whether we're keying on column name or alias. */
303
+ if(flag == Qtrue) {
304
+ rb_ary_push(parameters, rb_str_new2(row->columns[i].alias));
305
+ } else {
306
+ rb_ary_push(parameters, rb_str_new2(row->columns[i].name));
340
307
  }
341
- }
342
-
343
- return(result);
308
+ rb_ary_push(parameters, row->columns[i].value);
309
+ result = rb_yield(parameters);
310
+ }
311
+ }
312
+
313
+ return(result);
344
314
  }
345
315
 
346
316
 
@@ -355,31 +325,25 @@ VALUE eachColumn(VALUE self)
355
325
  * block was provided.
356
326
  *
357
327
  */
358
- VALUE eachColumnKey(VALUE self)
359
- {
360
- VALUE result = Qnil;
361
-
362
- if(rb_block_given_p())
363
- {
364
- RowHandle *row = NULL;
365
- int i;
366
- VALUE flag = getFireRubySetting("ALIAS_KEYS");
367
-
368
- Data_Get_Struct(self, RowHandle, row);
369
- for(i = 0; i < row->size; i++)
370
- {
371
- if(flag == Qtrue)
372
- {
373
- result = rb_yield(rb_str_new2(row->columns[i].alias));
374
- }
375
- else
376
- {
377
- result = rb_yield(rb_str_new2(row->columns[i].name));
378
- }
328
+ VALUE eachColumnKey(VALUE self) {
329
+ VALUE result = Qnil;
330
+
331
+ if(rb_block_given_p()) {
332
+ RowHandle *row = NULL;
333
+ int i;
334
+ VALUE flag = getFireRubySetting("ALIAS_KEYS");
335
+
336
+ Data_Get_Struct(self, RowHandle, row);
337
+ for(i = 0; i < row->size; i++) {
338
+ if(flag == Qtrue) {
339
+ result = rb_yield(rb_str_new2(row->columns[i].alias));
340
+ } else {
341
+ result = rb_yield(rb_str_new2(row->columns[i].name));
379
342
  }
380
- }
381
-
382
- return(result);
343
+ }
344
+ }
345
+
346
+ return(result);
383
347
  }
384
348
 
385
349
 
@@ -393,30 +357,27 @@ VALUE eachColumnKey(VALUE self)
393
357
  * block was provided.
394
358
  *
395
359
  */
396
- VALUE eachColumnValue(VALUE self)
397
- {
398
- VALUE result = Qnil;
399
-
400
- if(rb_block_given_p())
401
- {
402
- RowHandle *row = NULL;
403
- int i;
404
-
405
- Data_Get_Struct(self, RowHandle, row);
406
- for(i = 0; i < row->size; i++)
407
- {
408
- result = rb_yield(row->columns[i].value);
409
- }
410
- }
411
-
412
- return(result);
360
+ VALUE eachColumnValue(VALUE self) {
361
+ VALUE result = Qnil;
362
+
363
+ if(rb_block_given_p()) {
364
+ RowHandle *row = NULL;
365
+ int i;
366
+
367
+ Data_Get_Struct(self, RowHandle, row);
368
+ for(i = 0; i < row->size; i++) {
369
+ result = rb_yield(row->columns[i].value);
370
+ }
371
+ }
372
+
373
+ return(result);
413
374
  }
414
375
 
415
376
 
416
377
  /**
417
378
  * This function provides the fetch method for the Row class.
418
379
  *
419
- * @param self A reference to the Row class that the method is being
380
+ * @param self A reference to the Row class that the method is being
420
381
  * called for.
421
382
  * @param parameters A reference to an array containing the parameters for
422
383
  * the method call. Must contain at least a key.
@@ -425,35 +386,28 @@ VALUE eachColumnValue(VALUE self)
425
386
  * return value for any block specified.
426
387
  *
427
388
  */
428
- VALUE fetchRowValue(int size, VALUE *parameters, VALUE self)
429
- {
430
- VALUE value = Qnil;
431
-
432
- if(size < 1)
433
- {
434
- rb_raise(rb_eArgError, "Wrong number of arguments (%d for %d)", size, 1);
435
- }
436
-
437
- /* Extract the parameters. */
438
- value = getColumnValue(self, parameters[0]);
439
- if(value == Qnil)
440
- {
441
- if(size == 1 && rb_block_given_p())
442
- {
443
- value = rb_yield(rb_ary_new());
389
+ VALUE fetchRowValue(int size, VALUE *parameters, VALUE self) {
390
+ VALUE value = Qnil;
391
+
392
+ if(size < 1) {
393
+ rb_raise(rb_eArgError, "Wrong number of arguments (%d for %d)", size, 1);
394
+ }
395
+
396
+ /* Extract the parameters. */
397
+ value = getColumnValue(self, parameters[0]);
398
+ if(value == Qnil) {
399
+ if(size == 1 && rb_block_given_p()) {
400
+ value = rb_yield(rb_ary_new());
401
+ } else {
402
+ if(size == 1) {
403
+ rb_raise(rb_eIndexError, "Column identifier '%s' not found in row.",
404
+ StringValuePtr(parameters[0]));
444
405
  }
445
- else
446
- {
447
- if(size == 1)
448
- {
449
- rb_raise(rb_eIndexError, "Column identifier '%s' not found in row.",
450
- StringValuePtr(parameters[0]));
451
- }
452
- value = parameters[1];
453
- }
454
- }
455
-
456
- return(value);
406
+ value = parameters[1];
407
+ }
408
+ }
409
+
410
+ return(value);
457
411
  }
458
412
 
459
413
 
@@ -468,37 +422,31 @@ VALUE fetchRowValue(int size, VALUE *parameters, VALUE self)
468
422
  * otherwise.
469
423
  *
470
424
  */
471
- VALUE hasColumnKey(VALUE self, VALUE name)
472
- {
473
- VALUE result = Qfalse;
474
- RowHandle *row = NULL;
475
- char text[32];
476
- int i;
477
- VALUE flag = getFireRubySetting("ALIAS_KEYS");
478
-
479
- Data_Get_Struct(self, RowHandle, row);
480
- strcpy(text, StringValuePtr(name));
481
- for(i = 0; i < row->size && result == Qfalse; i++)
482
- {
483
- int match;
484
-
485
- /* Check whether key is column name or alias. */
486
- if(flag == Qtrue)
487
- {
488
- match = strcmp(text, row->columns[i].alias);
489
- }
490
- else
491
- {
492
- match = strcmp(text, row->columns[i].name);
493
- }
494
-
495
- if(match == 0)
496
- {
497
- result = Qtrue;
498
- }
499
- }
500
-
501
- return(result);
425
+ VALUE hasColumnKey(VALUE self, VALUE name) {
426
+ VALUE result = Qfalse;
427
+ RowHandle *row = NULL;
428
+ char text[32];
429
+ int i;
430
+ VALUE flag = getFireRubySetting("ALIAS_KEYS");
431
+
432
+ Data_Get_Struct(self, RowHandle, row);
433
+ strcpy(text, StringValuePtr(name));
434
+ for(i = 0; i < row->size && result == Qfalse; i++) {
435
+ int match;
436
+
437
+ /* Check whether key is column name or alias. */
438
+ if(flag == Qtrue) {
439
+ match = strcmp(text, row->columns[i].alias);
440
+ } else {
441
+ match = strcmp(text, row->columns[i].name);
442
+ }
443
+
444
+ if(match == 0) {
445
+ result = Qtrue;
446
+ }
447
+ }
448
+
449
+ return(result);
502
450
  }
503
451
 
504
452
 
@@ -513,24 +461,21 @@ VALUE hasColumnKey(VALUE self, VALUE name)
513
461
  * otherwise.
514
462
  *
515
463
  */
516
- VALUE hasColumnName(VALUE self, VALUE name)
517
- {
518
- VALUE result = Qfalse;
519
- RowHandle *row = NULL;
520
- char text[32];
521
- int i;
522
-
523
- Data_Get_Struct(self, RowHandle, row);
524
- strcpy(text, StringValuePtr(name));
525
- for(i = 0; i < row->size && result == Qfalse; i++)
526
- {
527
- if(strcmp(text, row->columns[i].name) == 0)
528
- {
529
- result = Qtrue;
530
- }
531
- }
532
-
533
- return(result);
464
+ VALUE hasColumnName(VALUE self, VALUE name) {
465
+ VALUE result = Qfalse;
466
+ RowHandle *row = NULL;
467
+ char text[32];
468
+ int i;
469
+
470
+ Data_Get_Struct(self, RowHandle, row);
471
+ strcpy(text, StringValuePtr(name));
472
+ for(i = 0; i < row->size && result == Qfalse; i++) {
473
+ if(strcmp(text, row->columns[i].name) == 0) {
474
+ result = Qtrue;
475
+ }
476
+ }
477
+
478
+ return(result);
534
479
  }
535
480
 
536
481
 
@@ -545,24 +490,21 @@ VALUE hasColumnName(VALUE self, VALUE name)
545
490
  * otherwise.
546
491
  *
547
492
  */
548
- VALUE hasColumnAlias(VALUE self, VALUE name)
549
- {
550
- VALUE result = Qfalse;
551
- RowHandle *row = NULL;
552
- char text[32];
553
- int i;
554
-
555
- Data_Get_Struct(self, RowHandle, row);
556
- strcpy(text, StringValuePtr(name));
557
- for(i = 0; i < row->size && result == Qfalse; i++)
558
- {
559
- if(strcmp(text, row->columns[i].alias) == 0)
560
- {
561
- result = Qtrue;
562
- }
563
- }
564
-
565
- return(result);
493
+ VALUE hasColumnAlias(VALUE self, VALUE name) {
494
+ VALUE result = Qfalse;
495
+ RowHandle *row = NULL;
496
+ char text[32];
497
+ int i;
498
+
499
+ Data_Get_Struct(self, RowHandle, row);
500
+ strcpy(text, StringValuePtr(name));
501
+ for(i = 0; i < row->size && result == Qfalse; i++) {
502
+ if(strcmp(text, row->columns[i].alias) == 0) {
503
+ result = Qtrue;
504
+ }
505
+ }
506
+
507
+ return(result);
566
508
  }
567
509
 
568
510
 
@@ -575,19 +517,17 @@ VALUE hasColumnAlias(VALUE self, VALUE name)
575
517
  * @return True if the row contains a matching value, false otherwise.
576
518
  *
577
519
  */
578
- VALUE hasColumnValue(VALUE self, VALUE value)
579
- {
580
- VALUE result = Qfalse;
581
- RowHandle *row = NULL;
582
- int i;
583
-
584
- Data_Get_Struct(self, RowHandle, row);
585
- for(i = 0; i < row->size && result == Qfalse; i++)
586
- {
587
- result = rb_funcall(row->columns[i].value, rb_intern("eql?"), 1, value);
588
- }
589
-
590
- return(result);
520
+ VALUE hasColumnValue(VALUE self, VALUE value) {
521
+ VALUE result = Qfalse;
522
+ RowHandle *row = NULL;
523
+ int i;
524
+
525
+ Data_Get_Struct(self, RowHandle, row);
526
+ for(i = 0; i < row->size && result == Qfalse; i++) {
527
+ result = rb_funcall(row->columns[i].value, rb_intern("eql?"), 1, value);
528
+ }
529
+
530
+ return(result);
591
531
  }
592
532
 
593
533
 
@@ -601,21 +541,17 @@ VALUE hasColumnValue(VALUE self, VALUE value)
601
541
  * @return A reference to an array containing the row keys.
602
542
  *
603
543
  */
604
- VALUE getColumnKeys(VALUE self)
605
- {
606
- VALUE flag = getFireRubySetting("ALIAS_KEYS"),
607
- keys = Qnil;
608
-
609
- if(flag == Qtrue)
610
- {
611
- keys = getColumnAliases(self);
612
- }
613
- else
614
- {
615
- keys = getColumnNames(self);
616
- }
617
-
618
- return(keys);
544
+ VALUE getColumnKeys(VALUE self) {
545
+ VALUE flag = getFireRubySetting("ALIAS_KEYS"),
546
+ keys = Qnil;
547
+
548
+ if(flag == Qtrue) {
549
+ keys = getColumnAliases(self);
550
+ } else {
551
+ keys = getColumnNames(self);
552
+ }
553
+
554
+ return(keys);
619
555
  }
620
556
 
621
557
 
@@ -624,22 +560,20 @@ VALUE getColumnKeys(VALUE self)
624
560
  *
625
561
  * @param self A reference to the Row object to call the method on.
626
562
  *
627
- * @return A reference to an array containing the row column names.
563
+ * @return A reference to an array containing the row column names.
628
564
  *
629
565
  */
630
- VALUE getColumnNames(VALUE self)
631
- {
632
- VALUE result = rb_ary_new();
633
- RowHandle *row = NULL;
634
- int i;
635
-
636
- Data_Get_Struct(self, RowHandle, row);
637
- for(i = 0; i < row->size; i++)
638
- {
639
- rb_ary_push(result, rb_str_new2(row->columns[i].name));
640
- }
641
-
642
- return(result);
566
+ VALUE getColumnNames(VALUE self) {
567
+ VALUE result = rb_ary_new();
568
+ RowHandle *row = NULL;
569
+ int i;
570
+
571
+ Data_Get_Struct(self, RowHandle, row);
572
+ for(i = 0; i < row->size; i++) {
573
+ rb_ary_push(result, rb_str_new2(row->columns[i].name));
574
+ }
575
+
576
+ return(result);
643
577
  }
644
578
 
645
579
 
@@ -648,22 +582,20 @@ VALUE getColumnNames(VALUE self)
648
582
  *
649
583
  * @param self A reference to the Row object to call the method on.
650
584
  *
651
- * @return A reference to an array containing the row column aliases.
585
+ * @return A reference to an array containing the row column aliases.
652
586
  *
653
587
  */
654
- VALUE getColumnAliases(VALUE self)
655
- {
656
- VALUE result = rb_ary_new();
657
- RowHandle *row = NULL;
658
- int i;
659
-
660
- Data_Get_Struct(self, RowHandle, row);
661
- for(i = 0; i < row->size; i++)
662
- {
663
- rb_ary_push(result, rb_str_new2(row->columns[i].alias));
664
- }
665
-
666
- return(result);
588
+ VALUE getColumnAliases(VALUE self) {
589
+ VALUE result = rb_ary_new();
590
+ RowHandle *row = NULL;
591
+ int i;
592
+
593
+ Data_Get_Struct(self, RowHandle, row);
594
+ for(i = 0; i < row->size; i++) {
595
+ rb_ary_push(result, rb_str_new2(row->columns[i].alias));
596
+ }
597
+
598
+ return(result);
667
599
  }
668
600
 
669
601
 
@@ -672,22 +604,20 @@ VALUE getColumnAliases(VALUE self)
672
604
  *
673
605
  * @param self A reference to the Row object to call the method on.
674
606
  *
675
- * @return A reference to an array containing the row column names.
607
+ * @return A reference to an array containing the row column names.
676
608
  *
677
609
  */
678
- VALUE getColumnValues(VALUE self)
679
- {
680
- VALUE result = rb_ary_new();
681
- RowHandle *row = NULL;
682
- int i;
683
-
684
- Data_Get_Struct(self, RowHandle, row);
685
- for(i = 0; i < row->size; i++)
686
- {
687
- rb_ary_push(result, row->columns[i].value);
688
- }
689
-
690
- return(result);
610
+ VALUE getColumnValues(VALUE self) {
611
+ VALUE result = rb_ary_new();
612
+ RowHandle *row = NULL;
613
+ int i;
614
+
615
+ Data_Get_Struct(self, RowHandle, row);
616
+ for(i = 0; i < row->size; i++) {
617
+ rb_ary_push(result, row->columns[i].value);
618
+ }
619
+
620
+ return(result);
691
621
  }
692
622
 
693
623
 
@@ -700,33 +630,63 @@ VALUE getColumnValues(VALUE self)
700
630
  * @return An Symbol containing the base type details.
701
631
  *
702
632
  */
703
- VALUE getColumnBaseType(VALUE self, VALUE index)
704
- {
705
- VALUE result = Qnil;
706
-
707
- if(TYPE(index) == T_FIXNUM)
708
- {
709
- RowHandle *row = NULL;
710
-
711
- Data_Get_Struct(self, RowHandle, row);
712
- if(row != NULL)
713
- {
714
- int offset = FIX2INT(index);
715
-
716
- /* Correct negative index values. */
717
- if(offset < 0)
718
- {
719
- offset = row->size + offset;
720
- }
721
-
722
- if(offset >= 0 && offset < row->size)
723
- {
724
- result = row->columns[offset].type;
725
- }
633
+ VALUE getColumnBaseType(VALUE self, VALUE index) {
634
+ VALUE result = Qnil;
635
+
636
+ if(TYPE(index) == T_FIXNUM) {
637
+ RowHandle *row = NULL;
638
+
639
+ Data_Get_Struct(self, RowHandle, row);
640
+ if(row != NULL) {
641
+ int offset = FIX2INT(index);
642
+
643
+ /* Correct negative index values. */
644
+ if(offset < 0) {
645
+ offset = row->size + offset;
646
+ }
647
+
648
+ if(offset >= 0 && offset < row->size) {
649
+ result = row->columns[offset].type;
726
650
  }
727
- }
728
-
729
- return(result);
651
+ }
652
+ }
653
+
654
+ return(result);
655
+ }
656
+
657
+ /**
658
+ * This function provides the column_scale method for the Row class.
659
+ *
660
+ * @param self A reference to the Row object to retrieve the column
661
+ * alias from.
662
+ * @param column An offset to the column to retrieve the scale of.
663
+ *
664
+ * @return An Integer representing the scale of the column, or nil if an
665
+ * invalid column was specified.
666
+ *
667
+ */
668
+ static VALUE getColumnScale(VALUE self, VALUE index) {
669
+ VALUE result = Qnil;
670
+
671
+ if(TYPE(index) == T_FIXNUM) {
672
+ RowHandle *row = NULL;
673
+
674
+ Data_Get_Struct(self, RowHandle, row);
675
+ if(row != NULL) {
676
+ int offset = FIX2INT(index);
677
+
678
+ /* Correct negative index values. */
679
+ if(offset < 0) {
680
+ offset = row->size + offset;
681
+ }
682
+
683
+ if(offset >= 0 && offset < row->size) {
684
+ result = row->columns[offset].scale;
685
+ }
686
+ }
687
+ }
688
+
689
+ return(result);
730
690
  }
731
691
 
732
692
 
@@ -739,42 +699,35 @@ VALUE getColumnBaseType(VALUE self, VALUE index)
739
699
  * function.
740
700
  *
741
701
  */
742
- VALUE selectRowEntries(VALUE self)
743
- {
744
- VALUE result = Qnil,
745
- flag = getFireRubySetting("ALIAS_KEYS");
746
- RowHandle *row = NULL;
747
- int i;
748
-
749
- if(!rb_block_given_p())
750
- {
751
- rb_raise(rb_eStandardError, "No block specified in call to Row#select.");
752
- }
753
-
754
- result = rb_ary_new();
755
- Data_Get_Struct(self, RowHandle, row);
756
- for(i = 0; i < row->size; i++)
757
- {
758
- VALUE parameters = rb_ary_new();
759
-
760
- /* Check whether we're keying on column name or alias. */
761
- if(flag == Qtrue)
762
- {
763
- rb_ary_push(parameters, rb_str_new2(row->columns[i].alias));
764
- }
765
- else
766
- {
767
- rb_ary_push(parameters, rb_str_new2(row->columns[i].name));
768
- }
769
- rb_ary_push(parameters, row->columns[i].value);
770
- if(rb_yield(parameters) == Qtrue)
771
- {
772
- rb_ary_push(result, parameters);
773
- }
774
- }
775
-
776
-
777
- return(result);
702
+ VALUE selectRowEntries(VALUE self) {
703
+ VALUE result = Qnil,
704
+ flag = getFireRubySetting("ALIAS_KEYS");
705
+ RowHandle *row = NULL;
706
+ int i;
707
+
708
+ if(!rb_block_given_p()) {
709
+ rb_raise(rb_eStandardError, "No block specified in call to Row#select.");
710
+ }
711
+
712
+ result = rb_ary_new();
713
+ Data_Get_Struct(self, RowHandle, row);
714
+ for(i = 0; i < row->size; i++) {
715
+ VALUE parameters = rb_ary_new();
716
+
717
+ /* Check whether we're keying on column name or alias. */
718
+ if(flag == Qtrue) {
719
+ rb_ary_push(parameters, rb_str_new2(row->columns[i].alias));
720
+ } else {
721
+ rb_ary_push(parameters, rb_str_new2(row->columns[i].name));
722
+ }
723
+ rb_ary_push(parameters, row->columns[i].value);
724
+ if(rb_yield(parameters) == Qtrue) {
725
+ rb_ary_push(result, parameters);
726
+ }
727
+ }
728
+
729
+
730
+ return(result);
778
731
  }
779
732
 
780
733
 
@@ -786,32 +739,27 @@ VALUE selectRowEntries(VALUE self)
786
739
  * @return An array containing the entries from the Row object.
787
740
  *
788
741
  */
789
- VALUE rowToArray(VALUE self)
790
- {
791
- VALUE result = rb_ary_new(),
792
- flag = getFireRubySetting("ALIAS_KEYS");
793
- RowHandle *row = NULL;
794
- int i;
795
-
796
- Data_Get_Struct(self, RowHandle, row);
797
- for(i = 0; i < row->size; i++)
798
- {
799
- VALUE parameters = rb_ary_new();
800
-
801
- /* Check whether we're keying on column name or alias. */
802
- if(flag == Qtrue)
803
- {
804
- rb_ary_push(parameters, rb_str_new2(row->columns[i].alias));
805
- }
806
- else
807
- {
808
- rb_ary_push(parameters, rb_str_new2(row->columns[i].name));
809
- }
810
- rb_ary_push(parameters, row->columns[i].value);
811
- rb_ary_push(result, parameters);
812
- }
813
-
814
- return(result);
742
+ VALUE rowToArray(VALUE self) {
743
+ VALUE result = rb_ary_new(),
744
+ flag = getFireRubySetting("ALIAS_KEYS");
745
+ RowHandle *row = NULL;
746
+ int i;
747
+
748
+ Data_Get_Struct(self, RowHandle, row);
749
+ for(i = 0; i < row->size; i++) {
750
+ VALUE parameters = rb_ary_new();
751
+
752
+ /* Check whether we're keying on column name or alias. */
753
+ if(flag == Qtrue) {
754
+ rb_ary_push(parameters, rb_str_new2(row->columns[i].alias));
755
+ } else {
756
+ rb_ary_push(parameters, rb_str_new2(row->columns[i].name));
757
+ }
758
+ rb_ary_push(parameters, row->columns[i].value);
759
+ rb_ary_push(result, parameters);
760
+ }
761
+
762
+ return(result);
815
763
  }
816
764
 
817
765
 
@@ -823,31 +771,26 @@ VALUE rowToArray(VALUE self)
823
771
  * @return A hash containing the entries from the Row object.
824
772
  *
825
773
  */
826
- VALUE rowToHash(VALUE self)
827
- {
828
- VALUE result = rb_hash_new(),
829
- flag = getFireRubySetting("ALIAS_KEYS");
830
- RowHandle *row = NULL;
831
- int i;
832
-
833
- Data_Get_Struct(self, RowHandle, row);
834
- for(i = 0; i < row->size; i++)
835
- {
836
- VALUE key = Qnil;
837
-
838
- /* Check if we're keying on column name or alias. */
839
- if(flag == Qtrue)
840
- {
841
- key = rb_str_new2(row->columns[i].alias);
842
- }
843
- else
844
- {
845
- key = rb_str_new2(row->columns[i].name);
846
- }
847
- rb_hash_aset(result, key, row->columns[i].value);
848
- }
849
-
850
- return(result);
774
+ VALUE rowToHash(VALUE self) {
775
+ VALUE result = rb_hash_new(),
776
+ flag = getFireRubySetting("ALIAS_KEYS");
777
+ RowHandle *row = NULL;
778
+ int i;
779
+
780
+ Data_Get_Struct(self, RowHandle, row);
781
+ for(i = 0; i < row->size; i++) {
782
+ VALUE key = Qnil;
783
+
784
+ /* Check if we're keying on column name or alias. */
785
+ if(flag == Qtrue) {
786
+ key = rb_str_new2(row->columns[i].alias);
787
+ } else {
788
+ key = rb_str_new2(row->columns[i].name);
789
+ }
790
+ rb_hash_aset(result, key, row->columns[i].value);
791
+ }
792
+
793
+ return(result);
851
794
  }
852
795
 
853
796
 
@@ -861,17 +804,15 @@ VALUE rowToHash(VALUE self)
861
804
  * @return An array of the values that match the column names specified.
862
805
  *
863
806
  */
864
- VALUE rowValuesAt(int size, VALUE *keys, VALUE self)
865
- {
866
- VALUE result = rb_ary_new();
867
- int i;
868
-
869
- for(i = 0; i < size; i++)
870
- {
871
- rb_ary_push(result, getColumnValue(self, keys[i]));
872
- }
873
-
874
- return(result);
807
+ VALUE rowValuesAt(int size, VALUE *keys, VALUE self) {
808
+ VALUE result = rb_ary_new();
809
+ int i;
810
+
811
+ for(i = 0; i < size; i++) {
812
+ rb_ary_push(result, getColumnValue(self, keys[i]));
813
+ }
814
+
815
+ return(result);
875
816
  }
876
817
 
877
818
 
@@ -883,18 +824,15 @@ VALUE rowValuesAt(int size, VALUE *keys, VALUE self)
883
824
  * @param row A pointer to the RowHandle object for the Row object.
884
825
  *
885
826
  */
886
- void freeRow(void *row)
887
- {
888
- if(row != NULL)
889
- {
890
- RowHandle *handle = (RowHandle *)row;
891
-
892
- if(handle->columns != NULL)
893
- {
894
- free(handle->columns);
895
- }
896
- free(handle);
897
- }
827
+ void freeRow(void *row) {
828
+ if(row != NULL) {
829
+ RowHandle *handle = (RowHandle *)row;
830
+
831
+ if(handle->columns != NULL) {
832
+ free(handle->columns);
833
+ }
834
+ free(handle);
835
+ }
898
836
  }
899
837
 
900
838
 
@@ -908,13 +846,12 @@ void freeRow(void *row)
908
846
  * @return A reference to the Row object created.
909
847
  *
910
848
  */
911
- VALUE rb_row_new(VALUE results, VALUE data, VALUE number)
912
- {
913
- VALUE row = allocateRow(cRow);
914
-
915
- initializeRow(row, results, data, number);
916
-
917
- return(row);
849
+ VALUE rb_row_new(VALUE results, VALUE data, VALUE number) {
850
+ VALUE row = allocateRow(cRow);
851
+
852
+ initializeRow(row, results, data, number);
853
+
854
+ return(row);
918
855
  }
919
856
 
920
857
 
@@ -926,40 +863,40 @@ VALUE rb_row_new(VALUE results, VALUE data, VALUE number)
926
863
  * under.
927
864
  *
928
865
  */
929
- void Init_Row(VALUE module)
930
- {
931
- cRow = rb_define_class_under(module, "Row", rb_cObject);
932
- rb_define_alloc_func(cRow, allocateRow);
933
- rb_include_module(cRow, rb_mEnumerable);
934
- rb_define_method(cRow, "initialize", initializeRow, 3);
935
- rb_define_method(cRow, "number", getRowNumber, 0);
936
- rb_define_method(cRow, "column_count", columnsInRow, 0);
937
- rb_define_method(cRow, "column_name", getColumnName, 1);
938
- rb_define_method(cRow, "column_alias", getColumnAlias, 1);
939
- rb_define_method(cRow, "each", eachColumn, 0);
940
- rb_define_method(cRow, "each_key", eachColumnKey, 0);
941
- rb_define_method(cRow, "each_value", eachColumnValue, 0);
942
- rb_define_method(cRow, "[]", getColumnValue, 1);
943
- rb_define_method(cRow, "fetch", fetchRowValue, -1);
944
- rb_define_method(cRow, "has_key?", hasColumnKey, 1);
945
- rb_define_method(cRow, "has_column?", hasColumnName, 1);
946
- rb_define_method(cRow, "has_alias?", hasColumnAlias, 1);
947
- rb_define_method(cRow, "has_value?", hasColumnValue, 1);
948
- rb_define_method(cRow, "keys", getColumnKeys, 0);
949
- rb_define_method(cRow, "names", getColumnNames, 0);
950
- rb_define_method(cRow, "aliases", getColumnAliases, 0);
951
- rb_define_method(cRow, "values", getColumnValues, 0);
952
- rb_define_method(cRow, "get_base_type", getColumnBaseType, 1);
953
- rb_define_method(cRow, "select", selectRowEntries, 0);
954
- rb_define_method(cRow, "to_a", rowToArray, 0);
955
- rb_define_method(cRow, "to_hash", rowToHash, 0);
956
- rb_define_method(cRow, "values_at", rowValuesAt, -1);;
957
-
958
- rb_define_alias(cRow, "each_pair", "each");
959
- rb_define_alias(cRow, "include?", "has_key?");
960
- rb_define_alias(cRow, "key?", "has_key?");
961
- rb_define_alias(cRow, "member?", "has_key?");
962
- rb_define_alias(cRow, "value?", "has_value?");
963
- rb_define_alias(cRow, "length", "column_count");
964
- rb_define_alias(cRow, "size", "column_count");
866
+ void Init_Row(VALUE module) {
867
+ cRow = rb_define_class_under(module, "Row", rb_cObject);
868
+ rb_define_alloc_func(cRow, allocateRow);
869
+ rb_include_module(cRow, rb_mEnumerable);
870
+ rb_define_method(cRow, "initialize", initializeRow, 3);
871
+ rb_define_method(cRow, "number", getRowNumber, 0);
872
+ rb_define_method(cRow, "column_count", columnsInRow, 0);
873
+ rb_define_method(cRow, "column_name", getColumnName, 1);
874
+ rb_define_method(cRow, "column_alias", getColumnAlias, 1);
875
+ rb_define_method(cRow, "column_scale", getColumnScale, 1);
876
+ rb_define_method(cRow, "each", eachColumn, 0);
877
+ rb_define_method(cRow, "each_key", eachColumnKey, 0);
878
+ rb_define_method(cRow, "each_value", eachColumnValue, 0);
879
+ rb_define_method(cRow, "[]", getColumnValue, 1);
880
+ rb_define_method(cRow, "fetch", fetchRowValue, -1);
881
+ rb_define_method(cRow, "has_key?", hasColumnKey, 1);
882
+ rb_define_method(cRow, "has_column?", hasColumnName, 1);
883
+ rb_define_method(cRow, "has_alias?", hasColumnAlias, 1);
884
+ rb_define_method(cRow, "has_value?", hasColumnValue, 1);
885
+ rb_define_method(cRow, "keys", getColumnKeys, 0);
886
+ rb_define_method(cRow, "names", getColumnNames, 0);
887
+ rb_define_method(cRow, "aliases", getColumnAliases, 0);
888
+ rb_define_method(cRow, "values", getColumnValues, 0);
889
+ rb_define_method(cRow, "get_base_type", getColumnBaseType, 1);
890
+ rb_define_method(cRow, "select", selectRowEntries, 0);
891
+ rb_define_method(cRow, "to_a", rowToArray, 0);
892
+ rb_define_method(cRow, "to_hash", rowToHash, 0);
893
+ rb_define_method(cRow, "values_at", rowValuesAt, -1);;
894
+
895
+ rb_define_alias(cRow, "each_pair", "each");
896
+ rb_define_alias(cRow, "include?", "has_key?");
897
+ rb_define_alias(cRow, "key?", "has_key?");
898
+ rb_define_alias(cRow, "member?", "has_key?");
899
+ rb_define_alias(cRow, "value?", "has_value?");
900
+ rb_define_alias(cRow, "length", "column_count");
901
+ rb_define_alias(cRow, "size", "column_count");
965
902
  }