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/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
- VALUE instance = Qnil;
67
- GeneratorHandle *generator = ALLOC(GeneratorHandle);
68
-
69
- if(generator != NULL)
70
- {
71
- generator->connection = NULL;
72
- instance = Data_Wrap_Struct(klass, NULL, generatorFree,
73
- generator);
74
- }
75
- else
76
- {
77
- rb_raise(rb_eNoMemError,
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
- GeneratorHandle *generator = NULL;
102
- ConnectionHandle *handle = NULL;
103
-
104
- if(TYPE(name) != T_STRING)
105
- {
106
- rb_fireruby_raise(NULL, "Invalid generator name specified.");
107
- }
108
-
109
- if(TYPE(connection) != T_DATA &&
110
- RDATA(connection)->dfree != (RUBY_DATA_FUNC)connectionFree)
111
- {
112
- rb_fireruby_raise(NULL, "Invalid connection specified for generator.");
113
- }
114
-
115
- rb_iv_set(self, "@name", name);
116
- rb_iv_set(self, "@connection", connection);
117
-
118
- Data_Get_Struct(connection, ConnectionHandle, handle);
119
- Data_Get_Struct(self, GeneratorHandle, generator);
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
- VALUE name = rb_iv_get(self, "@name");
168
- GeneratorHandle *generator = NULL;
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
- Data_Get_Struct(self, GeneratorHandle, generator);
161
+ Data_Get_Struct(self, GeneratorHandle, generator);
172
162
 
173
- number = getGeneratorValue(StringValuePtr(name), 0, generator->connection);
163
+ number = getGeneratorValue(StringValuePtr(name), 0, generator->connection);
174
164
 
175
- return(INT2NUM(number));
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
- VALUE name = rb_iv_get(self, "@name");
192
- GeneratorHandle *generator = NULL;
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
- Data_Get_Struct(self, GeneratorHandle, generator);
184
+ Data_Get_Struct(self, GeneratorHandle, generator);
196
185
 
197
- /* Check the step type. */
198
- if(TYPE(step) != T_FIXNUM)
199
- {
200
- rb_fireruby_raise(NULL, "Invalid generator step value.");
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
- number = getGeneratorValue(StringValuePtr(name), FIX2INT(step),
204
- generator->connection);
191
+ number = getGeneratorValue(StringValuePtr(name), FIX2INT(step),
192
+ generator->connection);
205
193
 
206
- return(INT2NUM(number));
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
- GeneratorHandle *generator = NULL;
221
- VALUE name;
206
+ static VALUE dropGenerator(VALUE self) {
207
+ GeneratorHandle *generator = NULL;
208
+ VALUE name;
222
209
 
223
- Data_Get_Struct(self, GeneratorHandle, generator);
224
- name = rb_iv_get(self, "@name");
210
+ Data_Get_Struct(self, GeneratorHandle, generator);
211
+ name = rb_iv_get(self, "@name");
225
212
 
226
- /* Drop the generator. */
227
- deleteGenerator(StringValuePtr(name), generator->connection);
213
+ /* Drop the generator. */
214
+ deleteGenerator(StringValuePtr(name), generator->connection);
228
215
 
229
- return(self);
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
- VALUE exists = Qfalse;
249
- ConnectionHandle *handle = NULL;
250
-
251
- if(TYPE(connection) != T_DATA ||
252
- RDATA(connection)->dfree != (RUBY_DATA_FUNC)connectionFree)
253
- {
254
- rb_fireruby_raise(NULL, "Invalid connection specified.");
255
- }
256
-
257
- Data_Get_Struct(connection, ConnectionHandle, handle);
258
-
259
- if(handle->handle == 0)
260
- {
261
- rb_fireruby_raise(NULL, "Connection is closed.");
262
- }
263
-
264
- if(checkForGenerator(StringValuePtr(name), &handle->handle))
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
- VALUE result = Qnil;
290
- ConnectionHandle *handle = NULL;
291
-
292
- if(TYPE(name) != T_STRING)
293
- {
294
- rb_fireruby_raise(NULL, "Invalid generator name specified.");
295
- }
296
-
297
- if(TYPE(connection) != T_DATA &&
298
- RDATA(connection)->dfree != (RUBY_DATA_FUNC)connectionFree)
299
- {
300
- rb_fireruby_raise(NULL,
301
- "Invalid connection specified for generator creation.");
302
- }
303
-
304
- Data_Get_Struct(connection, ConnectionHandle, handle);
305
- if(handle->handle != 0)
306
- {
307
- installGenerator(StringValuePtr(name), &handle->handle);
308
- result = rb_generator_new(name, connection);
309
- }
310
- else
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
- int result = -1;
335
- isc_stmt_handle statement = 0;
336
- ISC_STATUS status[20];
337
-
338
- if(isc_dsql_allocate_statement(status, connection, &statement) == 0)
339
- {
340
- isc_tr_handle transaction = 0;
341
-
342
- if(isc_start_transaction(status, &transaction, 1, connection, 0,
343
- NULL) == 0)
344
- {
345
- XSQLDA *da = (XSQLDA *)ALLOC_N(char, XSQLDA_LENGTH(1));
346
-
347
- if(da != NULL)
348
- {
349
- char sql[100];
350
-
351
- da->version = SQLDA_VERSION1;
352
- da->sqln = 1;
353
- sprintf(sql, "SELECT COUNT(*) FROM %sS WHERE %s_NAME = UPPER('%s')",
354
- "RDB$GENERATOR", "RDB$GENERATOR", name);
355
- if(isc_dsql_prepare(status, &transaction, &statement, strlen(sql),
356
- sql, 3, da) == 0)
357
- {
358
- /* Prepare the XSQLDA and provide it with data room. */
359
- allocateOutXSQLDA(da->sqld, &statement, 3);
360
- prepareDataArea(da);
361
- if(isc_dsql_execute(status, &transaction, &statement,
362
- 3, da) == 0)
363
- {
364
- if(isc_dsql_fetch(status, &statement, 3, da) == 0)
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
- releaseDataArea(da);
388
- }
389
- else
390
- {
391
- rb_raise(rb_eNoMemError, "Memory allocation failure checking "\
392
- "generator existence.");
393
- }
394
-
395
- if(transaction != 0)
396
- {
397
- isc_commit_transaction(status, &transaction);
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
- else
401
- {
402
- rb_fireruby_raise(status, "Error checking for generator.");
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
- isc_dsql_free_statement(status, &statement, DSQL_drop);
406
- }
364
+ isc_dsql_free_statement(status, &statement, DSQL_drop);
365
+ }
407
366
 
408
- return(result);
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
- int result = -1;
426
- isc_stmt_handle statement = 0;
427
- ISC_STATUS status[20];
428
-
429
- if(isc_dsql_allocate_statement(status, connection, &statement) == 0)
430
- {
431
- isc_tr_handle transaction = 0;
432
-
433
- if(isc_start_transaction(status, &transaction, 1, connection, 0,
434
- NULL) == 0)
435
- {
436
- char sql[100];
437
-
438
- sprintf(sql, "CREATE GENERATOR %s", name);
439
- if(isc_dsql_prepare(status, &transaction, &statement, strlen(sql),
440
- sql, 3, NULL) == 0)
441
- {
442
- if(isc_dsql_execute(status, &transaction, &statement,
443
- 3, NULL) == 0)
444
- {
445
- result = 0;
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
- else
463
- {
464
- rb_fireruby_raise(status, "Error creating generator.");
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
- isc_dsql_free_statement(status, &statement, DSQL_drop);
468
- }
414
+ isc_dsql_free_statement(status, &statement, DSQL_drop);
415
+ }
469
416
 
470
- return(result);
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
- int result = -1;
488
- isc_stmt_handle statement = 0;
489
- ISC_STATUS status[20];
490
-
491
- if(isc_dsql_allocate_statement(status, connection, &statement) == 0)
492
- {
493
- isc_tr_handle transaction = 0;
494
-
495
- if(isc_start_transaction(status, &transaction, 1, connection, 0,
496
- NULL) == 0)
497
- {
498
- char sql[100];
499
-
500
- sprintf(sql, "DROP GENERATOR %s", name);
501
- if(isc_dsql_prepare(status, &transaction, &statement, strlen(sql),
502
- sql, 3, NULL) == 0)
503
- {
504
- if(isc_dsql_execute(status, &transaction, &statement,
505
- 3, NULL) == 0)
506
- {
507
- result = 0;
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
- else
525
- {
526
- rb_fireruby_raise(status, "Error dropping generator.");
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
- isc_dsql_free_statement(status, &statement, DSQL_drop);
530
- }
464
+ isc_dsql_free_statement(status, &statement, DSQL_drop);
465
+ }
531
466
 
532
- return(result);
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
- XSQLDA *da = (XSQLDA *)ALLOC_N(char, XSQLDA_LENGTH(1));
547
-
548
- if(da != NULL)
549
- {
550
- XSQLVAR *var = da->sqlvar;
551
-
552
- da->version = SQLDA_VERSION1;
553
- da->sqln = 1;
554
- da->sqld = 1;
555
- var->sqltype = SQL_LONG;
556
- var->sqlscale = 0;
557
- var->sqllen = sizeof(long);
558
- prepareDataArea(da);
559
- }
560
- else
561
- {
562
- rb_raise(rb_eNoMemError,
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
- int32_t result = 0;
585
- ISC_STATUS status[20];
586
- isc_tr_handle transaction = 0;
587
- XSQLDA *da = createStorage();
588
-
589
- if(isc_start_transaction(status, &transaction, 1, connection, 0, NULL) == 0)
590
- {
591
- char sql[100];
592
-
593
- sprintf(sql, "SELECT GEN_ID(%s, %d) FROM RDB$DATABASE", name, step);
594
- if(isc_dsql_exec_immed2(status, connection, &transaction, 0, sql,
595
- 3, NULL, da) == 0)
596
- {
597
- result = *((int32_t *)da->sqlvar->sqldata);
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
- /* Clean up. */
615
- if(da != NULL)
616
- {
617
- releaseDataArea(da);
618
- }
538
+ /* Clean up. */
539
+ if(da != NULL) {
540
+ releaseDataArea(da);
541
+ }
619
542
 
620
- return(result);
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
- initializeGenerator(instance, name, connection);
561
+ initializeGenerator(instance, name, connection);
640
562
 
641
- return(instance);
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
- if(generator != NULL)
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
- cGenerator = rb_define_class_under(module, "Generator", rb_cObject);
673
- rb_define_alloc_func(cGenerator, allocateGenerator);
674
- rb_define_method(cGenerator, "initialize", initializeGenerator, 2);
675
- rb_define_method(cGenerator, "initialize_copy", forbidObjectCopy, 1);
676
- rb_define_method(cGenerator, "last", getLastGeneratorValue, 0);
677
- rb_define_method(cGenerator, "next", getNextGeneratorValue, 1);
678
- rb_define_method(cGenerator, "connection", getGeneratorConnection, 0);
679
- rb_define_method(cGenerator, "name", getGeneratorName, 0);
680
- rb_define_method(cGenerator, "drop", dropGenerator, 0);
681
- rb_define_module_function(cGenerator, "exists?", doesGeneratorExist, 2);
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
  }