openbase 0.8.1
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/History.txt +50 -0
- data/License.txt +20 -0
- data/Manifest.txt +53 -0
- data/README.txt +35 -0
- data/Rakefile +126 -0
- data/examples/example.rb +37 -0
- data/ext/CommAPI.c +643 -0
- data/ext/Headers/CommAPI.h +1 -0
- data/ext/Headers/NetClient.h +42 -0
- data/ext/Headers/NetClientLib.h +41 -0
- data/ext/Headers/OB_Memory.h +69 -0
- data/ext/Headers/OpenBaseAdmin.h +227 -0
- data/ext/Headers/OpenBaseConnection.h +337 -0
- data/ext/Headers/OpenBaseEncoding.h +302 -0
- data/ext/Headers/OpenBasePrepare.h +1 -0
- data/ext/Headers/OpenBaseSupport.h +1 -0
- data/ext/Headers/Platform_Carbon_Header.h +5 -0
- data/ext/Headers/Platform_Classic_Header.h +6 -0
- data/ext/Headers/Platform_Linux.h +4 -0
- data/ext/Headers/Platform_Mach_Header.h +4 -0
- data/ext/Headers/Platform_Windows.h +3 -0
- data/ext/Headers/conversion.h +1 -0
- data/ext/Headers/datetime.h +26 -0
- data/ext/Headers/longlong.h +46 -0
- data/ext/Headers/platform.h +67 -0
- data/ext/Headers/stringConversion.h +15 -0
- data/ext/NetClient.c +888 -0
- data/ext/OpenBaseAdmin.c +1884 -0
- data/ext/OpenBaseConnection.c +1841 -0
- data/ext/OpenBaseEncoding.c +993 -0
- data/ext/OpenBaseEncoding_DOS.c +1 -0
- data/ext/OpenBaseEncoding_ISO8859.c +1 -0
- data/ext/OpenBaseEncoding_MacOS.c +1 -0
- data/ext/OpenBaseEncoding_Windows.c +1150 -0
- data/ext/OpenBasePrepare.c +1 -0
- data/ext/OpenBaseSupport.c +1 -0
- data/ext/conversion.c +1 -0
- data/ext/datetime.c +816 -0
- data/ext/depend +1 -0
- data/ext/extconf.rb +10 -0
- data/ext/longlong.c +1 -0
- data/ext/openbase.c +980 -0
- data/ext/stringConversion.c +169 -0
- data/lib/ruby-openbase/version.rb +9 -0
- data/scripts/txt2html +67 -0
- data/setup.rb +1585 -0
- data/test/test_helper.rb +2 -0
- data/test/test_openbase.rb +241 -0
- data/website/index.html +114 -0
- data/website/index.txt +59 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +133 -0
- data/website/template.rhtml +47 -0
- metadata +105 -0
data/ext/depend
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
openbase.o: openbase.c
|
data/ext/extconf.rb
ADDED
data/ext/longlong.c
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
// ------------------------------------------------------------------------------
|
data/ext/openbase.c
ADDED
@@ -0,0 +1,980 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <OpenBaseConnection.h>
|
3
|
+
#include <CommAPI.h>
|
4
|
+
#include <NetClient.h>
|
5
|
+
#include <stdio.h>
|
6
|
+
|
7
|
+
// Ruby Classes Declared by this Library
|
8
|
+
static VALUE rb_cOpenBase;
|
9
|
+
static VALUE rb_cOpenBaseResult;
|
10
|
+
static VALUE rb_cOpenBaseColumnInfo;
|
11
|
+
static VALUE rb_cOpenBaseError;
|
12
|
+
|
13
|
+
// Ruby methods used by this Library
|
14
|
+
static ID rb_gsub_bang_id;
|
15
|
+
static VALUE rb_date_regex;
|
16
|
+
static VALUE rb_replacement_str;
|
17
|
+
|
18
|
+
// Other Ruby Classes used by this Library
|
19
|
+
static VALUE rb_cDate;
|
20
|
+
static VALUE rb_cBigDecimal;
|
21
|
+
|
22
|
+
|
23
|
+
#define OB_CHAR_LENGTH 4096
|
24
|
+
#define OB_MONEY_LENGTH 32
|
25
|
+
#define OB_DATE_LENGTH 32
|
26
|
+
#define OB_TIME_LENGTH 32
|
27
|
+
#define OB_DATETIME_LENGTH 32
|
28
|
+
#define OB_TIMESTAMP_LENGTH 32
|
29
|
+
#define OB_BLOB_KEY_LENGTH 8
|
30
|
+
#define OB_BOOLEAN_LENGTH 2
|
31
|
+
|
32
|
+
|
33
|
+
/**** Macros ****/
|
34
|
+
#define GET_OPENBASE(obj,var) Data_Get_Struct(obj, OpenBase, var)
|
35
|
+
#define GET_OPENBASE_IF_CONNECTED(obj,var) \
|
36
|
+
Data_Get_Struct(obj, OpenBase, var); \
|
37
|
+
if (!ob_isConnected(var)) { \
|
38
|
+
rb_raise(rb_cOpenBaseError, "The database is not connected."); \
|
39
|
+
}
|
40
|
+
|
41
|
+
#define GET_RESULT(obj,var) Data_Get_Struct(obj, OpenBaseResult, var)
|
42
|
+
#define GET_INFO(obj,var) Data_Get_Struct(obj, OpenBaseColumnInfo, var)
|
43
|
+
|
44
|
+
#define OPTIONAL_STRING(var,default_string) \
|
45
|
+
if (NIL_P(var)) { var = rb_str_new2(default_string); } \
|
46
|
+
else { Check_Type(var, T_STRING); }
|
47
|
+
|
48
|
+
|
49
|
+
struct OpenBaseResultStruct {
|
50
|
+
OpenBasePtr openbase;
|
51
|
+
OpenBaseCursorPtr cursor;
|
52
|
+
VALUE infos;
|
53
|
+
VALUE col_names; // used to create hashes
|
54
|
+
long fetch_limit;
|
55
|
+
long fetch_offset;
|
56
|
+
int rows_fetched;
|
57
|
+
int has_been_offset;
|
58
|
+
long rows_affected;
|
59
|
+
int col_count; // column count
|
60
|
+
int *types; // result column types
|
61
|
+
void **buf; // buffer to bind result columns
|
62
|
+
};
|
63
|
+
typedef struct OpenBaseResultStruct OpenBaseResult;
|
64
|
+
|
65
|
+
struct OpenBaseColumnInfoStruct {
|
66
|
+
VALUE name;
|
67
|
+
VALUE type;
|
68
|
+
VALUE table;
|
69
|
+
};
|
70
|
+
typedef struct OpenBaseColumnInfoStruct OpenBaseColumnInfo;
|
71
|
+
|
72
|
+
|
73
|
+
/**** Class Constructor Prototypes ****/
|
74
|
+
static VALUE result_new _((VALUE self, VALUE obconn));
|
75
|
+
static VALUE columninfo_new _((VALUE self, VALUE name, VALUE type, VALUE table));
|
76
|
+
|
77
|
+
|
78
|
+
/*** OpenBase: Construction/Destruction ***/
|
79
|
+
|
80
|
+
static void openbase_free( OpenBasePtr openbase )
|
81
|
+
{
|
82
|
+
ob_deallocConnection(openbase);
|
83
|
+
}
|
84
|
+
|
85
|
+
static VALUE openbase_alloc( VALUE klass )
|
86
|
+
{
|
87
|
+
OpenBasePtr openbase = ob_newConnection();
|
88
|
+
return Data_Wrap_Struct(klass, 0, openbase_free, openbase);
|
89
|
+
}
|
90
|
+
|
91
|
+
static VALUE openbase_initialize( int argc, VALUE *argv, VALUE self )
|
92
|
+
{
|
93
|
+
OpenBasePtr openbase;
|
94
|
+
|
95
|
+
GET_OPENBASE(self, openbase);
|
96
|
+
|
97
|
+
if (argc >=3) rb_funcall2(self, rb_intern("connect"), argc, argv);
|
98
|
+
|
99
|
+
return Qnil;
|
100
|
+
}
|
101
|
+
|
102
|
+
/* END OpenBase Construction/Destruction */
|
103
|
+
|
104
|
+
|
105
|
+
/*** OpenBase: Connection Methods ***/
|
106
|
+
|
107
|
+
static VALUE openbase_connect( int argc, VALUE *argv, VALUE self )
|
108
|
+
{
|
109
|
+
OpenBasePtr openbase;
|
110
|
+
VALUE database, host, login, password;
|
111
|
+
int return_code;
|
112
|
+
|
113
|
+
GET_OPENBASE(self, openbase);
|
114
|
+
rb_scan_args(argc, argv, "31", &database, &host, &login, &password);
|
115
|
+
|
116
|
+
Check_Type(database, T_STRING);
|
117
|
+
OPTIONAL_STRING(host, "127.0.0.1");
|
118
|
+
OPTIONAL_STRING(login, "admin");
|
119
|
+
OPTIONAL_STRING(password, "");
|
120
|
+
|
121
|
+
if (ob_isConnected(openbase)) {ob_invalidate(openbase);}
|
122
|
+
if ( !ob_connectToDatabase(openbase,StringValuePtr(database), StringValuePtr(host), StringValuePtr(login), StringValuePtr(password),"","", &return_code) ) {
|
123
|
+
rb_raise(rb_cOpenBaseError, ob_connectErrorMessage(openbase));
|
124
|
+
}
|
125
|
+
|
126
|
+
return Qnil;
|
127
|
+
}
|
128
|
+
|
129
|
+
static VALUE openbase_isConnected( VALUE self )
|
130
|
+
{
|
131
|
+
OpenBasePtr openbase;
|
132
|
+
|
133
|
+
GET_OPENBASE(self, openbase);
|
134
|
+
|
135
|
+
if (ob_isConnected(openbase)) {
|
136
|
+
return Qtrue;
|
137
|
+
} else {
|
138
|
+
return Qfalse;
|
139
|
+
}
|
140
|
+
}
|
141
|
+
|
142
|
+
static VALUE openbase_invalidate( VALUE self )
|
143
|
+
{
|
144
|
+
OpenBasePtr openbase;
|
145
|
+
|
146
|
+
GET_OPENBASE(self, openbase);
|
147
|
+
ob_invalidate(openbase);
|
148
|
+
|
149
|
+
return Qnil;
|
150
|
+
}
|
151
|
+
|
152
|
+
static VALUE openbase_database( VALUE self )
|
153
|
+
{
|
154
|
+
OpenBasePtr openbase;
|
155
|
+
GET_OPENBASE_IF_CONNECTED(self, openbase);
|
156
|
+
|
157
|
+
return rb_str_new2(ob_databaseName(openbase));
|
158
|
+
}
|
159
|
+
|
160
|
+
static VALUE openbase_host( VALUE self )
|
161
|
+
{
|
162
|
+
OpenBasePtr openbase;
|
163
|
+
GET_OPENBASE_IF_CONNECTED(self, openbase);
|
164
|
+
|
165
|
+
return rb_str_new2(ob_hostName(openbase));
|
166
|
+
}
|
167
|
+
|
168
|
+
static VALUE openbase_login( VALUE self )
|
169
|
+
{
|
170
|
+
OpenBasePtr openbase;
|
171
|
+
GET_OPENBASE_IF_CONNECTED(self, openbase);
|
172
|
+
|
173
|
+
return rb_str_new2(ob_loginName(openbase));
|
174
|
+
}
|
175
|
+
|
176
|
+
static VALUE openbase_password( VALUE self )
|
177
|
+
{
|
178
|
+
OpenBasePtr openbase;
|
179
|
+
GET_OPENBASE_IF_CONNECTED(self, openbase);
|
180
|
+
|
181
|
+
return rb_str_new2(ob_password(openbase));
|
182
|
+
}
|
183
|
+
|
184
|
+
static VALUE openbase_encoding( VALUE self )
|
185
|
+
{
|
186
|
+
OpenBasePtr openbase;
|
187
|
+
|
188
|
+
GET_OPENBASE(self, openbase);
|
189
|
+
return rb_str_new2(ob_getEncodingName(ob_databaseEncoding(openbase)));
|
190
|
+
}
|
191
|
+
|
192
|
+
/* END OpenBase Connection Methods */
|
193
|
+
|
194
|
+
|
195
|
+
/*** OpenBase: Schema Methods ***/
|
196
|
+
|
197
|
+
static VALUE openbase_tables( VALUE self )
|
198
|
+
{
|
199
|
+
OpenBasePtr openbase;
|
200
|
+
VALUE ary;
|
201
|
+
char table_name[100];
|
202
|
+
|
203
|
+
GET_OPENBASE_IF_CONNECTED(self, openbase);
|
204
|
+
|
205
|
+
ary = rb_ary_new();
|
206
|
+
|
207
|
+
ob_makeCommand(openbase,"select distinct tablename from _sys_tables");
|
208
|
+
if (ob_executeCommand(openbase)) {
|
209
|
+
ob_bindString(openbase,table_name);
|
210
|
+
while (ob_nextRow(openbase)) {
|
211
|
+
rb_ary_push(ary, rb_str_new2(table_name));
|
212
|
+
}
|
213
|
+
}
|
214
|
+
|
215
|
+
return ary;
|
216
|
+
}
|
217
|
+
|
218
|
+
|
219
|
+
static VALUE openbase_columns( VALUE self, VALUE table )
|
220
|
+
{
|
221
|
+
OpenBasePtr openbase;
|
222
|
+
VALUE ary;
|
223
|
+
char col_name[100];
|
224
|
+
|
225
|
+
GET_OPENBASE_IF_CONNECTED(self, openbase);
|
226
|
+
|
227
|
+
ary = rb_ary_new();
|
228
|
+
|
229
|
+
ob_makeCommand(openbase, "select fieldname, typename from _SYS_TABLES where tablename = '");
|
230
|
+
ob_makeCommand(openbase, RSTRING(table)->ptr);
|
231
|
+
ob_makeCommand(openbase, "' and fieldname not in('_timestamp', '_version') ");
|
232
|
+
if (ob_executeCommand(openbase)) {
|
233
|
+
ob_bindString(openbase,col_name);
|
234
|
+
while (ob_nextRow(openbase)) {
|
235
|
+
rb_ary_push(ary, rb_str_new2(col_name));
|
236
|
+
}
|
237
|
+
}
|
238
|
+
|
239
|
+
return ary;
|
240
|
+
}
|
241
|
+
|
242
|
+
|
243
|
+
static VALUE openbase_relationships( VALUE self, VALUE table )
|
244
|
+
{
|
245
|
+
OpenBasePtr openbase;
|
246
|
+
VALUE ary;
|
247
|
+
char relationship_name[100];
|
248
|
+
|
249
|
+
GET_OPENBASE_IF_CONNECTED(self, openbase);
|
250
|
+
|
251
|
+
ary = rb_ary_new();
|
252
|
+
|
253
|
+
ob_makeCommand(openbase, "select relationshipName from _SYS_RELATIONSHIP where source_table = '");
|
254
|
+
ob_makeCommand(openbase, RSTRING(table)->ptr);
|
255
|
+
ob_makeCommand(openbase,"' ");
|
256
|
+
|
257
|
+
if ( ob_executeCommand(openbase)) {
|
258
|
+
ob_bindString(openbase, relationship_name);
|
259
|
+
while (ob_nextRow(openbase)) {
|
260
|
+
rb_ary_push(ary, rb_str_new2(relationship_name));
|
261
|
+
}
|
262
|
+
}
|
263
|
+
|
264
|
+
return ary;
|
265
|
+
}
|
266
|
+
|
267
|
+
/* END OpenBase Schema Methods */
|
268
|
+
|
269
|
+
|
270
|
+
/*** OpenBase: Query & Transaction Methods ***/
|
271
|
+
|
272
|
+
static VALUE openbase_begin( VALUE self )
|
273
|
+
{
|
274
|
+
OpenBasePtr openbase;
|
275
|
+
|
276
|
+
GET_OPENBASE_IF_CONNECTED(self, openbase);
|
277
|
+
|
278
|
+
if ( !ob_beginTransaction(openbase) )
|
279
|
+
rb_raise(rb_cOpenBaseError, ob_serverMessage(openbase));
|
280
|
+
|
281
|
+
return Qnil;
|
282
|
+
}
|
283
|
+
|
284
|
+
static VALUE openbase_commit( VALUE self )
|
285
|
+
{
|
286
|
+
OpenBasePtr openbase;
|
287
|
+
|
288
|
+
GET_OPENBASE_IF_CONNECTED(self, openbase);
|
289
|
+
|
290
|
+
if ( !ob_commitTransaction(openbase) )
|
291
|
+
rb_raise(rb_cOpenBaseError, ob_serverMessage(openbase));
|
292
|
+
|
293
|
+
return Qnil;
|
294
|
+
}
|
295
|
+
|
296
|
+
static VALUE openbase_rollback( VALUE self )
|
297
|
+
{
|
298
|
+
OpenBasePtr openbase;
|
299
|
+
|
300
|
+
GET_OPENBASE_IF_CONNECTED(self, openbase);
|
301
|
+
|
302
|
+
if ( !ob_rollbackTransaction(openbase) )
|
303
|
+
rb_raise(rb_cOpenBaseError, ob_serverMessage(openbase));
|
304
|
+
|
305
|
+
return Qnil;
|
306
|
+
}
|
307
|
+
|
308
|
+
static VALUE openbase_transaction( VALUE self )
|
309
|
+
{
|
310
|
+
OpenBasePtr openbase;
|
311
|
+
int error_code = 0; // default will rollback
|
312
|
+
|
313
|
+
GET_OPENBASE_IF_CONNECTED(self, openbase);
|
314
|
+
|
315
|
+
if ( !ob_beginTransaction(openbase) )
|
316
|
+
rb_raise(rb_cOpenBaseError, ob_serverMessage(openbase));
|
317
|
+
|
318
|
+
rb_protect(rb_yield, self, &error_code);
|
319
|
+
if (error_code) {
|
320
|
+
ob_rollbackTransaction(openbase);
|
321
|
+
rb_exc_raise(ruby_errinfo);
|
322
|
+
} else {
|
323
|
+
ob_commitTransaction(openbase);
|
324
|
+
}
|
325
|
+
|
326
|
+
return Qnil;
|
327
|
+
}
|
328
|
+
|
329
|
+
static VALUE openbase_transaction_in_progress( VALUE self )
|
330
|
+
{
|
331
|
+
OpenBasePtr openbase;
|
332
|
+
|
333
|
+
GET_OPENBASE_IF_CONNECTED(self, openbase);
|
334
|
+
|
335
|
+
if ( ob_isTransactionInProgress(openbase) ) {
|
336
|
+
return Qtrue;
|
337
|
+
} else {
|
338
|
+
return Qfalse;
|
339
|
+
}
|
340
|
+
}
|
341
|
+
|
342
|
+
static VALUE openbase_execute( VALUE self, VALUE statement )
|
343
|
+
{
|
344
|
+
OpenBasePtr openbase;
|
345
|
+
|
346
|
+
Check_Type(statement, T_STRING);
|
347
|
+
GET_OPENBASE_IF_CONNECTED(self, openbase);
|
348
|
+
|
349
|
+
ob_makeCommand(openbase,RSTRING(statement)->ptr);
|
350
|
+
if ( !ob_executeCommand(openbase) )
|
351
|
+
rb_raise(rb_cOpenBaseError, ob_serverMessage(openbase));
|
352
|
+
|
353
|
+
return result_new(rb_cOpenBaseResult, self);
|
354
|
+
}
|
355
|
+
|
356
|
+
static VALUE openbase_unique_row_id( int argc, VALUE *argv, VALUE self )
|
357
|
+
{
|
358
|
+
OpenBasePtr openbase;
|
359
|
+
VALUE table, column;
|
360
|
+
const char *row_id;
|
361
|
+
|
362
|
+
GET_OPENBASE_IF_CONNECTED(self, openbase);
|
363
|
+
rb_scan_args(argc, argv, "11", &table, &column);
|
364
|
+
|
365
|
+
Check_Type(table, T_STRING);
|
366
|
+
if ( NIL_P(column) ) {
|
367
|
+
row_id = ob_uniqueRowIdForTable(openbase,StringValuePtr(table));
|
368
|
+
} else {
|
369
|
+
Check_Type(column, T_STRING);
|
370
|
+
row_id = ob_uniqueRowIdForTableColumn(openbase,StringValuePtr(table),StringValuePtr(column));
|
371
|
+
}
|
372
|
+
|
373
|
+
return rb_cstr_to_inum(row_id, 10, Qfalse);
|
374
|
+
}
|
375
|
+
|
376
|
+
static VALUE openbase_insert_binary( VALUE self, VALUE data )
|
377
|
+
{
|
378
|
+
OpenBasePtr openbase;
|
379
|
+
char blobKey[9]; // extra spot for the null character
|
380
|
+
|
381
|
+
Check_Type(data, T_STRING);
|
382
|
+
|
383
|
+
GET_OPENBASE_IF_CONNECTED(self, openbase);
|
384
|
+
|
385
|
+
strcpy(blobKey, ob_insertBinary(openbase,RSTRING(data)->ptr,RSTRING(data)->len) );
|
386
|
+
|
387
|
+
return rb_str_new(blobKey, 8);
|
388
|
+
}
|
389
|
+
|
390
|
+
static VALUE openbase_fetch_blob( VALUE self, VALUE blob_key )
|
391
|
+
{
|
392
|
+
OpenBasePtr openbase;
|
393
|
+
int blob_length;
|
394
|
+
|
395
|
+
Check_Type(blob_key, T_STRING);
|
396
|
+
|
397
|
+
GET_OPENBASE_IF_CONNECTED(self, openbase);
|
398
|
+
|
399
|
+
return rb_str_new2(ob_retrieveBinary(openbase,(const char *)RSTRING(blob_key)->ptr,&blob_length));
|
400
|
+
}
|
401
|
+
/* End OpenBase Query & Transaction Methods */
|
402
|
+
|
403
|
+
|
404
|
+
/*** OpenBaseResult: Construction/Destruction ***/
|
405
|
+
|
406
|
+
static void result_mark( OpenBaseResult *result )
|
407
|
+
{
|
408
|
+
rb_gc_mark(result->infos);
|
409
|
+
rb_gc_mark(result->col_names);
|
410
|
+
}
|
411
|
+
|
412
|
+
static void result_free( OpenBaseResult *result )
|
413
|
+
{
|
414
|
+
int i;
|
415
|
+
for (i = 0; i < result->col_count; i++) {
|
416
|
+
free(result->buf[i]);
|
417
|
+
}
|
418
|
+
free(result->types);
|
419
|
+
free(result->buf);
|
420
|
+
ob_deallocCursor(result->cursor);
|
421
|
+
ob_deallocConnection(result->openbase);
|
422
|
+
free(result);
|
423
|
+
}
|
424
|
+
|
425
|
+
static VALUE result_new( VALUE self, VALUE ob )
|
426
|
+
{
|
427
|
+
OpenBasePtr openbase;
|
428
|
+
OpenBaseResult *result;
|
429
|
+
int count, col_type_code, return_code, has_blobs, i;
|
430
|
+
char msg[40];
|
431
|
+
VALUE info, value, data, result_data;
|
432
|
+
char *type;
|
433
|
+
|
434
|
+
openbase = (OpenBasePtr)(RDATA(ob)->data);
|
435
|
+
result = ALLOC(OpenBaseResult);
|
436
|
+
result->rows_affected = ob_rowsAffected(openbase);
|
437
|
+
result->col_names = rb_ary_new();
|
438
|
+
result->infos = rb_ary_new();
|
439
|
+
result->rows_fetched = 0;
|
440
|
+
result->has_been_offset = 0;
|
441
|
+
result->fetch_offset = 0;
|
442
|
+
result->fetch_limit = 0;
|
443
|
+
|
444
|
+
has_blobs = 0;
|
445
|
+
|
446
|
+
result->col_count = ob_resultColumnCount(openbase);
|
447
|
+
result->types = ALLOC_N(int, result->col_count);
|
448
|
+
result->buf = ALLOC_N(void *, result->col_count);
|
449
|
+
VALUE col_names = rb_ary_new();
|
450
|
+
VALUE infos = rb_ary_new();
|
451
|
+
for (i = 0; i < result->col_count; i++) {
|
452
|
+
col_type_code = ob_resultColumnType(openbase,i);
|
453
|
+
result->types[i] = col_type_code;
|
454
|
+
switch (col_type_code) {
|
455
|
+
case OBTYPE_CHAR:
|
456
|
+
type = "char";
|
457
|
+
result->buf[i] = ALLOC_N(char, OB_CHAR_LENGTH);
|
458
|
+
ob_bindString(openbase,(char *)result->buf[i]);
|
459
|
+
break;
|
460
|
+
case OBTYPE_INT:
|
461
|
+
type = "int";
|
462
|
+
result->buf[i] = ALLOC(int);
|
463
|
+
ob_bindInt(openbase,(int *)result->buf[i]);
|
464
|
+
break;
|
465
|
+
case OBTYPE_FLOAT:
|
466
|
+
type = "float";
|
467
|
+
result->buf[i] = ALLOC(double);
|
468
|
+
ob_bindDouble(openbase,(double *)result->buf[i]);
|
469
|
+
break;
|
470
|
+
case OBTYPE_LONG:
|
471
|
+
type = "long";
|
472
|
+
result->buf[i] = ALLOC(long);
|
473
|
+
ob_bindLong(openbase,(long *)result->buf[i]);
|
474
|
+
break;
|
475
|
+
case OBTYPE_MONEY:
|
476
|
+
type = "money";
|
477
|
+
result->buf[i] = ALLOC_N(char, OB_MONEY_LENGTH);
|
478
|
+
ob_bindString(openbase,(char *)result->buf[i]);
|
479
|
+
break;
|
480
|
+
case OBTYPE_DATE:
|
481
|
+
type = "date";
|
482
|
+
result->buf[i] = ALLOC_N(char, OB_DATE_LENGTH);
|
483
|
+
ob_bindString(openbase,(char *)result->buf[i]);
|
484
|
+
break;
|
485
|
+
case OBTYPE_TIME:
|
486
|
+
type = "time";
|
487
|
+
result->buf[i] = ALLOC_N(char, OB_TIME_LENGTH);
|
488
|
+
ob_bindString(openbase,(char *)result->buf[i]);
|
489
|
+
break;
|
490
|
+
case OBTYPE_OBJECT:
|
491
|
+
type = "object";
|
492
|
+
has_blobs = 1;
|
493
|
+
result->buf[i] = ALLOC_N(char, OB_BLOB_KEY_LENGTH);
|
494
|
+
ob_bindString(openbase,(char *)result->buf[i]);
|
495
|
+
break;
|
496
|
+
case OBTYPE_DATETIME:
|
497
|
+
type = "datetime";
|
498
|
+
result->buf[i] = ALLOC_N(char, OB_DATETIME_LENGTH);
|
499
|
+
ob_bindString(openbase,(char *)result->buf[i]);
|
500
|
+
break;
|
501
|
+
case OBTYPE_LONGLONG:
|
502
|
+
type = "longlong";
|
503
|
+
result->buf[i] = ALLOC(long long);
|
504
|
+
ob_bindLongLong(openbase,(int *)result->buf[i]);
|
505
|
+
break;
|
506
|
+
case OBTYPE_BOOLEAN:
|
507
|
+
type = "boolean";
|
508
|
+
result->buf[i] = ALLOC_N(char, OB_BOOLEAN_LENGTH);
|
509
|
+
ob_bindString(openbase,(char *)result->buf[i]);
|
510
|
+
break;
|
511
|
+
case OBTYPE_BINARY:
|
512
|
+
type = "binary";
|
513
|
+
has_blobs = 1;
|
514
|
+
result->buf[i] = ALLOC_N(char, OB_BLOB_KEY_LENGTH);
|
515
|
+
ob_bindString(openbase,(char *)result->buf[i]);
|
516
|
+
break;
|
517
|
+
case OBTYPE_OBJECT_TEXT:
|
518
|
+
type = "text";
|
519
|
+
has_blobs = 1;
|
520
|
+
result->buf[i] = ALLOC_N(char, OB_BLOB_KEY_LENGTH);
|
521
|
+
ob_bindString(openbase,(char *)result->buf[i]);
|
522
|
+
break;
|
523
|
+
case OBTYPE_TIMESTAMP:
|
524
|
+
type = "timestamp";
|
525
|
+
result->buf[i] = ALLOC_N(char, OB_TIMESTAMP_LENGTH);
|
526
|
+
ob_bindString(openbase,(char *)result->buf[i]);
|
527
|
+
break;
|
528
|
+
default:
|
529
|
+
break;
|
530
|
+
}
|
531
|
+
rb_ary_push(col_names,rb_str_new2(ob_resultColumnName(openbase,i)));
|
532
|
+
info = columninfo_new(rb_cOpenBaseColumnInfo, rb_str_new2(ob_resultColumnName(openbase,i)), \
|
533
|
+
rb_str_new2(type), rb_str_new2(ob_resultTableName(openbase,i)));
|
534
|
+
rb_ary_push(infos, info);
|
535
|
+
}
|
536
|
+
|
537
|
+
result->col_names = col_names;
|
538
|
+
result->infos = infos;
|
539
|
+
result->cursor = ob_retrieveCursor(openbase);
|
540
|
+
result->openbase = ob_newConnection();
|
541
|
+
if (has_blobs) {
|
542
|
+
// Create a connection for retrieving blobs
|
543
|
+
ob_connectToDatabase( result->openbase, \
|
544
|
+
ob_databaseName(openbase), \
|
545
|
+
ob_hostName(openbase), \
|
546
|
+
ob_loginName(openbase), \
|
547
|
+
ob_password(openbase), \
|
548
|
+
"", "", \
|
549
|
+
&return_code);
|
550
|
+
}
|
551
|
+
return Data_Wrap_Struct(self, result_mark, result_free, result);
|
552
|
+
}
|
553
|
+
|
554
|
+
/* END OpenBaseResult Construction/Destruction */
|
555
|
+
|
556
|
+
|
557
|
+
#define PUSH_COLUMN(row,col_name,col_value,returnAsHash) \
|
558
|
+
if (returnAsHash) { rb_hash_aset(row,col_name,col_value); } \
|
559
|
+
else { rb_ary_push(row,col_value); }
|
560
|
+
|
561
|
+
#define PARSE(klass, value) rb_funcall(klass, rb_intern("parse"), 1, value)
|
562
|
+
|
563
|
+
static VALUE result_retrieve_binary(OpenBasePtr conn, char *blob_key, int *returned_size);
|
564
|
+
|
565
|
+
/*** OpenBaseResult: Fetching/Iteration ***/
|
566
|
+
static VALUE result_fetch( VALUE self, int returnAsHash )
|
567
|
+
{
|
568
|
+
OpenBaseResult *result;
|
569
|
+
int i;
|
570
|
+
VALUE row, col_name;
|
571
|
+
|
572
|
+
if ( returnAsHash ) {
|
573
|
+
row = rb_hash_new();
|
574
|
+
} else {
|
575
|
+
row = rb_ary_new();
|
576
|
+
}
|
577
|
+
|
578
|
+
GET_RESULT(self, result);
|
579
|
+
|
580
|
+
if (!result->has_been_offset) {
|
581
|
+
result->has_been_offset = 1;
|
582
|
+
for(i=0; i<result->fetch_offset; i++) {ob_nextCursorRow(result->cursor);}
|
583
|
+
}
|
584
|
+
|
585
|
+
|
586
|
+
if (result->fetch_limit && result->fetch_limit <= result->rows_fetched) {
|
587
|
+
return Qnil;
|
588
|
+
|
589
|
+
} else if (ob_nextCursorRow(result->cursor)) {
|
590
|
+
result->rows_fetched++;
|
591
|
+
for (i = 0; i < result->col_count; i++) {
|
592
|
+
col_name = rb_ary_entry(result->col_names, i);
|
593
|
+
if (ob_isCursorColumnNULL(result->cursor, i)) {
|
594
|
+
PUSH_COLUMN(row, col_name, Qnil, returnAsHash);
|
595
|
+
} else {
|
596
|
+
switch (result->types[i]) {
|
597
|
+
case OBTYPE_CHAR:
|
598
|
+
{
|
599
|
+
if (strlen((char *)result->buf[i]) == 0) {
|
600
|
+
PUSH_COLUMN(row, col_name, Qnil, returnAsHash);
|
601
|
+
} else {
|
602
|
+
PUSH_COLUMN(row, col_name, rb_str_new2((char *)result->buf[i]), returnAsHash);
|
603
|
+
}
|
604
|
+
break;
|
605
|
+
}
|
606
|
+
case OBTYPE_MONEY:
|
607
|
+
{
|
608
|
+
VALUE money_string = rb_tainted_str_new2((char *)result->buf[i]);
|
609
|
+
rb_funcall(money_string,rb_gsub_bang_id,2,rb_reg_new("[$,]",4,0),rb_str_new("",0));
|
610
|
+
VALUE money_value = rb_funcall(rb_cBigDecimal, rb_intern("new"), 1, money_string);
|
611
|
+
PUSH_COLUMN(row, col_name, money_value, returnAsHash);
|
612
|
+
break;
|
613
|
+
}
|
614
|
+
case OBTYPE_DATE:
|
615
|
+
{
|
616
|
+
if (strlen((char *)result->buf[i]) == 0) {
|
617
|
+
PUSH_COLUMN(row, col_name, Qnil, returnAsHash);
|
618
|
+
} else {
|
619
|
+
VALUE date_string = rb_str_new2((char *)result->buf[i]);
|
620
|
+
rb_funcall(date_string,rb_gsub_bang_id,2,rb_reg_new("\\.",2,0),rb_str_new("-",1));
|
621
|
+
PUSH_COLUMN(row, col_name, PARSE(rb_cDate,date_string), returnAsHash);
|
622
|
+
}
|
623
|
+
break;
|
624
|
+
}
|
625
|
+
case OBTYPE_TIME:
|
626
|
+
case OBTYPE_DATETIME:
|
627
|
+
case OBTYPE_TIMESTAMP:
|
628
|
+
{
|
629
|
+
PUSH_COLUMN(row, col_name, PARSE(rb_cTime,rb_str_new2((char *)result->buf[i])), returnAsHash);
|
630
|
+
break;
|
631
|
+
}
|
632
|
+
case OBTYPE_BOOLEAN:
|
633
|
+
{
|
634
|
+
VALUE boolVal;
|
635
|
+
char * boolS = (char *)result->buf[i];
|
636
|
+
if (strlen(boolS) == 0)
|
637
|
+
boolVal = Qnil;
|
638
|
+
else if (strcmp(boolS, "1") == 0)
|
639
|
+
boolVal = Qtrue;
|
640
|
+
else
|
641
|
+
boolVal = Qfalse;
|
642
|
+
PUSH_COLUMN(row, col_name, boolVal, returnAsHash);
|
643
|
+
break;
|
644
|
+
}
|
645
|
+
case OBTYPE_INT:
|
646
|
+
case OBTYPE_LONG:
|
647
|
+
{
|
648
|
+
PUSH_COLUMN(row, col_name, LONG2NUM(*(long *)result->buf[i]), returnAsHash);
|
649
|
+
break;
|
650
|
+
}
|
651
|
+
case OBTYPE_LONGLONG:
|
652
|
+
{
|
653
|
+
PUSH_COLUMN(row, col_name, LL2NUM(*(long long *)result->buf[i]), returnAsHash);
|
654
|
+
break;
|
655
|
+
}
|
656
|
+
case OBTYPE_FLOAT:
|
657
|
+
{
|
658
|
+
PUSH_COLUMN(row, col_name, rb_float_new(*(double *)result->buf[i]), returnAsHash);
|
659
|
+
break;
|
660
|
+
}
|
661
|
+
case OBTYPE_BINARY:
|
662
|
+
case OBTYPE_OBJECT:
|
663
|
+
case OBTYPE_OBJECT_TEXT:
|
664
|
+
{
|
665
|
+
int data_size;
|
666
|
+
VALUE data = result_retrieve_binary(result->openbase,(char *)result->buf[i],&data_size);
|
667
|
+
PUSH_COLUMN(row, col_name, data, returnAsHash);
|
668
|
+
break;
|
669
|
+
}
|
670
|
+
default:
|
671
|
+
rb_raise(rb_cOpenBaseError, "Unknown result column type for column '%s'", ob_cursorColumnName(result->cursor,i));
|
672
|
+
}
|
673
|
+
}
|
674
|
+
}
|
675
|
+
return row;
|
676
|
+
|
677
|
+
} else { // No More Rows
|
678
|
+
return Qnil;
|
679
|
+
}
|
680
|
+
}
|
681
|
+
|
682
|
+
|
683
|
+
void _setErrorMessage(OpenBasePtr conn, int errorCode);
|
684
|
+
static VALUE result_retrieve_binary(OpenBasePtr conn, char *blob_key, int *returned_size)
|
685
|
+
{
|
686
|
+
const char *blob_data;
|
687
|
+
|
688
|
+
prepareDictionary(conn->altConnection);
|
689
|
+
addDictionaryPair(conn->altConnection, "action", "call_getFile");
|
690
|
+
addDictionaryPair(conn->altConnection, "fileKey", blob_key);
|
691
|
+
if (!sendBuffer(conn->altConnection)){
|
692
|
+
_setErrorMessage(conn, ERR_NOSERVER);
|
693
|
+
return 0;
|
694
|
+
}
|
695
|
+
// YIELD_THREAD;
|
696
|
+
|
697
|
+
if (readResult(conn->altConnection) == 0) {
|
698
|
+
*returned_size = 0;
|
699
|
+
ob_invalidate(conn);
|
700
|
+
return Qnil; // failure
|
701
|
+
}
|
702
|
+
|
703
|
+
blob_data = resultValueForKey(conn->altConnection, "data", returned_size);
|
704
|
+
if (!blob_data) {
|
705
|
+
*returned_size = 0;
|
706
|
+
ob_invalidate(conn);
|
707
|
+
return Qnil; // failure
|
708
|
+
}
|
709
|
+
return rb_str_new(blob_data,(long int)*returned_size);
|
710
|
+
}
|
711
|
+
|
712
|
+
#define AS_ARRAY NO
|
713
|
+
#define AS_HASH YES
|
714
|
+
static VALUE result_fetch_array( VALUE self)
|
715
|
+
{
|
716
|
+
return result_fetch( self, AS_ARRAY );
|
717
|
+
}
|
718
|
+
|
719
|
+
static VALUE result_fetch_hash( VALUE self )
|
720
|
+
{
|
721
|
+
return result_fetch( self, AS_HASH );
|
722
|
+
}
|
723
|
+
|
724
|
+
static VALUE result_each( VALUE self )
|
725
|
+
{
|
726
|
+
VALUE row;
|
727
|
+
|
728
|
+
while ((row = result_fetch(self, AS_ARRAY)) != Qnil) {
|
729
|
+
rb_yield(row);
|
730
|
+
}
|
731
|
+
|
732
|
+
return self;
|
733
|
+
}
|
734
|
+
|
735
|
+
static VALUE result_each_hash( VALUE self )
|
736
|
+
{
|
737
|
+
VALUE row;
|
738
|
+
|
739
|
+
while ((row = result_fetch(self, AS_HASH)) != Qnil) {
|
740
|
+
rb_yield(row);
|
741
|
+
}
|
742
|
+
|
743
|
+
return self;
|
744
|
+
}
|
745
|
+
|
746
|
+
static VALUE result_fetch_all( VALUE self )
|
747
|
+
{
|
748
|
+
VALUE row;
|
749
|
+
VALUE all_rows = rb_ary_new();
|
750
|
+
|
751
|
+
while ((row = result_fetch(self, AS_ARRAY)) != Qnil) {
|
752
|
+
rb_ary_push(all_rows, row);
|
753
|
+
}
|
754
|
+
|
755
|
+
return all_rows;
|
756
|
+
}
|
757
|
+
#undef AS_ARRAY
|
758
|
+
#undef AS_HASH
|
759
|
+
|
760
|
+
static VALUE result_get_fetch_limit( VALUE self )
|
761
|
+
{
|
762
|
+
OpenBaseResult *result;
|
763
|
+
|
764
|
+
GET_RESULT(self, result);
|
765
|
+
|
766
|
+
return INT2FIX(result->fetch_limit);
|
767
|
+
}
|
768
|
+
static VALUE result_set_fetch_limit( VALUE self, VALUE limit )
|
769
|
+
{
|
770
|
+
OpenBaseResult *result;
|
771
|
+
|
772
|
+
GET_RESULT(self, result);
|
773
|
+
|
774
|
+
result->fetch_limit = FIX2INT(limit);
|
775
|
+
return Qtrue;
|
776
|
+
}
|
777
|
+
|
778
|
+
static VALUE result_get_fetch_offset( VALUE self )
|
779
|
+
{
|
780
|
+
OpenBaseResult *result;
|
781
|
+
|
782
|
+
GET_RESULT(self, result);
|
783
|
+
|
784
|
+
return INT2FIX(result->fetch_offset);
|
785
|
+
}
|
786
|
+
static VALUE result_set_fetch_offset( VALUE self, VALUE offset )
|
787
|
+
{
|
788
|
+
OpenBaseResult *result;
|
789
|
+
|
790
|
+
GET_RESULT(self, result);
|
791
|
+
|
792
|
+
result->fetch_offset = FIX2INT(offset);
|
793
|
+
return Qtrue;
|
794
|
+
}
|
795
|
+
/* END OpenBaseResult Fetching/Iteration */
|
796
|
+
|
797
|
+
|
798
|
+
/*** OpenBaseResult: Column Information ***/
|
799
|
+
static VALUE result_column_count( VALUE self )
|
800
|
+
{
|
801
|
+
OpenBaseResult *result;
|
802
|
+
|
803
|
+
GET_RESULT(self, result);
|
804
|
+
|
805
|
+
return INT2FIX(result->col_count);
|
806
|
+
}
|
807
|
+
|
808
|
+
static VALUE result_rows_affected( VALUE self )
|
809
|
+
{
|
810
|
+
OpenBaseResult *result;
|
811
|
+
|
812
|
+
GET_RESULT(self, result);
|
813
|
+
|
814
|
+
return INT2FIX(result->rows_affected);
|
815
|
+
}
|
816
|
+
|
817
|
+
static VALUE result_column_infos( VALUE self )
|
818
|
+
{
|
819
|
+
OpenBaseResult *result;
|
820
|
+
GET_RESULT(self, result);
|
821
|
+
return result->infos;
|
822
|
+
}
|
823
|
+
|
824
|
+
/* END OpenBaseResult Column Information */
|
825
|
+
|
826
|
+
|
827
|
+
/*** OpenBaseColumnInfo Construction/Destruction ***/
|
828
|
+
|
829
|
+
static void columninfo_mark( OpenBaseColumnInfo *info )
|
830
|
+
{
|
831
|
+
rb_gc_mark(info->name);
|
832
|
+
rb_gc_mark(info->type);
|
833
|
+
rb_gc_mark(info->table);
|
834
|
+
}
|
835
|
+
|
836
|
+
static void columninfo_free( OpenBaseColumnInfo *info )
|
837
|
+
{
|
838
|
+
free(info);
|
839
|
+
}
|
840
|
+
|
841
|
+
static VALUE columninfo_new( VALUE self, VALUE name, VALUE type, VALUE table )
|
842
|
+
{
|
843
|
+
OpenBaseColumnInfo *info;
|
844
|
+
info = ALLOC(OpenBaseColumnInfo);
|
845
|
+
|
846
|
+
Check_Type(name, T_STRING);
|
847
|
+
Check_Type(type, T_STRING);
|
848
|
+
Check_Type(table, T_STRING);
|
849
|
+
info->name = name;
|
850
|
+
info->type = type;
|
851
|
+
info->table = table;
|
852
|
+
|
853
|
+
return Data_Wrap_Struct(self, columninfo_mark, columninfo_free, info);
|
854
|
+
}
|
855
|
+
|
856
|
+
/* END OpenBaseColumnInfo Construction/Destruction */
|
857
|
+
|
858
|
+
|
859
|
+
/*** OpenBaseColumnInfo: Getter Methods ***/
|
860
|
+
|
861
|
+
static VALUE columninfo_name( VALUE self )
|
862
|
+
{
|
863
|
+
OpenBaseColumnInfo *info;
|
864
|
+
GET_INFO(self, info);
|
865
|
+
return info->name;
|
866
|
+
}
|
867
|
+
|
868
|
+
|
869
|
+
static VALUE columninfo_type( VALUE self )
|
870
|
+
{
|
871
|
+
OpenBaseColumnInfo *info;
|
872
|
+
GET_INFO(self, info);
|
873
|
+
return info->type;
|
874
|
+
}
|
875
|
+
|
876
|
+
|
877
|
+
static VALUE columninfo_table( VALUE self )
|
878
|
+
{
|
879
|
+
OpenBaseColumnInfo *info;
|
880
|
+
GET_INFO(self, info);
|
881
|
+
return info->table;
|
882
|
+
}
|
883
|
+
|
884
|
+
/* END OpenBaseColumInfo Getter Methods */
|
885
|
+
|
886
|
+
|
887
|
+
|
888
|
+
/*********************** OpenBase Library Interface *************************/
|
889
|
+
// This typedef and macro address a complaint by the compiler
|
890
|
+
// concerning the callbacks passed to rb_define_method.
|
891
|
+
//typedef VALUE (ruby_method)(...);
|
892
|
+
//#define CALLBACK(method_name) (ruby_method*)&method_name
|
893
|
+
#define CALLBACK(method_name) method_name
|
894
|
+
|
895
|
+
void Init_openbase() {
|
896
|
+
const int VARIABLE_C_ARRAY = -1;
|
897
|
+
const int VARIABLE_RB_ARRAY = -2;
|
898
|
+
|
899
|
+
rb_gsub_bang_id = rb_intern("gsub!");
|
900
|
+
rb_date_regex = rb_reg_new("\\.",2,0);
|
901
|
+
rb_replacement_str = rb_str_new("-",1);
|
902
|
+
|
903
|
+
rb_require("date");
|
904
|
+
rb_require("time");
|
905
|
+
rb_require("bigdecimal");
|
906
|
+
rb_cDate = rb_const_get(rb_cObject, rb_intern("Date"));
|
907
|
+
rb_cBigDecimal = rb_const_get(rb_cObject, rb_intern("BigDecimal"));
|
908
|
+
|
909
|
+
// OpenBaseError: Simple Error Object
|
910
|
+
rb_cOpenBaseError = rb_define_class("OpenBaseError", rb_eStandardError);
|
911
|
+
|
912
|
+
|
913
|
+
// OpenBase: Class Definition, Construction, & Destruction
|
914
|
+
rb_cOpenBase = rb_define_class("OpenBase", rb_cObject);
|
915
|
+
rb_define_alloc_func(rb_cOpenBase, openbase_alloc);
|
916
|
+
rb_define_method(rb_cOpenBase, "initialize", CALLBACK(openbase_initialize), VARIABLE_C_ARRAY);
|
917
|
+
|
918
|
+
// OpenBase: Connection Related Methods
|
919
|
+
rb_define_method(rb_cOpenBase, "connect", CALLBACK(openbase_connect), VARIABLE_C_ARRAY);
|
920
|
+
rb_define_method(rb_cOpenBase, "connected?", CALLBACK(openbase_isConnected), 0);
|
921
|
+
rb_define_alias(rb_cOpenBase, "connect?", "connected?");
|
922
|
+
rb_define_method(rb_cOpenBase, "invalidate", CALLBACK(openbase_invalidate), 0);
|
923
|
+
rb_define_alias(rb_cOpenBase, "disconnect", "invalidate");
|
924
|
+
rb_define_method(rb_cOpenBase, "database", CALLBACK(openbase_database), 0);
|
925
|
+
rb_define_method(rb_cOpenBase, "host", CALLBACK(openbase_host), 0);
|
926
|
+
rb_define_method(rb_cOpenBase, "login", CALLBACK(openbase_login), 0);
|
927
|
+
rb_define_method(rb_cOpenBase, "password", CALLBACK(openbase_password), 0);
|
928
|
+
rb_define_method(rb_cOpenBase, "encoding", CALLBACK(openbase_encoding), 0);
|
929
|
+
|
930
|
+
// OpenBase: Schema Related Methods
|
931
|
+
rb_define_method(rb_cOpenBase, "tables", CALLBACK(openbase_tables), 0);
|
932
|
+
rb_define_method(rb_cOpenBase, "columns", CALLBACK(openbase_columns), 1);
|
933
|
+
rb_define_method(rb_cOpenBase, "relationships", CALLBACK(openbase_relationships), 1);
|
934
|
+
|
935
|
+
// OpenBase: Query & Transaction Related Methods
|
936
|
+
rb_define_method(rb_cOpenBase, "begin", CALLBACK(openbase_begin), 0);
|
937
|
+
rb_define_method(rb_cOpenBase, "commit", CALLBACK(openbase_commit), 0);
|
938
|
+
rb_define_method(rb_cOpenBase, "rollback", CALLBACK(openbase_rollback), 0);
|
939
|
+
rb_define_method(rb_cOpenBase, "transaction?", CALLBACK(openbase_transaction_in_progress), 0);
|
940
|
+
rb_define_method(rb_cOpenBase, "transaction", CALLBACK(openbase_transaction), 0);
|
941
|
+
rb_define_method(rb_cOpenBase, "execute", CALLBACK(openbase_execute), 1);
|
942
|
+
rb_define_method(rb_cOpenBase, "unique_row_id", CALLBACK(openbase_unique_row_id), VARIABLE_C_ARRAY);
|
943
|
+
rb_define_method(rb_cOpenBase, "insert_binary", CALLBACK(openbase_insert_binary), 1);
|
944
|
+
rb_define_method(rb_cOpenBase, "fetch_blob", CALLBACK(openbase_fetch_blob),1);
|
945
|
+
|
946
|
+
|
947
|
+
// OpenBaseResult: Class Definition, Construction, & Destruction
|
948
|
+
rb_cOpenBaseResult = rb_define_class("OpenBaseResult", rb_cObject);
|
949
|
+
rb_define_singleton_method(rb_cOpenBaseResult, "new", CALLBACK(result_new), 1);
|
950
|
+
rb_include_module(rb_cOpenBaseResult, rb_mEnumerable); // Array behavior
|
951
|
+
|
952
|
+
// OpenBaseResult: Attributes
|
953
|
+
rb_define_method(rb_cOpenBaseResult, "fetch_limit", CALLBACK(result_get_fetch_limit), 0);
|
954
|
+
rb_define_method(rb_cOpenBaseResult, "fetch_limit=", CALLBACK(result_set_fetch_limit), 1);
|
955
|
+
rb_define_method(rb_cOpenBaseResult, "fetch_offset", CALLBACK(result_get_fetch_offset), 0);
|
956
|
+
rb_define_method(rb_cOpenBaseResult, "fetch_offset=", CALLBACK(result_set_fetch_offset), 1);
|
957
|
+
|
958
|
+
// OpenBaseResult: Fetching, Iteration
|
959
|
+
rb_define_method(rb_cOpenBaseResult, "fetch", CALLBACK(result_fetch_array), 0);
|
960
|
+
rb_define_method(rb_cOpenBaseResult, "fetch_hash", CALLBACK(result_fetch_hash), 0);
|
961
|
+
rb_define_method(rb_cOpenBaseResult, "each", CALLBACK(result_each), 0);
|
962
|
+
rb_define_method(rb_cOpenBaseResult, "each_hash", CALLBACK(result_each_hash), 0);
|
963
|
+
rb_define_method(rb_cOpenBaseResult, "fetch_all", CALLBACK(result_fetch_all), 0);
|
964
|
+
|
965
|
+
// OpenBaseResult: Column Information
|
966
|
+
rb_define_method(rb_cOpenBaseResult, "column_count", CALLBACK(result_column_count), 0);
|
967
|
+
rb_define_method(rb_cOpenBaseResult, "rows_affected", CALLBACK(result_rows_affected), 0);
|
968
|
+
rb_define_method(rb_cOpenBaseResult, "column_infos", CALLBACK(result_column_infos), 0);
|
969
|
+
|
970
|
+
|
971
|
+
// OpenBaseColumnInfo: Class Definition, Construction & Destruction
|
972
|
+
rb_cOpenBaseColumnInfo = rb_define_class("OpenBaseColumnInfo", rb_cObject);
|
973
|
+
rb_define_singleton_method(rb_cOpenBaseColumnInfo, "new", CALLBACK(columninfo_new), 3);
|
974
|
+
|
975
|
+
// OpenBaseColumnInfo: Getter Methods
|
976
|
+
rb_define_method(rb_cOpenBaseColumnInfo, "name", CALLBACK(columninfo_name), 0);
|
977
|
+
rb_define_method(rb_cOpenBaseColumnInfo, "type", CALLBACK(columninfo_type), 0);
|
978
|
+
rb_define_method(rb_cOpenBaseColumnInfo, "table", CALLBACK(columninfo_table), 0);
|
979
|
+
|
980
|
+
}
|