rubyfb 0.6.4 → 0.6.7
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +14 -0
- data/Manifest +6 -7
- data/Rakefile +1 -1
- data/ext/Common.c +74 -0
- data/ext/Common.h +2 -0
- data/ext/Connection.c +0 -1
- data/ext/FireRuby.c +1 -4
- data/ext/Generator.c +0 -1
- data/ext/Statement.c +186 -26
- data/ext/Statement.h +1 -0
- data/ext/Transaction.c +0 -1
- data/ext/TypeMap.c +60 -285
- data/ext/TypeMap.h +2 -10
- data/lib/active_record/connection_adapters/rubyfb_adapter.rb +17 -16
- data/lib/{Connection.rb → connection.rb} +0 -0
- data/lib/{ProcedureCall.rb → procedure_call.rb} +0 -0
- data/lib/result_set.rb +109 -0
- data/lib/row.rb +149 -0
- data/lib/rubyfb.rb +7 -3
- data/lib/rubyfb_lib.so +0 -0
- data/lib/{SQLType.rb → sql_type.rb} +0 -0
- data/lib/statement.rb +17 -0
- data/rubyfb.gemspec +4 -4
- data/test/ResultSetTest.rb +7 -4
- data/test/RowTest.rb +4 -1
- data/test/TypeTest.rb +1 -1
- metadata +14 -12
- data/ext/ResultSet.c +0 -648
- data/ext/ResultSet.h +0 -59
- data/ext/Row.c +0 -678
- data/ext/Row.h +0 -38
data/ext/ResultSet.h
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
/*------------------------------------------------------------------------------
|
2
|
-
* ResultSet.h
|
3
|
-
*----------------------------------------------------------------------------*/
|
4
|
-
/**
|
5
|
-
* Copyright � Peter Wood, 2005
|
6
|
-
*
|
7
|
-
* The contents of this file are subject to the Mozilla Public License Version
|
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
|
10
|
-
*
|
11
|
-
* http://www.mozilla.org/MPL/
|
12
|
-
*
|
13
|
-
* Software distributed under the License is distributed on an "AS IS" basis,
|
14
|
-
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
|
15
|
-
* the specificlanguage governing rights and limitations under the License.
|
16
|
-
*
|
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
|
20
|
-
* Reserved.
|
21
|
-
*
|
22
|
-
* @author Peter Wood
|
23
|
-
* @version 1.0
|
24
|
-
*/
|
25
|
-
#ifndef FIRERUBY_RESULT_SET_H
|
26
|
-
#define FIRERUBY_RESULT_SET_H
|
27
|
-
|
28
|
-
/* Includes. */
|
29
|
-
#ifndef IBASE_H_INCLUDED
|
30
|
-
#include "ibase.h"
|
31
|
-
#define IBASE_H_INCLUDED
|
32
|
-
#endif
|
33
|
-
|
34
|
-
#ifndef RUBY_H_INCLUDED
|
35
|
-
#include "ruby.h"
|
36
|
-
#define RUBY_H_INCLUDED
|
37
|
-
#endif
|
38
|
-
|
39
|
-
/* Type definitions. */
|
40
|
-
typedef struct {
|
41
|
-
long fetched;
|
42
|
-
short active,
|
43
|
-
manage_transaction,
|
44
|
-
manage_statement;
|
45
|
-
} ResultsHandle;
|
46
|
-
|
47
|
-
/* Function prototypes. */
|
48
|
-
VALUE rb_result_set_new(VALUE, VALUE);
|
49
|
-
void resultSetFree(void *);
|
50
|
-
void Init_ResultSet(VALUE);
|
51
|
-
short isActiveResultSet(VALUE);
|
52
|
-
VALUE yieldResultsRows(VALUE);
|
53
|
-
void resultSetManageTransaction(VALUE);
|
54
|
-
void resultSetManageStatement(VALUE);
|
55
|
-
VALUE getResultsColumns(VALUE);
|
56
|
-
|
57
|
-
#endif /* FIRERUBY_RESULT_SET_H */
|
58
|
-
|
59
|
-
|
data/ext/Row.c
DELETED
@@ -1,678 +0,0 @@
|
|
1
|
-
/*------------------------------------------------------------------------------
|
2
|
-
* Row.c
|
3
|
-
*----------------------------------------------------------------------------*/
|
4
|
-
/**
|
5
|
-
* Copyright � Peter Wood, 2005
|
6
|
-
*
|
7
|
-
* The contents of this file are subject to the Mozilla Public License Version
|
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
|
10
|
-
*
|
11
|
-
* http://www.mozilla.org/MPL/
|
12
|
-
*
|
13
|
-
* Software distributed under the License is distributed on an "AS IS" basis,
|
14
|
-
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
|
15
|
-
* the specificlanguage governing rights and limitations under the License.
|
16
|
-
*
|
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
|
20
|
-
* Reserved.
|
21
|
-
*
|
22
|
-
* @author Peter Wood
|
23
|
-
* @version 1.0
|
24
|
-
*/
|
25
|
-
|
26
|
-
/* Includes. */
|
27
|
-
#include "Row.h"
|
28
|
-
#include "TypeMap.h"
|
29
|
-
#include "FireRuby.h"
|
30
|
-
#include "ibase.h"
|
31
|
-
#include "ruby.h"
|
32
|
-
|
33
|
-
/* Function prototypes. */
|
34
|
-
static VALUE initializeRow(VALUE, VALUE, VALUE);
|
35
|
-
static VALUE columnsInRow(VALUE);
|
36
|
-
static VALUE getRowNumber(VALUE);
|
37
|
-
static VALUE getColumnName(VALUE, VALUE);
|
38
|
-
static VALUE getColumnAlias(VALUE, VALUE);
|
39
|
-
static VALUE getColumnScale(VALUE, VALUE);
|
40
|
-
static VALUE getColumnValue(VALUE, VALUE);
|
41
|
-
static VALUE eachColumn(VALUE);
|
42
|
-
static VALUE eachColumnKey(VALUE);
|
43
|
-
static VALUE eachColumnValue(VALUE);
|
44
|
-
static VALUE fetchRowValue(int, VALUE *, VALUE);
|
45
|
-
static VALUE hasColumnKey(VALUE, VALUE);
|
46
|
-
static VALUE hasColumnName(VALUE, VALUE);
|
47
|
-
static VALUE hasColumnAlias(VALUE, VALUE);
|
48
|
-
static VALUE hasColumnValue(VALUE, VALUE);
|
49
|
-
static VALUE getColumnNames(VALUE);
|
50
|
-
static VALUE getColumnAliases(VALUE);
|
51
|
-
static VALUE getColumnValues(VALUE);
|
52
|
-
static VALUE getColumnBaseType(VALUE, VALUE);
|
53
|
-
static VALUE selectRowEntries(VALUE);
|
54
|
-
static VALUE rowToArray(VALUE);
|
55
|
-
static VALUE rowToHash(VALUE);
|
56
|
-
static VALUE rowValuesAt(int, VALUE *, VALUE);
|
57
|
-
|
58
|
-
/* Globals. */
|
59
|
-
VALUE cRow;
|
60
|
-
ID EQL_ID, FETCH_ID, NEW_ID,
|
61
|
-
AT_COLUMNS_ID, AT_NUMBER_ID,
|
62
|
-
AT_NAME_ID, AT_ALIAS_ID, AT_KEY_ID, AT_SCALE_ID,
|
63
|
-
AT_VALUE_ID, AT_TYPE_ID, AT_COLUMN_ID;
|
64
|
-
|
65
|
-
static VALUE getColumns(VALUE self) {
|
66
|
-
return rb_ivar_get(self, AT_COLUMNS_ID);
|
67
|
-
}
|
68
|
-
|
69
|
-
static VALUE checkRowOffset(VALUE columns, VALUE index) {
|
70
|
-
int offset = FIX2INT(index);
|
71
|
-
|
72
|
-
/* Correct negative index values. */
|
73
|
-
if(offset < 0) {
|
74
|
-
return INT2NUM(RARRAY_LEN(columns) + offset);
|
75
|
-
}
|
76
|
-
return index;
|
77
|
-
}
|
78
|
-
|
79
|
-
static VALUE metadataScan(VALUE self, VALUE key, ID slot) {
|
80
|
-
long idx;
|
81
|
-
VALUE columns = getColumns(self);
|
82
|
-
|
83
|
-
for(idx=0; idx < RARRAY_LEN(columns); idx++) {
|
84
|
-
VALUE column = rb_ary_entry(columns, idx),
|
85
|
-
meta_data = rb_ivar_get(column, AT_COLUMN_ID);
|
86
|
-
if(Qtrue == rb_funcall(rb_ivar_get(meta_data, slot), EQL_ID, 1, key)) {
|
87
|
-
return(column);
|
88
|
-
}
|
89
|
-
}
|
90
|
-
return(Qnil);
|
91
|
-
}
|
92
|
-
|
93
|
-
static VALUE rowCollect(VALUE self, ID slot, short metadata_flag) {
|
94
|
-
VALUE columns = getColumns(self);
|
95
|
-
long idx, size = RARRAY_LEN(columns);
|
96
|
-
VALUE result = rb_ary_new2(size);
|
97
|
-
for(idx=0; idx < size; idx++) {
|
98
|
-
VALUE target = rb_ary_entry(columns, idx);
|
99
|
-
if(metadata_flag) {
|
100
|
-
target = rb_ivar_get(target, AT_COLUMN_ID);
|
101
|
-
}
|
102
|
-
rb_ary_store(result, idx, rb_ivar_get(target, slot));
|
103
|
-
}
|
104
|
-
return(result);
|
105
|
-
}
|
106
|
-
|
107
|
-
static VALUE getColumn(VALUE columns, VALUE index) {
|
108
|
-
return rb_funcall(columns, FETCH_ID, 1, index);
|
109
|
-
}
|
110
|
-
|
111
|
-
static VALUE getMetadata(VALUE columns, VALUE index) {
|
112
|
-
return rb_ivar_get(getColumn(columns, index), AT_COLUMN_ID);
|
113
|
-
}
|
114
|
-
|
115
|
-
static VALUE columnKey(VALUE column) {
|
116
|
-
return rb_ivar_get(rb_ivar_get(column, AT_COLUMN_ID), AT_KEY_ID);
|
117
|
-
}
|
118
|
-
|
119
|
-
static VALUE keyValuePair(VALUE column) {
|
120
|
-
VALUE result = rb_ary_new2(2);
|
121
|
-
rb_ary_store(result, 0, columnKey(column));
|
122
|
-
rb_ary_store(result, 1, rb_ivar_get(column, AT_VALUE_ID));
|
123
|
-
return(result);
|
124
|
-
}
|
125
|
-
|
126
|
-
/**
|
127
|
-
* This function provides the initialize method for the Row class.
|
128
|
-
*
|
129
|
-
* @param self A reference to the Row object to be initialized.
|
130
|
-
* @param results A reference to the ResultSet object that generated the row
|
131
|
-
* of data.
|
132
|
-
* @param data A reference to an array object containing the data for the
|
133
|
-
* row. This will be in the form of an array of arrays, with
|
134
|
-
* each contained array containing two elements - the column
|
135
|
-
* value and the column base type.
|
136
|
-
* @param number A reference to the row number to be associated with the
|
137
|
-
* row.
|
138
|
-
*
|
139
|
-
* @return A reference to the initialize Row object.
|
140
|
-
*
|
141
|
-
*/
|
142
|
-
static VALUE initializeRow(VALUE self, VALUE results, VALUE number) {
|
143
|
-
rb_ivar_set(self, AT_NUMBER_ID, number);
|
144
|
-
rb_ivar_set(self, AT_COLUMNS_ID, toRowColumns(results));
|
145
|
-
return(self);
|
146
|
-
}
|
147
|
-
|
148
|
-
|
149
|
-
/**
|
150
|
-
* This function provides the column_count method for the Row class.
|
151
|
-
*
|
152
|
-
* @param self A reference to the Row object to fetch the column count for.
|
153
|
-
*
|
154
|
-
* @return The number of columns that make up the row.
|
155
|
-
*
|
156
|
-
*/
|
157
|
-
static VALUE columnsInRow(VALUE self) {
|
158
|
-
return LONG2NUM(RARRAY_LEN(getColumns(self)));
|
159
|
-
}
|
160
|
-
|
161
|
-
|
162
|
-
/**
|
163
|
-
* This function provides the number method for the Row class.
|
164
|
-
*
|
165
|
-
* @param self A reference to the Row object to retrieve the number for.
|
166
|
-
*
|
167
|
-
* @param A reference to the row number.
|
168
|
-
*
|
169
|
-
*/
|
170
|
-
static VALUE getRowNumber(VALUE self) {
|
171
|
-
return(rb_ivar_get(self, AT_NUMBER_ID));
|
172
|
-
}
|
173
|
-
|
174
|
-
|
175
|
-
/**
|
176
|
-
* This function provides the column_name method for the Row class.
|
177
|
-
*
|
178
|
-
* @param self A reference to the Row object to fetch the column name for.
|
179
|
-
* @param index A reference to the column index to retrieve the name for.
|
180
|
-
*
|
181
|
-
* @return A reference to the column name or nil if an invalid index is
|
182
|
-
* specified.
|
183
|
-
*
|
184
|
-
*/
|
185
|
-
static VALUE getColumnName(VALUE self, VALUE index) {
|
186
|
-
return rb_ivar_get(getMetadata(getColumns(self), index), AT_NAME_ID);
|
187
|
-
}
|
188
|
-
|
189
|
-
|
190
|
-
/**
|
191
|
-
* This function provides the column_alias method for the Row class.
|
192
|
-
*
|
193
|
-
* @param self A reference to the Row object to fetch the column alias for.
|
194
|
-
* @param index A reference to the column index to retrieve the alias for.
|
195
|
-
*
|
196
|
-
* @return A reference to the column alias or nil if an invalid index is
|
197
|
-
* specified.
|
198
|
-
*
|
199
|
-
*/
|
200
|
-
static VALUE getColumnAlias(VALUE self, VALUE index) {
|
201
|
-
return rb_ivar_get(getMetadata(getColumns(self), index), AT_ALIAS_ID);
|
202
|
-
}
|
203
|
-
|
204
|
-
|
205
|
-
/**
|
206
|
-
* This function provides the [] method for the Row class.
|
207
|
-
*
|
208
|
-
* @param self A reference to the Row object to fetch the column alias for.
|
209
|
-
* @param index Either the column index or the column name of the column to
|
210
|
-
* retrieve the value for.
|
211
|
-
*
|
212
|
-
* @return A reference to the column value or nil if an invalid column index
|
213
|
-
* is specified.
|
214
|
-
*
|
215
|
-
*/
|
216
|
-
static VALUE getColumnValue(VALUE self, VALUE index) {
|
217
|
-
VALUE fld;
|
218
|
-
|
219
|
-
if(TYPE(index) == T_STRING) {
|
220
|
-
fld = metadataScan(self, index, AT_KEY_ID);
|
221
|
-
} else {
|
222
|
-
fld = getColumn(getColumns(self), index);
|
223
|
-
}
|
224
|
-
if(Qnil == fld) {
|
225
|
-
return(Qnil);
|
226
|
-
}
|
227
|
-
return rb_ivar_get(fld, AT_VALUE_ID);
|
228
|
-
}
|
229
|
-
|
230
|
-
|
231
|
-
/**
|
232
|
-
* This function provides the each method for the Row class.
|
233
|
-
*
|
234
|
-
* @param self A reference to the Row object that the method is being called
|
235
|
-
* for.
|
236
|
-
*
|
237
|
-
* @return A reference to the last value returned from the block or nil if no
|
238
|
-
* block was provided.
|
239
|
-
*
|
240
|
-
*/
|
241
|
-
VALUE eachColumn(VALUE self) {
|
242
|
-
VALUE result = Qnil;
|
243
|
-
|
244
|
-
if(rb_block_given_p()) {
|
245
|
-
long i;
|
246
|
-
VALUE columns = getColumns(self);
|
247
|
-
for(i = 0; i < RARRAY_LEN(columns); i++) {
|
248
|
-
result = rb_yield(keyValuePair(rb_ary_entry(columns, i)));
|
249
|
-
}
|
250
|
-
}
|
251
|
-
|
252
|
-
return(result);
|
253
|
-
}
|
254
|
-
|
255
|
-
|
256
|
-
/**
|
257
|
-
* This function provides iteration across the column identifiers (either name
|
258
|
-
* or alias depending on library settings) of a Row object.
|
259
|
-
*
|
260
|
-
* @param self A reference to the Row object that the method is being called
|
261
|
-
* for.
|
262
|
-
*
|
263
|
-
* @return A reference to the last value returned from the block or nil if no
|
264
|
-
* block was provided.
|
265
|
-
*
|
266
|
-
*/
|
267
|
-
VALUE eachColumnKey(VALUE self) {
|
268
|
-
VALUE result = Qnil;
|
269
|
-
|
270
|
-
if(rb_block_given_p()) {
|
271
|
-
long i;
|
272
|
-
VALUE columns = getColumns(self);
|
273
|
-
for(i = 0; i < RARRAY_LEN(columns); i++) {
|
274
|
-
result = rb_yield(columnKey(rb_ary_entry(columns, i)));
|
275
|
-
}
|
276
|
-
}
|
277
|
-
|
278
|
-
return(result);
|
279
|
-
}
|
280
|
-
|
281
|
-
|
282
|
-
/**
|
283
|
-
* This function provides the each_value method for the Row class.
|
284
|
-
*
|
285
|
-
* @param self A reference to the Row object that the method is being called
|
286
|
-
* for.
|
287
|
-
*
|
288
|
-
* @return A reference to the last value returned from the block or nil if no
|
289
|
-
* block was provided.
|
290
|
-
*
|
291
|
-
*/
|
292
|
-
VALUE eachColumnValue(VALUE self) {
|
293
|
-
VALUE result = Qnil;
|
294
|
-
|
295
|
-
if(rb_block_given_p()) {
|
296
|
-
long i;
|
297
|
-
VALUE columns = getColumns(self);
|
298
|
-
for(i = 0; i < RARRAY_LEN(columns); i++) {
|
299
|
-
result = rb_yield(rb_ivar_get(rb_ary_entry(columns, i), AT_VALUE_ID));
|
300
|
-
}
|
301
|
-
}
|
302
|
-
|
303
|
-
return(result);
|
304
|
-
}
|
305
|
-
|
306
|
-
|
307
|
-
/**
|
308
|
-
* This function provides the fetch method for the Row class.
|
309
|
-
*
|
310
|
-
* @param self A reference to the Row class that the method is being
|
311
|
-
* called for.
|
312
|
-
* @param parameters A reference to an array containing the parameters for
|
313
|
-
* the method call. Must contain at least a key.
|
314
|
-
*
|
315
|
-
* @return A reference to the column value, the alternative value of the
|
316
|
-
* return value for any block specified.
|
317
|
-
*
|
318
|
-
*/
|
319
|
-
VALUE fetchRowValue(int size, VALUE *parameters, VALUE self) {
|
320
|
-
VALUE value = Qnil;
|
321
|
-
|
322
|
-
if(size < 1) {
|
323
|
-
rb_raise(rb_eArgError, "Wrong number of arguments (%d for %d)", size, 1);
|
324
|
-
}
|
325
|
-
|
326
|
-
/* Extract the parameters. */
|
327
|
-
value = getColumnValue(self, parameters[0]);
|
328
|
-
if(value == Qnil) {
|
329
|
-
if(size == 1 && rb_block_given_p()) {
|
330
|
-
value = rb_yield(rb_ary_new());
|
331
|
-
} else {
|
332
|
-
if(size == 1) {
|
333
|
-
rb_raise(rb_eIndexError, "Column identifier '%s' not found in row.",
|
334
|
-
StringValuePtr(parameters[0]));
|
335
|
-
}
|
336
|
-
value = parameters[1];
|
337
|
-
}
|
338
|
-
}
|
339
|
-
|
340
|
-
return(value);
|
341
|
-
}
|
342
|
-
|
343
|
-
|
344
|
-
/**
|
345
|
-
* This function provides the has_key? method for the Row class.
|
346
|
-
*
|
347
|
-
* @param self A reference to the Row object to call the method on.
|
348
|
-
* @param name A reference to a String containing the name of the column to
|
349
|
-
* check for.
|
350
|
-
*
|
351
|
-
* @return True if the row possesses the specified column name, false
|
352
|
-
* otherwise.
|
353
|
-
*
|
354
|
-
*/
|
355
|
-
VALUE hasColumnKey(VALUE self, VALUE name) {
|
356
|
-
if(Qnil == metadataScan(self, name, AT_KEY_ID)) {
|
357
|
-
return Qfalse;
|
358
|
-
}
|
359
|
-
return Qtrue;
|
360
|
-
}
|
361
|
-
|
362
|
-
|
363
|
-
/**
|
364
|
-
* This function provides the has_column? method for the Row class.
|
365
|
-
*
|
366
|
-
* @param self A reference to the Row object to call the method on.
|
367
|
-
* @param name A reference to a String containing the name of the column to
|
368
|
-
* check for.
|
369
|
-
*
|
370
|
-
* @return True if the row possesses the specified column name, false
|
371
|
-
* otherwise.
|
372
|
-
*
|
373
|
-
*/
|
374
|
-
VALUE hasColumnName(VALUE self, VALUE name) {
|
375
|
-
if(Qnil == metadataScan(self, name, AT_NAME_ID)) {
|
376
|
-
return Qfalse;
|
377
|
-
}
|
378
|
-
return Qtrue;
|
379
|
-
}
|
380
|
-
|
381
|
-
|
382
|
-
/**
|
383
|
-
* This function provides the has_alias? method for the Row class.
|
384
|
-
*
|
385
|
-
* @param self A reference to the Row object to call the method on.
|
386
|
-
* @param name A reference to a String containing the alias of the column to
|
387
|
-
* check for.
|
388
|
-
*
|
389
|
-
* @return True if the row possesses the specified column alias, false
|
390
|
-
* otherwise.
|
391
|
-
*
|
392
|
-
*/
|
393
|
-
VALUE hasColumnAlias(VALUE self, VALUE name) {
|
394
|
-
if(Qnil == metadataScan(self, name, AT_ALIAS_ID)) {
|
395
|
-
return Qfalse;
|
396
|
-
}
|
397
|
-
return Qtrue;
|
398
|
-
}
|
399
|
-
|
400
|
-
|
401
|
-
/**
|
402
|
-
* This function provides the has_value? method for the Row class.
|
403
|
-
*
|
404
|
-
* @param self A reference to the Row object to call the method on.
|
405
|
-
* @param value A reference to the value to be checked for.
|
406
|
-
*
|
407
|
-
* @return True if the row contains a matching value, false otherwise.
|
408
|
-
*
|
409
|
-
*/
|
410
|
-
VALUE hasColumnValue(VALUE self, VALUE value) {
|
411
|
-
long i;
|
412
|
-
VALUE columns = getColumns(self);
|
413
|
-
for(i = 0; i < RARRAY_LEN(columns); i++) {
|
414
|
-
if(Qtrue == rb_funcall(rb_ivar_get(rb_ary_entry(columns, i), AT_VALUE_ID), EQL_ID, 1, value)) {
|
415
|
-
return(Qtrue);
|
416
|
-
}
|
417
|
-
}
|
418
|
-
return(Qfalse);
|
419
|
-
}
|
420
|
-
|
421
|
-
/**
|
422
|
-
* This function fetches a list of column index keys for a Row object. What the
|
423
|
-
* keys are depends on the library settings, but they will either be the column
|
424
|
-
* names or the column aliases.
|
425
|
-
*
|
426
|
-
* @param self A reference to the Row object to make the call on.
|
427
|
-
*
|
428
|
-
* @return A reference to an array containing the row keys.
|
429
|
-
*
|
430
|
-
*/
|
431
|
-
VALUE getColumnKeys(VALUE self) {
|
432
|
-
return rowCollect(self, AT_KEY_ID, 1);
|
433
|
-
}
|
434
|
-
|
435
|
-
|
436
|
-
/**
|
437
|
-
* This function provides the keys method for the Row class.
|
438
|
-
*
|
439
|
-
* @param self A reference to the Row object to call the method on.
|
440
|
-
*
|
441
|
-
* @return A reference to an array containing the row column names.
|
442
|
-
*
|
443
|
-
*/
|
444
|
-
VALUE getColumnNames(VALUE self) {
|
445
|
-
return rowCollect(self, AT_NAME_ID, 1);
|
446
|
-
}
|
447
|
-
|
448
|
-
|
449
|
-
/**
|
450
|
-
* This function provides the aliases method for the Row class.
|
451
|
-
*
|
452
|
-
* @param self A reference to the Row object to call the method on.
|
453
|
-
*
|
454
|
-
* @return A reference to an array containing the row column aliases.
|
455
|
-
*
|
456
|
-
*/
|
457
|
-
VALUE getColumnAliases(VALUE self) {
|
458
|
-
return rowCollect(self, AT_ALIAS_ID, 1);
|
459
|
-
}
|
460
|
-
|
461
|
-
|
462
|
-
/**
|
463
|
-
* This function provides the values method for the Row class.
|
464
|
-
*
|
465
|
-
* @param self A reference to the Row object to call the method on.
|
466
|
-
*
|
467
|
-
* @return A reference to an array containing the row column names.
|
468
|
-
*
|
469
|
-
*/
|
470
|
-
VALUE getColumnValues(VALUE self) {
|
471
|
-
return rowCollect(self, AT_VALUE_ID, 0);
|
472
|
-
}
|
473
|
-
|
474
|
-
|
475
|
-
/**
|
476
|
-
* This function provides the get_base_type method for the Row class.
|
477
|
-
*
|
478
|
-
* @param self A reference to the Row object to call the method on.
|
479
|
-
* @param index The index of the column to retrieve the base type for.
|
480
|
-
*
|
481
|
-
* @return An Symbol containing the base type details.
|
482
|
-
*
|
483
|
-
*/
|
484
|
-
VALUE getColumnBaseType(VALUE self, VALUE index) {
|
485
|
-
VALUE columns = getColumns(self);
|
486
|
-
return rb_ivar_get(getMetadata(columns, checkRowOffset(columns, index)), AT_TYPE_ID);
|
487
|
-
}
|
488
|
-
|
489
|
-
/**
|
490
|
-
* This function provides the column_scale method for the Row class.
|
491
|
-
*
|
492
|
-
* @param self A reference to the Row object to retrieve the column
|
493
|
-
* alias from.
|
494
|
-
* @param column An offset to the column to retrieve the scale of.
|
495
|
-
*
|
496
|
-
* @return An Integer representing the scale of the column, or nil if an
|
497
|
-
* invalid column was specified.
|
498
|
-
*
|
499
|
-
*/
|
500
|
-
static VALUE getColumnScale(VALUE self, VALUE index) {
|
501
|
-
VALUE columns = getColumns(self);
|
502
|
-
return rb_ivar_get(getMetadata(columns, checkRowOffset(columns, index)), AT_SCALE_ID);
|
503
|
-
}
|
504
|
-
|
505
|
-
|
506
|
-
/**
|
507
|
-
* This function provides the select method for the Row class.
|
508
|
-
*
|
509
|
-
* @param self A reference to the Row object to make the method call on.
|
510
|
-
*
|
511
|
-
* @return An array containing the entries selected by the block passed to the
|
512
|
-
* function.
|
513
|
-
*
|
514
|
-
*/
|
515
|
-
VALUE selectRowEntries(VALUE self) {
|
516
|
-
long i;
|
517
|
-
VALUE result = rb_ary_new(),
|
518
|
-
columns = getColumns(self);
|
519
|
-
|
520
|
-
if(!rb_block_given_p()) {
|
521
|
-
rb_raise(rb_eStandardError, "No block specified in call to Row#select.");
|
522
|
-
}
|
523
|
-
|
524
|
-
for(i = 0; i < RARRAY_LEN(columns); i++) {
|
525
|
-
VALUE parameters = keyValuePair(rb_ary_entry(columns, i));
|
526
|
-
if(rb_yield(parameters) == Qtrue) {
|
527
|
-
rb_ary_push(result, parameters);
|
528
|
-
}
|
529
|
-
}
|
530
|
-
|
531
|
-
return(result);
|
532
|
-
}
|
533
|
-
|
534
|
-
|
535
|
-
/**
|
536
|
-
* This function provides the to_a method for the Row class.
|
537
|
-
*
|
538
|
-
* @param self A reference to the Row object to make the method call on.
|
539
|
-
*
|
540
|
-
* @return An array containing the entries from the Row object.
|
541
|
-
*
|
542
|
-
*/
|
543
|
-
VALUE rowToArray(VALUE self) {
|
544
|
-
long i;
|
545
|
-
VALUE result = rb_ary_new(),
|
546
|
-
columns = getColumns(self);
|
547
|
-
|
548
|
-
for(i = 0; i < RARRAY_LEN(columns); i++) {
|
549
|
-
rb_ary_push(result, keyValuePair(rb_ary_entry(columns, i)));
|
550
|
-
}
|
551
|
-
|
552
|
-
return(result);
|
553
|
-
}
|
554
|
-
|
555
|
-
|
556
|
-
/**
|
557
|
-
* This function provides the to_hash method for the Row class.
|
558
|
-
*
|
559
|
-
* @param self A reference to the Row object to make the method call on.
|
560
|
-
*
|
561
|
-
* @return A hash containing the entries from the Row object.
|
562
|
-
*
|
563
|
-
*/
|
564
|
-
VALUE rowToHash(VALUE self) {
|
565
|
-
long i;
|
566
|
-
VALUE result = rb_hash_new(),
|
567
|
-
columns = getColumns(self);
|
568
|
-
|
569
|
-
for(i = 0; i < RARRAY_LEN(columns); i++) {
|
570
|
-
VALUE fld = rb_ary_entry(columns, i);
|
571
|
-
rb_hash_aset(result, columnKey(fld), rb_ivar_get(fld, AT_VALUE_ID));
|
572
|
-
}
|
573
|
-
|
574
|
-
return(result);
|
575
|
-
}
|
576
|
-
|
577
|
-
|
578
|
-
/**
|
579
|
-
* This function provides the values_at method for the Row class.
|
580
|
-
*
|
581
|
-
* @param self A reference to the Row object to call the method on.
|
582
|
-
* @param keys An array containing the name of the columns that should be
|
583
|
-
* included in the output array.
|
584
|
-
*
|
585
|
-
* @return An array of the values that match the column names specified.
|
586
|
-
*
|
587
|
-
*/
|
588
|
-
VALUE rowValuesAt(int size, VALUE *keys, VALUE self) {
|
589
|
-
int i;
|
590
|
-
VALUE result = rb_ary_new();
|
591
|
-
|
592
|
-
for(i = 0; i < size; i++) {
|
593
|
-
rb_ary_push(result, getColumnValue(self, keys[i]));
|
594
|
-
}
|
595
|
-
|
596
|
-
return(result);
|
597
|
-
}
|
598
|
-
|
599
|
-
|
600
|
-
/**
|
601
|
-
* This function provides a programmatic means of creating a Row object.
|
602
|
-
*
|
603
|
-
* @param results A reference to the ResultSet object that the row relates to.
|
604
|
-
* @param data A reference to an array containing the row data.
|
605
|
-
* @param number A reference to the number to be associated with the row.
|
606
|
-
*
|
607
|
-
* @return A reference to the Row object created.
|
608
|
-
*
|
609
|
-
*/
|
610
|
-
VALUE rb_row_new(VALUE results, VALUE number) {
|
611
|
-
VALUE row = rb_funcall(cRow, NEW_ID, 2, results, number);
|
612
|
-
|
613
|
-
RB_GC_GUARD(row);
|
614
|
-
|
615
|
-
initializeRow(row, results, number);
|
616
|
-
|
617
|
-
return(row);
|
618
|
-
}
|
619
|
-
|
620
|
-
|
621
|
-
/**
|
622
|
-
* This function is used to create and initialize the Row class within the
|
623
|
-
* Ruby environment.
|
624
|
-
*
|
625
|
-
* @param module A reference to the module that the Row class will be created
|
626
|
-
* under.
|
627
|
-
*
|
628
|
-
*/
|
629
|
-
void Init_Row(VALUE module) {
|
630
|
-
Init_TypeMap();
|
631
|
-
EQL_ID = rb_intern("eql?");
|
632
|
-
FETCH_ID = rb_intern("fetch");
|
633
|
-
AT_NAME_ID = rb_intern("@name");
|
634
|
-
AT_ALIAS_ID = rb_intern("@alias");
|
635
|
-
AT_KEY_ID = rb_intern("@key");
|
636
|
-
AT_SCALE_ID = rb_intern("@scale");
|
637
|
-
AT_COLUMNS_ID = rb_intern("@columns");
|
638
|
-
AT_NUMBER_ID = rb_intern("@number");
|
639
|
-
AT_VALUE_ID = rb_intern("@value");
|
640
|
-
AT_TYPE_ID = rb_intern("@type");
|
641
|
-
NEW_ID = rb_intern("new");
|
642
|
-
AT_COLUMN_ID = rb_intern("@column");
|
643
|
-
|
644
|
-
cRow = rb_define_class_under(module, "Row", rb_cObject);
|
645
|
-
rb_include_module(cRow, rb_mEnumerable);
|
646
|
-
rb_define_method(cRow, "initialize", initializeRow, 2);
|
647
|
-
rb_define_method(cRow, "number", getRowNumber, 0);
|
648
|
-
rb_define_method(cRow, "column_count", columnsInRow, 0);
|
649
|
-
rb_define_method(cRow, "column_name", getColumnName, 1);
|
650
|
-
rb_define_method(cRow, "column_alias", getColumnAlias, 1);
|
651
|
-
rb_define_method(cRow, "column_scale", getColumnScale, 1);
|
652
|
-
rb_define_method(cRow, "each", eachColumn, 0);
|
653
|
-
rb_define_method(cRow, "each_key", eachColumnKey, 0);
|
654
|
-
rb_define_method(cRow, "each_value", eachColumnValue, 0);
|
655
|
-
rb_define_method(cRow, "[]", getColumnValue, 1);
|
656
|
-
rb_define_method(cRow, "fetch", fetchRowValue, -1);
|
657
|
-
rb_define_method(cRow, "has_key?", hasColumnKey, 1);
|
658
|
-
rb_define_method(cRow, "has_column?", hasColumnName, 1);
|
659
|
-
rb_define_method(cRow, "has_alias?", hasColumnAlias, 1);
|
660
|
-
rb_define_method(cRow, "has_value?", hasColumnValue, 1);
|
661
|
-
rb_define_method(cRow, "keys", getColumnKeys, 0);
|
662
|
-
rb_define_method(cRow, "names", getColumnNames, 0);
|
663
|
-
rb_define_method(cRow, "aliases", getColumnAliases, 0);
|
664
|
-
rb_define_method(cRow, "values", getColumnValues, 0);
|
665
|
-
rb_define_method(cRow, "get_base_type", getColumnBaseType, 1);
|
666
|
-
rb_define_method(cRow, "select", selectRowEntries, 0);
|
667
|
-
rb_define_method(cRow, "to_a", rowToArray, 0);
|
668
|
-
rb_define_method(cRow, "to_hash", rowToHash, 0);
|
669
|
-
rb_define_method(cRow, "values_at", rowValuesAt, -1);;
|
670
|
-
|
671
|
-
rb_define_alias(cRow, "each_pair", "each");
|
672
|
-
rb_define_alias(cRow, "include?", "has_key?");
|
673
|
-
rb_define_alias(cRow, "key?", "has_key?");
|
674
|
-
rb_define_alias(cRow, "member?", "has_key?");
|
675
|
-
rb_define_alias(cRow, "value?", "has_value?");
|
676
|
-
rb_define_alias(cRow, "length", "column_count");
|
677
|
-
rb_define_alias(cRow, "size", "column_count");
|
678
|
-
}
|