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/CHANGELOG +6 -0
- data/Manifest +0 -1
- data/Rakefile +1 -1
- data/ext/AddUser.c +217 -248
- data/ext/AddUser.h +3 -3
- data/ext/Backup.c +337 -404
- data/ext/Backup.h +3 -3
- data/ext/Blob.c +197 -248
- data/ext/Blob.h +30 -31
- data/ext/Common.c +17 -18
- data/ext/Common.h +10 -10
- data/ext/Connection.c +413 -487
- data/ext/Connection.h +18 -19
- data/ext/DataArea.c +172 -189
- data/ext/DataArea.h +11 -11
- data/ext/Database.c +198 -238
- data/ext/Database.h +16 -17
- data/ext/FireRuby.c +118 -142
- data/ext/FireRuby.h +17 -17
- data/ext/FireRubyException.c +68 -138
- data/ext/FireRubyException.h +14 -21
- data/ext/Generator.c +296 -377
- data/ext/Generator.h +17 -18
- data/ext/RemoveUser.c +91 -102
- data/ext/RemoveUser.h +3 -3
- data/ext/Restore.c +353 -423
- data/ext/Restore.h +3 -3
- data/ext/ResultSet.c +423 -456
- data/ext/ResultSet.h +26 -27
- data/ext/Row.c +505 -568
- data/ext/Row.h +27 -28
- data/ext/ServiceManager.c +143 -164
- data/ext/ServiceManager.h +17 -18
- data/ext/Services.c +58 -67
- data/ext/Services.h +3 -3
- data/ext/Statement.c +388 -449
- data/ext/Statement.h +30 -31
- data/ext/Transaction.c +374 -448
- data/ext/Transaction.h +17 -18
- data/ext/TypeMap.c +654 -774
- data/ext/TypeMap.h +17 -17
- data/ext/rfbint.h +3 -3
- data/lib/active_record/connection_adapters/rubyfb_adapter.rb +1 -1
- data/lib/rubyfb_lib.so +0 -0
- data/lib/src.rb +33 -0
- data/rubyfb.gemspec +3 -3
- data/test/ResultSetTest.rb +13 -0
- data/test/RowTest.rb +16 -0
- metadata +4 -5
- data/test/UnitTest.rb +0 -65
data/ext/Generator.c
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/*------------------------------------------------------------------------------
|
2
2
|
* Generator.c
|
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
|
@@ -61,24 +61,20 @@ VALUE cGenerator;
|
|
61
61
|
* @return A reference to the newly allocated Generator object.
|
62
62
|
*
|
63
63
|
*/
|
64
|
-
static VALUE allocateGenerator(VALUE klass)
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
"Memory allocation failure allocating a generator.");
|
79
|
-
}
|
80
|
-
|
81
|
-
return(instance);
|
64
|
+
static VALUE allocateGenerator(VALUE klass) {
|
65
|
+
VALUE instance = Qnil;
|
66
|
+
GeneratorHandle *generator = ALLOC(GeneratorHandle);
|
67
|
+
|
68
|
+
if(generator != NULL) {
|
69
|
+
generator->connection = NULL;
|
70
|
+
instance = Data_Wrap_Struct(klass, NULL, generatorFree,
|
71
|
+
generator);
|
72
|
+
} else {
|
73
|
+
rb_raise(rb_eNoMemError,
|
74
|
+
"Memory allocation failure allocating a generator.");
|
75
|
+
}
|
76
|
+
|
77
|
+
return(instance);
|
82
78
|
}
|
83
79
|
|
84
80
|
|
@@ -96,30 +92,27 @@ static VALUE allocateGenerator(VALUE klass)
|
|
96
92
|
*/
|
97
93
|
static VALUE initializeGenerator(VALUE self,
|
98
94
|
VALUE name,
|
99
|
-
VALUE connection)
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
generator->connection = &handle->handle;
|
121
|
-
|
122
|
-
return(self);
|
95
|
+
VALUE connection) {
|
96
|
+
GeneratorHandle *generator = NULL;
|
97
|
+
ConnectionHandle *handle = NULL;
|
98
|
+
|
99
|
+
if(TYPE(name) != T_STRING) {
|
100
|
+
rb_fireruby_raise(NULL, "Invalid generator name specified.");
|
101
|
+
}
|
102
|
+
|
103
|
+
if(TYPE(connection) != T_DATA &&
|
104
|
+
RDATA(connection)->dfree != (RUBY_DATA_FUNC)connectionFree) {
|
105
|
+
rb_fireruby_raise(NULL, "Invalid connection specified for generator.");
|
106
|
+
}
|
107
|
+
|
108
|
+
rb_iv_set(self, "@name", name);
|
109
|
+
rb_iv_set(self, "@connection", connection);
|
110
|
+
|
111
|
+
Data_Get_Struct(connection, ConnectionHandle, handle);
|
112
|
+
Data_Get_Struct(self, GeneratorHandle, generator);
|
113
|
+
generator->connection = &handle->handle;
|
114
|
+
|
115
|
+
return(self);
|
123
116
|
}
|
124
117
|
|
125
118
|
|
@@ -132,9 +125,8 @@ static VALUE initializeGenerator(VALUE self,
|
|
132
125
|
* @return A reference to a String containing the Generator name.
|
133
126
|
*
|
134
127
|
*/
|
135
|
-
static VALUE getGeneratorName(VALUE self)
|
136
|
-
|
137
|
-
return(rb_iv_get(self, "@name"));
|
128
|
+
static VALUE getGeneratorName(VALUE self) {
|
129
|
+
return(rb_iv_get(self, "@name"));
|
138
130
|
}
|
139
131
|
|
140
132
|
|
@@ -148,9 +140,8 @@ static VALUE getGeneratorName(VALUE self)
|
|
148
140
|
* @return A reference to the Connection object for the generator.
|
149
141
|
*
|
150
142
|
*/
|
151
|
-
static VALUE getGeneratorConnection(VALUE self)
|
152
|
-
|
153
|
-
return(rb_iv_get(self, "@connection"));
|
143
|
+
static VALUE getGeneratorConnection(VALUE self) {
|
144
|
+
return(rb_iv_get(self, "@connection"));
|
154
145
|
}
|
155
146
|
|
156
147
|
|
@@ -162,17 +153,16 @@ static VALUE getGeneratorConnection(VALUE self)
|
|
162
153
|
* @return A reference to the last value retrieved from the generator.
|
163
154
|
*
|
164
155
|
*/
|
165
|
-
static VALUE getLastGeneratorValue(VALUE self)
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
int32_t number = 0;
|
156
|
+
static VALUE getLastGeneratorValue(VALUE self) {
|
157
|
+
VALUE name = rb_iv_get(self, "@name");
|
158
|
+
GeneratorHandle *generator = NULL;
|
159
|
+
int32_t number = 0;
|
170
160
|
|
171
|
-
|
161
|
+
Data_Get_Struct(self, GeneratorHandle, generator);
|
172
162
|
|
173
|
-
|
163
|
+
number = getGeneratorValue(StringValuePtr(name), 0, generator->connection);
|
174
164
|
|
175
|
-
|
165
|
+
return(INT2NUM(number));
|
176
166
|
}
|
177
167
|
|
178
168
|
|
@@ -186,24 +176,22 @@ static VALUE getLastGeneratorValue(VALUE self)
|
|
186
176
|
* @return A reference to an integer containing the next generator value.
|
187
177
|
*
|
188
178
|
*/
|
189
|
-
static VALUE getNextGeneratorValue(VALUE self, VALUE step)
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
int32_t number = 0;
|
179
|
+
static VALUE getNextGeneratorValue(VALUE self, VALUE step) {
|
180
|
+
VALUE name = rb_iv_get(self, "@name");
|
181
|
+
GeneratorHandle *generator = NULL;
|
182
|
+
int32_t number = 0;
|
194
183
|
|
195
|
-
|
184
|
+
Data_Get_Struct(self, GeneratorHandle, generator);
|
196
185
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
}
|
186
|
+
/* Check the step type. */
|
187
|
+
if(TYPE(step) != T_FIXNUM) {
|
188
|
+
rb_fireruby_raise(NULL, "Invalid generator step value.");
|
189
|
+
}
|
202
190
|
|
203
|
-
|
204
|
-
|
191
|
+
number = getGeneratorValue(StringValuePtr(name), FIX2INT(step),
|
192
|
+
generator->connection);
|
205
193
|
|
206
|
-
|
194
|
+
return(INT2NUM(number));
|
207
195
|
}
|
208
196
|
|
209
197
|
|
@@ -215,18 +203,17 @@ static VALUE getNextGeneratorValue(VALUE self, VALUE step)
|
|
215
203
|
* @return A reference to the Generator object dropped.
|
216
204
|
*
|
217
205
|
*/
|
218
|
-
static VALUE dropGenerator(VALUE self)
|
219
|
-
|
220
|
-
|
221
|
-
VALUE name;
|
206
|
+
static VALUE dropGenerator(VALUE self) {
|
207
|
+
GeneratorHandle *generator = NULL;
|
208
|
+
VALUE name;
|
222
209
|
|
223
|
-
|
224
|
-
|
210
|
+
Data_Get_Struct(self, GeneratorHandle, generator);
|
211
|
+
name = rb_iv_get(self, "@name");
|
225
212
|
|
226
|
-
|
227
|
-
|
213
|
+
/* Drop the generator. */
|
214
|
+
deleteGenerator(StringValuePtr(name), generator->connection);
|
228
215
|
|
229
|
-
|
216
|
+
return(self);
|
230
217
|
}
|
231
218
|
|
232
219
|
|
@@ -243,30 +230,26 @@ static VALUE dropGenerator(VALUE self)
|
|
243
230
|
* otherwise.
|
244
231
|
*
|
245
232
|
*/
|
246
|
-
static VALUE doesGeneratorExist(VALUE klass, VALUE name, VALUE connection)
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
exists = Qtrue;
|
267
|
-
}
|
268
|
-
|
269
|
-
return(exists);
|
233
|
+
static VALUE doesGeneratorExist(VALUE klass, VALUE name, VALUE connection) {
|
234
|
+
VALUE exists = Qfalse;
|
235
|
+
ConnectionHandle *handle = NULL;
|
236
|
+
|
237
|
+
if(TYPE(connection) != T_DATA ||
|
238
|
+
RDATA(connection)->dfree != (RUBY_DATA_FUNC)connectionFree) {
|
239
|
+
rb_fireruby_raise(NULL, "Invalid connection specified.");
|
240
|
+
}
|
241
|
+
|
242
|
+
Data_Get_Struct(connection, ConnectionHandle, handle);
|
243
|
+
|
244
|
+
if(handle->handle == 0) {
|
245
|
+
rb_fireruby_raise(NULL, "Connection is closed.");
|
246
|
+
}
|
247
|
+
|
248
|
+
if(checkForGenerator(StringValuePtr(name), &handle->handle)) {
|
249
|
+
exists = Qtrue;
|
250
|
+
}
|
251
|
+
|
252
|
+
return(exists);
|
270
253
|
}
|
271
254
|
|
272
255
|
|
@@ -284,36 +267,30 @@ static VALUE doesGeneratorExist(VALUE klass, VALUE name, VALUE connection)
|
|
284
267
|
* @return A reference to a Generator object.
|
285
268
|
*
|
286
269
|
*/
|
287
|
-
static VALUE createGenerator(VALUE klass, VALUE name, VALUE connection)
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
{
|
312
|
-
rb_fireruby_raise(NULL,
|
313
|
-
"Closed connection specified for generator creation.");
|
314
|
-
}
|
315
|
-
|
316
|
-
return(result);
|
270
|
+
static VALUE createGenerator(VALUE klass, VALUE name, VALUE connection) {
|
271
|
+
VALUE result = Qnil;
|
272
|
+
ConnectionHandle *handle = NULL;
|
273
|
+
|
274
|
+
if(TYPE(name) != T_STRING) {
|
275
|
+
rb_fireruby_raise(NULL, "Invalid generator name specified.");
|
276
|
+
}
|
277
|
+
|
278
|
+
if(TYPE(connection) != T_DATA &&
|
279
|
+
RDATA(connection)->dfree != (RUBY_DATA_FUNC)connectionFree) {
|
280
|
+
rb_fireruby_raise(NULL,
|
281
|
+
"Invalid connection specified for generator creation.");
|
282
|
+
}
|
283
|
+
|
284
|
+
Data_Get_Struct(connection, ConnectionHandle, handle);
|
285
|
+
if(handle->handle != 0) {
|
286
|
+
installGenerator(StringValuePtr(name), &handle->handle);
|
287
|
+
result = rb_generator_new(name, connection);
|
288
|
+
} else {
|
289
|
+
rb_fireruby_raise(NULL,
|
290
|
+
"Closed connection specified for generator creation.");
|
291
|
+
}
|
292
|
+
|
293
|
+
return(result);
|
317
294
|
}
|
318
295
|
|
319
296
|
|
@@ -329,83 +306,65 @@ static VALUE createGenerator(VALUE klass, VALUE name, VALUE connection)
|
|
329
306
|
* exist or -1 if there was an error.
|
330
307
|
*
|
331
308
|
*/
|
332
|
-
int checkForGenerator(const char *name, isc_db_handle *connection)
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
{
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
{
|
366
|
-
int32_t count = *((long *)da->sqlvar->sqldata);
|
367
|
-
|
368
|
-
result = (count > 0 ? 1 : 0);
|
369
|
-
}
|
370
|
-
else
|
371
|
-
{
|
372
|
-
rb_fireruby_raise(status,
|
373
|
-
"Error checking for generator.");
|
374
|
-
}
|
375
|
-
}
|
376
|
-
else
|
377
|
-
{
|
378
|
-
rb_fireruby_raise(status,
|
379
|
-
"Error checking for generator.");
|
380
|
-
}
|
381
|
-
}
|
382
|
-
else
|
383
|
-
{
|
384
|
-
rb_fireruby_raise(status, "Error checking for generator.");
|
309
|
+
int checkForGenerator(const char *name, isc_db_handle *connection) {
|
310
|
+
int result = -1;
|
311
|
+
isc_stmt_handle statement = 0;
|
312
|
+
ISC_STATUS status[ISC_STATUS_LENGTH];
|
313
|
+
|
314
|
+
if(isc_dsql_allocate_statement(status, connection, &statement) == 0) {
|
315
|
+
isc_tr_handle transaction = 0;
|
316
|
+
|
317
|
+
if(isc_start_transaction(status, &transaction, 1, connection, 0,
|
318
|
+
NULL) == 0) {
|
319
|
+
XSQLDA *da = (XSQLDA *)ALLOC_N(char, XSQLDA_LENGTH(1));
|
320
|
+
|
321
|
+
if(da != NULL) {
|
322
|
+
char sql[100];
|
323
|
+
|
324
|
+
da->version = SQLDA_VERSION1;
|
325
|
+
da->sqln = 1;
|
326
|
+
sprintf(sql, "SELECT COUNT(*) FROM %sS WHERE %s_NAME = UPPER('%s')",
|
327
|
+
"RDB$GENERATOR", "RDB$GENERATOR", name);
|
328
|
+
if(isc_dsql_prepare(status, &transaction, &statement, strlen(sql),
|
329
|
+
sql, 3, da) == 0) {
|
330
|
+
/* Prepare the XSQLDA and provide it with data room. */
|
331
|
+
allocateOutXSQLDA(da->sqld, &statement, 3);
|
332
|
+
prepareDataArea(da);
|
333
|
+
if(isc_dsql_execute(status, &transaction, &statement,
|
334
|
+
3, da) == 0) {
|
335
|
+
if(isc_dsql_fetch(status, &statement, 3, da) == 0) {
|
336
|
+
int32_t count = *((long *)da->sqlvar->sqldata);
|
337
|
+
|
338
|
+
result = (count > 0 ? 1 : 0);
|
339
|
+
} else {
|
340
|
+
rb_fireruby_raise(status,
|
341
|
+
"Error checking for generator.");
|
385
342
|
}
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
}
|
343
|
+
} else {
|
344
|
+
rb_fireruby_raise(status,
|
345
|
+
"Error checking for generator.");
|
346
|
+
}
|
347
|
+
} else {
|
348
|
+
rb_fireruby_raise(status, "Error checking for generator.");
|
349
|
+
}
|
350
|
+
|
351
|
+
releaseDataArea(da);
|
352
|
+
} else {
|
353
|
+
rb_raise(rb_eNoMemError, "Memory allocation failure checking " \
|
354
|
+
"generator existence.");
|
399
355
|
}
|
400
|
-
|
401
|
-
{
|
402
|
-
|
356
|
+
|
357
|
+
if(transaction != 0) {
|
358
|
+
isc_commit_transaction(status, &transaction);
|
403
359
|
}
|
360
|
+
} else {
|
361
|
+
rb_fireruby_raise(status, "Error checking for generator.");
|
362
|
+
}
|
404
363
|
|
405
|
-
|
406
|
-
|
364
|
+
isc_dsql_free_statement(status, &statement, DSQL_drop);
|
365
|
+
}
|
407
366
|
|
408
|
-
|
367
|
+
return(result);
|
409
368
|
}
|
410
369
|
|
411
370
|
|
@@ -420,54 +379,42 @@ int checkForGenerator(const char *name, isc_db_handle *connection)
|
|
420
379
|
* @return Returns 0 if the generator was created or -1 if there was an error.
|
421
380
|
*
|
422
381
|
*/
|
423
|
-
int installGenerator(const char *name, isc_db_handle *connection)
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
}
|
447
|
-
else
|
448
|
-
{
|
449
|
-
rb_fireruby_raise(status, "Error creating generator.");
|
450
|
-
}
|
451
|
-
}
|
452
|
-
else
|
453
|
-
{
|
454
|
-
rb_fireruby_raise(status, "Error creating generator.");
|
455
|
-
}
|
456
|
-
|
457
|
-
if(transaction != 0)
|
458
|
-
{
|
459
|
-
isc_commit_transaction(status, &transaction);
|
460
|
-
}
|
382
|
+
int installGenerator(const char *name, isc_db_handle *connection) {
|
383
|
+
int result = -1;
|
384
|
+
isc_stmt_handle statement = 0;
|
385
|
+
ISC_STATUS status[ISC_STATUS_LENGTH];
|
386
|
+
|
387
|
+
if(isc_dsql_allocate_statement(status, connection, &statement) == 0) {
|
388
|
+
isc_tr_handle transaction = 0;
|
389
|
+
|
390
|
+
if(isc_start_transaction(status, &transaction, 1, connection, 0,
|
391
|
+
NULL) == 0) {
|
392
|
+
char sql[100];
|
393
|
+
|
394
|
+
sprintf(sql, "CREATE GENERATOR %s", name);
|
395
|
+
if(isc_dsql_prepare(status, &transaction, &statement, strlen(sql),
|
396
|
+
sql, 3, NULL) == 0) {
|
397
|
+
if(isc_dsql_execute(status, &transaction, &statement,
|
398
|
+
3, NULL) == 0) {
|
399
|
+
result = 0;
|
400
|
+
} else {
|
401
|
+
rb_fireruby_raise(status, "Error creating generator.");
|
402
|
+
}
|
403
|
+
} else {
|
404
|
+
rb_fireruby_raise(status, "Error creating generator.");
|
461
405
|
}
|
462
|
-
|
463
|
-
{
|
464
|
-
|
406
|
+
|
407
|
+
if(transaction != 0) {
|
408
|
+
isc_commit_transaction(status, &transaction);
|
465
409
|
}
|
410
|
+
} else {
|
411
|
+
rb_fireruby_raise(status, "Error creating generator.");
|
412
|
+
}
|
466
413
|
|
467
|
-
|
468
|
-
|
414
|
+
isc_dsql_free_statement(status, &statement, DSQL_drop);
|
415
|
+
}
|
469
416
|
|
470
|
-
|
417
|
+
return(result);
|
471
418
|
}
|
472
419
|
|
473
420
|
|
@@ -482,54 +429,42 @@ int installGenerator(const char *name, isc_db_handle *connection)
|
|
482
429
|
* @return Returns 0 if the generator was dropped or -1 if there was an error.
|
483
430
|
*
|
484
431
|
*/
|
485
|
-
int deleteGenerator(const char *name, isc_db_handle *connection)
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
}
|
509
|
-
else
|
510
|
-
{
|
511
|
-
rb_fireruby_raise(status, "Error dropping generator.");
|
512
|
-
}
|
513
|
-
}
|
514
|
-
else
|
515
|
-
{
|
516
|
-
rb_fireruby_raise(status, "Error dropping generator.");
|
517
|
-
}
|
518
|
-
|
519
|
-
if(transaction != 0)
|
520
|
-
{
|
521
|
-
isc_commit_transaction(status, &transaction);
|
522
|
-
}
|
432
|
+
int deleteGenerator(const char *name, isc_db_handle *connection) {
|
433
|
+
int result = -1;
|
434
|
+
isc_stmt_handle statement = 0;
|
435
|
+
ISC_STATUS status[ISC_STATUS_LENGTH];
|
436
|
+
|
437
|
+
if(isc_dsql_allocate_statement(status, connection, &statement) == 0) {
|
438
|
+
isc_tr_handle transaction = 0;
|
439
|
+
|
440
|
+
if(isc_start_transaction(status, &transaction, 1, connection, 0,
|
441
|
+
NULL) == 0) {
|
442
|
+
char sql[100];
|
443
|
+
|
444
|
+
sprintf(sql, "DROP GENERATOR %s", name);
|
445
|
+
if(isc_dsql_prepare(status, &transaction, &statement, strlen(sql),
|
446
|
+
sql, 3, NULL) == 0) {
|
447
|
+
if(isc_dsql_execute(status, &transaction, &statement,
|
448
|
+
3, NULL) == 0) {
|
449
|
+
result = 0;
|
450
|
+
} else {
|
451
|
+
rb_fireruby_raise(status, "Error dropping generator.");
|
452
|
+
}
|
453
|
+
} else {
|
454
|
+
rb_fireruby_raise(status, "Error dropping generator.");
|
523
455
|
}
|
524
|
-
|
525
|
-
{
|
526
|
-
|
456
|
+
|
457
|
+
if(transaction != 0) {
|
458
|
+
isc_commit_transaction(status, &transaction);
|
527
459
|
}
|
460
|
+
} else {
|
461
|
+
rb_fireruby_raise(status, "Error dropping generator.");
|
462
|
+
}
|
528
463
|
|
529
|
-
|
530
|
-
|
464
|
+
isc_dsql_free_statement(status, &statement, DSQL_drop);
|
465
|
+
}
|
531
466
|
|
532
|
-
|
467
|
+
return(result);
|
533
468
|
}
|
534
469
|
|
535
470
|
|
@@ -541,29 +476,25 @@ int deleteGenerator(const char *name, isc_db_handle *connection)
|
|
541
476
|
* from a generator.
|
542
477
|
*
|
543
478
|
*/
|
544
|
-
XSQLDA *createStorage(void)
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
"Memory allocation failure allocating generator storage space.");
|
564
|
-
}
|
565
|
-
|
566
|
-
return(da);
|
479
|
+
XSQLDA *createStorage(void) {
|
480
|
+
XSQLDA *da = (XSQLDA *)ALLOC_N(char, XSQLDA_LENGTH(1));
|
481
|
+
|
482
|
+
if(da != NULL) {
|
483
|
+
XSQLVAR *var = da->sqlvar;
|
484
|
+
|
485
|
+
da->version = SQLDA_VERSION1;
|
486
|
+
da->sqln = 1;
|
487
|
+
da->sqld = 1;
|
488
|
+
var->sqltype = SQL_LONG;
|
489
|
+
var->sqlscale = 0;
|
490
|
+
var->sqllen = sizeof(long);
|
491
|
+
prepareDataArea(da);
|
492
|
+
} else {
|
493
|
+
rb_raise(rb_eNoMemError,
|
494
|
+
"Memory allocation failure allocating generator storage space.");
|
495
|
+
}
|
496
|
+
|
497
|
+
return(da);
|
567
498
|
}
|
568
499
|
|
569
500
|
|
@@ -579,45 +510,37 @@ XSQLDA *createStorage(void)
|
|
579
510
|
* @return A long integer containing the generator value.
|
580
511
|
*
|
581
512
|
*/
|
582
|
-
int32_t getGeneratorValue(const char *name, int step, isc_db_handle *connection)
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
else
|
600
|
-
{
|
601
|
-
ISC_STATUS local[20];
|
602
|
-
|
603
|
-
isc_rollback_transaction(local, &transaction);
|
604
|
-
rb_fireruby_raise(status, "Error obtaining generator value.");
|
605
|
-
}
|
606
|
-
|
607
|
-
isc_commit_transaction(status, &transaction);
|
608
|
-
}
|
609
|
-
else
|
610
|
-
{
|
513
|
+
int32_t getGeneratorValue(const char *name, int step, isc_db_handle *connection) {
|
514
|
+
int32_t result = 0;
|
515
|
+
ISC_STATUS status[ISC_STATUS_LENGTH];
|
516
|
+
isc_tr_handle transaction = 0;
|
517
|
+
XSQLDA *da = createStorage();
|
518
|
+
|
519
|
+
if(isc_start_transaction(status, &transaction, 1, connection, 0, NULL) == 0) {
|
520
|
+
char sql[100];
|
521
|
+
|
522
|
+
sprintf(sql, "SELECT GEN_ID(%s, %d) FROM RDB$DATABASE", name, step);
|
523
|
+
if(isc_dsql_exec_immed2(status, connection, &transaction, 0, sql,
|
524
|
+
3, NULL, da) == 0) {
|
525
|
+
result = *((int32_t *)da->sqlvar->sqldata);
|
526
|
+
} else {
|
527
|
+
ISC_STATUS local[20];
|
528
|
+
|
529
|
+
isc_rollback_transaction(local, &transaction);
|
611
530
|
rb_fireruby_raise(status, "Error obtaining generator value.");
|
612
|
-
|
531
|
+
}
|
532
|
+
|
533
|
+
isc_commit_transaction(status, &transaction);
|
534
|
+
} else {
|
535
|
+
rb_fireruby_raise(status, "Error obtaining generator value.");
|
536
|
+
}
|
613
537
|
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
}
|
538
|
+
/* Clean up. */
|
539
|
+
if(da != NULL) {
|
540
|
+
releaseDataArea(da);
|
541
|
+
}
|
619
542
|
|
620
|
-
|
543
|
+
return(result);
|
621
544
|
}
|
622
545
|
|
623
546
|
|
@@ -632,13 +555,12 @@ int32_t getGeneratorValue(const char *name, int step, isc_db_handle *connection)
|
|
632
555
|
* @return A reference to the new Generator object.
|
633
556
|
*
|
634
557
|
*/
|
635
|
-
VALUE rb_generator_new(VALUE name, VALUE connection)
|
636
|
-
|
637
|
-
VALUE instance = allocateGenerator(cGenerator);
|
558
|
+
VALUE rb_generator_new(VALUE name, VALUE connection) {
|
559
|
+
VALUE instance = allocateGenerator(cGenerator);
|
638
560
|
|
639
|
-
|
561
|
+
initializeGenerator(instance, name, connection);
|
640
562
|
|
641
|
-
|
563
|
+
return(instance);
|
642
564
|
}
|
643
565
|
|
644
566
|
|
@@ -651,12 +573,10 @@ VALUE rb_generator_new(VALUE name, VALUE connection)
|
|
651
573
|
* with the Generator object being collected.
|
652
574
|
*
|
653
575
|
*/
|
654
|
-
void generatorFree(void *generator)
|
655
|
-
{
|
656
|
-
|
657
|
-
|
658
|
-
free((GeneratorHandle *)generator);
|
659
|
-
}
|
576
|
+
void generatorFree(void *generator) {
|
577
|
+
if(generator != NULL) {
|
578
|
+
free((GeneratorHandle *)generator);
|
579
|
+
}
|
660
580
|
}
|
661
581
|
|
662
582
|
|
@@ -667,17 +587,16 @@ void generatorFree(void *generator)
|
|
667
587
|
* @param module A reference to the module to create the class within.
|
668
588
|
*
|
669
589
|
*/
|
670
|
-
void Init_Generator(VALUE module)
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
rb_define_module_function(cGenerator, "create", createGenerator, 2);
|
590
|
+
void Init_Generator(VALUE module) {
|
591
|
+
cGenerator = rb_define_class_under(module, "Generator", rb_cObject);
|
592
|
+
rb_define_alloc_func(cGenerator, allocateGenerator);
|
593
|
+
rb_define_method(cGenerator, "initialize", initializeGenerator, 2);
|
594
|
+
rb_define_method(cGenerator, "initialize_copy", forbidObjectCopy, 1);
|
595
|
+
rb_define_method(cGenerator, "last", getLastGeneratorValue, 0);
|
596
|
+
rb_define_method(cGenerator, "next", getNextGeneratorValue, 1);
|
597
|
+
rb_define_method(cGenerator, "connection", getGeneratorConnection, 0);
|
598
|
+
rb_define_method(cGenerator, "name", getGeneratorName, 0);
|
599
|
+
rb_define_method(cGenerator, "drop", dropGenerator, 0);
|
600
|
+
rb_define_module_function(cGenerator, "exists?", doesGeneratorExist, 2);
|
601
|
+
rb_define_module_function(cGenerator, "create", createGenerator, 2);
|
683
602
|
}
|