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/Backup.h CHANGED
@@ -25,13 +25,13 @@
25
25
  #ifndef FIRERUBY_BACKUP_H
26
26
  #define FIRERUBY_BACKUP_H
27
27
 
28
- /* Includes. */
28
+ /* Includes. */
29
29
  #ifndef RUBY_H_INCLUDED
30
30
  #include "ruby.h"
31
31
  #define RUBY_H_INCLUDED
32
32
  #endif
33
33
 
34
- /* Function prototypes. */
35
- void Init_Backup(VALUE);
34
+ /* Function prototypes. */
35
+ void Init_Backup(VALUE);
36
36
 
37
37
  #endif /* FIRERUBY_BACKUP_H */
data/ext/Blob.c CHANGED
@@ -3,20 +3,20 @@
3
3
  *----------------------------------------------------------------------------*/
4
4
  /**
5
5
  * Copyright � Peter Wood, 2005
6
- *
6
+ *
7
7
  * The contents of this file are subject to the Mozilla Public License Version
8
8
  * 1.1 (the "License"); you may not use this file except in compliance with the
9
- * License. You may obtain a copy of the License at
9
+ * License. You may obtain a copy of the License at
10
10
  *
11
11
  * http://www.mozilla.org/MPL/
12
- *
12
+ *
13
13
  * Software distributed under the License is distributed on an "AS IS" basis,
14
14
  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
15
15
  * the specificlanguage governing rights and limitations under the License.
16
- *
16
+ *
17
17
  * The Original Code is the FireRuby extension for the Ruby language.
18
- *
19
- * The Initial Developer of the Original Code is Peter Wood. All Rights
18
+ *
19
+ * The Initial Developer of the Original Code is Peter Wood. All Rights
20
20
  * Reserved.
21
21
  *
22
22
  * @author Peter Wood
@@ -47,24 +47,20 @@ VALUE cBlob;
47
47
  * @param klass A reference to the Blob Class object.
48
48
  *
49
49
  */
50
- static VALUE allocateBlob(VALUE klass)
51
- {
52
- VALUE instance;
53
- BlobHandle *blob = ALLOC(BlobHandle);
54
-
55
- if(blob != NULL)
56
- {
57
- memset(&blob->description, 0, sizeof(ISC_BLOB_DESC));
58
- blob->segments = blob->size = 0;
59
- blob->handle = 0;
60
- instance = Data_Wrap_Struct(klass, NULL, blobFree, blob);
61
- }
62
- else
63
- {
64
- rb_raise(rb_eNoMemError, "Memory allocation failure allocating a blob.");
65
- }
66
-
67
- return(instance);
50
+ static VALUE allocateBlob(VALUE klass) {
51
+ VALUE instance;
52
+ BlobHandle *blob = ALLOC(BlobHandle);
53
+
54
+ if(blob != NULL) {
55
+ memset(&blob->description, 0, sizeof(ISC_BLOB_DESC));
56
+ blob->segments = blob->size = 0;
57
+ blob->handle = 0;
58
+ instance = Data_Wrap_Struct(klass, NULL, blobFree, blob);
59
+ } else {
60
+ rb_raise(rb_eNoMemError, "Memory allocation failure allocating a blob.");
61
+ }
62
+
63
+ return(instance);
68
64
  }
69
65
 
70
66
 
@@ -76,10 +72,9 @@ static VALUE allocateBlob(VALUE klass)
76
72
  * @return A reference to the newly initialized Blob object.
77
73
  *
78
74
  */
79
- VALUE initializeBlob(VALUE self)
80
- {
81
- rb_iv_set(self, "@data", Qnil);
82
- return(self);
75
+ VALUE initializeBlob(VALUE self) {
76
+ rb_iv_set(self, "@data", Qnil);
77
+ return(self);
83
78
  }
84
79
 
85
80
 
@@ -92,29 +87,25 @@ VALUE initializeBlob(VALUE self)
92
87
  * @return A reference to a String containing the Blob object data.
93
88
  *
94
89
  */
95
- static VALUE getBlobData(VALUE self)
96
- {
97
- VALUE data = rb_iv_get(self, "@data");
98
-
99
- if(data == Qnil)
100
- {
101
- BlobHandle *blob = NULL;
102
-
103
- Data_Get_Struct(self, BlobHandle, blob);
104
- if(blob->size > 0)
105
- {
106
- char *buffer = loadBlobData(blob);
107
-
108
- if(buffer != NULL)
109
- {
110
- data = rb_str_new(buffer, blob->size);
111
- }
112
- free(buffer);
90
+ static VALUE getBlobData(VALUE self) {
91
+ VALUE data = rb_iv_get(self, "@data");
92
+
93
+ if(data == Qnil) {
94
+ BlobHandle *blob = NULL;
95
+
96
+ Data_Get_Struct(self, BlobHandle, blob);
97
+ if(blob->size > 0) {
98
+ char *buffer = loadBlobData(blob);
99
+
100
+ if(buffer != NULL) {
101
+ data = rb_str_new(buffer, blob->size);
113
102
  }
114
- rb_iv_set(self, "@data", data);
115
- }
116
-
117
- return(data);
103
+ free(buffer);
104
+ }
105
+ rb_iv_set(self, "@data", data);
106
+ }
107
+
108
+ return(data);
118
109
  }
119
110
 
120
111
 
@@ -128,29 +119,25 @@ static VALUE getBlobData(VALUE self)
128
119
  * @return A reference to the closed Blob object.
129
120
  *
130
121
  */
131
- static VALUE closeBlob(VALUE self)
132
- {
133
- VALUE data = rb_iv_get(self, "@data");
134
- BlobHandle *blob = NULL;
135
-
136
- if(data != Qnil)
137
- {
138
- rb_iv_set(self, "@data", Qnil);
139
- }
140
-
141
- Data_Get_Struct(self, BlobHandle, blob);
142
- if(blob->handle != 0)
143
- {
144
- ISC_STATUS status[20];
145
-
146
- if(isc_close_blob(status, &blob->handle) != 0)
147
- {
148
- rb_fireruby_raise(status, "Error closing blob.");
149
- }
150
- blob->handle = 0;
151
- }
152
-
153
- return(self);
122
+ static VALUE closeBlob(VALUE self) {
123
+ VALUE data = rb_iv_get(self, "@data");
124
+ BlobHandle *blob = NULL;
125
+
126
+ if(data != Qnil) {
127
+ rb_iv_set(self, "@data", Qnil);
128
+ }
129
+
130
+ Data_Get_Struct(self, BlobHandle, blob);
131
+ if(blob->handle != 0) {
132
+ ISC_STATUS status[ISC_STATUS_LENGTH];
133
+
134
+ if(isc_close_blob(status, &blob->handle) != 0) {
135
+ rb_fireruby_raise(status, "Error closing blob.");
136
+ }
137
+ blob->handle = 0;
138
+ }
139
+
140
+ return(self);
154
141
  }
155
142
 
156
143
 
@@ -163,27 +150,24 @@ static VALUE closeBlob(VALUE self)
163
150
  * @return A reference to the last return value from the block called.
164
151
  *
165
152
  */
166
- static VALUE eachBlobSegment(VALUE self)
167
- {
168
- VALUE result = Qnil;
169
-
170
- if(rb_block_given_p())
171
- {
172
- BlobHandle *blob = NULL;
173
- char *segment = NULL;
174
- unsigned short size = 0;
175
-
176
- Data_Get_Struct(self, BlobHandle, blob);
153
+ static VALUE eachBlobSegment(VALUE self) {
154
+ VALUE result = Qnil;
155
+
156
+ if(rb_block_given_p()) {
157
+ BlobHandle *blob = NULL;
158
+ char *segment = NULL;
159
+ unsigned short size = 0;
160
+
161
+ Data_Get_Struct(self, BlobHandle, blob);
162
+ segment = loadBlobSegment(blob, &size);
163
+ while(segment != NULL) {
164
+ result = rb_yield(rb_str_new(segment, size));
165
+ free(segment);
177
166
  segment = loadBlobSegment(blob, &size);
178
- while(segment != NULL)
179
- {
180
- result = rb_yield(rb_str_new(segment, size));
181
- free(segment);
182
- segment = loadBlobSegment(blob, &size);
183
- }
184
- }
185
-
186
- return(result);
167
+ }
168
+ }
169
+
170
+ return(result);
187
171
  }
188
172
 
189
173
 
@@ -207,68 +191,54 @@ BlobHandle *openBlob(ISC_QUAD blobId,
207
191
  char *table,
208
192
  char *column,
209
193
  isc_db_handle *connection,
210
- isc_tr_handle *transaction)
211
- {
212
- BlobHandle *blob = ALLOC(BlobHandle);
213
-
214
- if(blob != NULL)
215
- {
216
- ISC_STATUS status[20];
217
-
218
- /* Extract the blob details and open it. */
219
- blob->handle = 0;
220
- isc_blob_default_desc(&blob->description,
221
- (unsigned char *)table,
222
- (unsigned char *)column);
223
- if(isc_open_blob2(status, connection, transaction, &blob->handle, &blobId,
224
- 0, NULL) == 0)
225
- {
226
- char items[] = {isc_info_blob_num_segments,
227
- isc_info_blob_total_length},
228
- data[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
229
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
230
-
231
- if(isc_blob_info(status, &blob->handle, 2, items, 20, data) == 0)
232
- {
233
- int offset = 0,
234
- done = 0;
235
-
236
- while(done < 2)
237
- {
238
- int length = isc_vax_integer(&data[offset + 1], 2);
239
-
240
- if(data[offset] == isc_info_blob_num_segments)
241
- {
242
- blob->segments = isc_vax_integer(&data[offset + 3], length);
243
- done++;
244
- }
245
- else if(data[offset] == isc_info_blob_total_length)
246
- {
247
- blob->size = isc_vax_integer(&data[offset + 3], length);
248
- done++;
249
- }
250
- else
251
- {
252
- free(blob);
253
- rb_fireruby_raise(NULL, "Error reading blob details.");
254
- }
255
- offset += length + 3;
256
- }
257
- }
258
- else
259
- {
194
+ isc_tr_handle *transaction) {
195
+ BlobHandle *blob = ALLOC(BlobHandle);
196
+
197
+ if(blob != NULL) {
198
+ ISC_STATUS status[ISC_STATUS_LENGTH];
199
+
200
+ /* Extract the blob details and open it. */
201
+ blob->handle = 0;
202
+ isc_blob_default_desc(&blob->description,
203
+ (unsigned char *)table,
204
+ (unsigned char *)column);
205
+ if(isc_open_blob2(status, connection, transaction, &blob->handle, &blobId,
206
+ 0, NULL) == 0) {
207
+ char items[] = {isc_info_blob_num_segments,
208
+ isc_info_blob_total_length},
209
+ data[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
210
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
211
+
212
+ if(isc_blob_info(status, &blob->handle, 2, items, 20, data) == 0) {
213
+ int offset = 0,
214
+ done = 0;
215
+
216
+ while(done < 2) {
217
+ int length = isc_vax_integer(&data[offset + 1], 2);
218
+
219
+ if(data[offset] == isc_info_blob_num_segments) {
220
+ blob->segments = isc_vax_integer(&data[offset + 3], length);
221
+ done++;
222
+ } else if(data[offset] == isc_info_blob_total_length) {
223
+ blob->size = isc_vax_integer(&data[offset + 3], length);
224
+ done++;
225
+ } else {
260
226
  free(blob);
261
- rb_fireruby_raise(status, "Error fetching blob details.");
262
- }
263
- }
264
- else
265
- {
266
- free(blob);
267
- rb_fireruby_raise(status, "Error opening blob.");
227
+ rb_fireruby_raise(NULL, "Error reading blob details.");
228
+ }
229
+ offset += length + 3;
230
+ }
231
+ } else {
232
+ free(blob);
233
+ rb_fireruby_raise(status, "Error fetching blob details.");
268
234
  }
269
- }
270
-
271
- return(blob);
235
+ } else {
236
+ free(blob);
237
+ rb_fireruby_raise(status, "Error opening blob.");
238
+ }
239
+ }
240
+
241
+ return(blob);
272
242
  }
273
243
 
274
244
 
@@ -282,47 +252,38 @@ BlobHandle *openBlob(ISC_QUAD blobId,
282
252
  * blob.
283
253
  *
284
254
  */
285
- char *loadBlobData(BlobHandle *blob)
286
- {
287
- char *data = NULL;
288
-
289
- if(blob != NULL && blob->handle != 0)
290
- {
291
- if((data = ALLOC_N(char, blob->size)) != NULL)
292
- {
293
- ISC_STATUS status[20],
294
- result = 0;
295
- int offset = 0;
296
-
297
- while(result == 0 || result == isc_segment)
298
- {
299
- unsigned short quantity = 0,
300
- available = 0;
301
- int remains = blob->size - offset;
302
-
303
- available = remains > USHRT_MAX ? USHRT_MAX : remains;
304
- result = isc_get_segment(status, &blob->handle, &quantity,
305
- available, &data[offset]);
306
- if(result != 0 && result != isc_segment && result != isc_segstr_eof)
307
- {
308
- free(data);
309
- rb_fireruby_raise(status, "Error loading blob data.");
310
- }
311
- offset = offset + quantity;
312
- }
313
- }
314
- else
315
- {
316
- rb_raise(rb_eNoMemError,
317
- "Memory allocation failure loading blob data.");
255
+ char *loadBlobData(BlobHandle *blob) {
256
+ char *data = NULL;
257
+
258
+ if(blob != NULL && blob->handle != 0) {
259
+ if((data = ALLOC_N(char, blob->size)) != NULL) {
260
+ ISC_STATUS status[ISC_STATUS_LENGTH],
261
+ result = 0;
262
+ int offset = 0;
263
+
264
+ while(result == 0 || result == isc_segment) {
265
+ unsigned short quantity = 0,
266
+ available = 0;
267
+ int remains = blob->size - offset;
268
+
269
+ available = remains > USHRT_MAX ? USHRT_MAX : remains;
270
+ result = isc_get_segment(status, &blob->handle, &quantity,
271
+ available, &data[offset]);
272
+ if(result != 0 && result != isc_segment && result != isc_segstr_eof) {
273
+ free(data);
274
+ rb_fireruby_raise(status, "Error loading blob data.");
275
+ }
276
+ offset = offset + quantity;
318
277
  }
319
- }
320
- else
321
- {
322
- rb_fireruby_raise(NULL, "Invalid blob specified for loading.");
323
- }
324
-
325
- return(data);
278
+ } else {
279
+ rb_raise(rb_eNoMemError,
280
+ "Memory allocation failure loading blob data.");
281
+ }
282
+ } else {
283
+ rb_fireruby_raise(NULL, "Invalid blob specified for loading.");
284
+ }
285
+
286
+ return(data);
326
287
  }
327
288
 
328
289
 
@@ -339,39 +300,31 @@ char *loadBlobData(BlobHandle *blob)
339
300
  * segements to be read.
340
301
  *
341
302
  */
342
- char *loadBlobSegment(BlobHandle *blob, unsigned short *length)
343
- {
344
- char *data = NULL;
345
-
346
- *length = 0;
347
- if(blob != NULL && blob->handle != 0)
348
- {
349
- unsigned short size = blob->description.blob_desc_segment_size;
350
-
351
- if((data = ALLOC_N(char, size)) != NULL)
352
- {
353
- ISC_STATUS status[20],
354
- result;
355
-
356
- result = isc_get_segment(status, &blob->handle, length, size, data);
357
- if(result != 0 && result != isc_segstr_eof)
358
- {
359
- free(data);
360
- rb_fireruby_raise(status, "Error reading blob segment.");
361
- }
362
- }
363
- else
364
- {
365
- rb_raise(rb_eNoMemError,
366
- "Memory allocation failre loading blob segment.");
303
+ char *loadBlobSegment(BlobHandle *blob, unsigned short *length) {
304
+ char *data = NULL;
305
+
306
+ *length = 0;
307
+ if(blob != NULL && blob->handle != 0) {
308
+ unsigned short size = blob->description.blob_desc_segment_size;
309
+
310
+ if((data = ALLOC_N(char, size)) != NULL) {
311
+ ISC_STATUS status[ISC_STATUS_LENGTH],
312
+ result;
313
+
314
+ result = isc_get_segment(status, &blob->handle, length, size, data);
315
+ if(result != 0 && result != isc_segstr_eof) {
316
+ free(data);
317
+ rb_fireruby_raise(status, "Error reading blob segment.");
367
318
  }
368
- }
369
- else
370
- {
371
- rb_fireruby_raise(NULL, "Invalid blob specified for loading.");
372
- }
373
-
374
- return(data);
319
+ } else {
320
+ rb_raise(rb_eNoMemError,
321
+ "Memory allocation failre loading blob segment.");
322
+ }
323
+ } else {
324
+ rb_fireruby_raise(NULL, "Invalid blob specified for loading.");
325
+ }
326
+
327
+ return(data);
375
328
  }
376
329
 
377
330
 
@@ -384,20 +337,17 @@ char *loadBlobSegment(BlobHandle *blob, unsigned short *length)
384
337
  * object being collected.
385
338
  *
386
339
  */
387
- void blobFree(void *blob)
388
- {
389
- if(blob != NULL)
390
- {
391
- BlobHandle *handle = (BlobHandle *)blob;
392
-
393
- if(handle->handle != 0)
394
- {
395
- ISC_STATUS status[20];
396
-
397
- isc_close_blob(status, &handle->handle);
398
- }
399
- free(handle);
400
- }
340
+ void blobFree(void *blob) {
341
+ if(blob != NULL) {
342
+ BlobHandle *handle = (BlobHandle *)blob;
343
+
344
+ if(handle->handle != 0) {
345
+ ISC_STATUS status[ISC_STATUS_LENGTH];
346
+
347
+ isc_close_blob(status, &handle->handle);
348
+ }
349
+ free(handle);
350
+ }
401
351
  }
402
352
 
403
353
 
@@ -409,13 +359,12 @@ void blobFree(void *blob)
409
359
  * under.
410
360
  *
411
361
  */
412
- void Init_Blob(VALUE module)
413
- {
414
- cBlob = rb_define_class_under(module, "Blob", rb_cObject);
415
- rb_define_alloc_func(cBlob, allocateBlob);
416
- rb_define_method(cBlob, "initialize", initializeBlob, 0);
417
- rb_define_method(cBlob, "initialize_copy", forbidObjectCopy, 1);
418
- rb_define_method(cBlob, "to_s", getBlobData, 0);
419
- rb_define_method(cBlob, "close", closeBlob, 0);
420
- rb_define_method(cBlob, "each", eachBlobSegment, 0);
362
+ void Init_Blob(VALUE module) {
363
+ cBlob = rb_define_class_under(module, "Blob", rb_cObject);
364
+ rb_define_alloc_func(cBlob, allocateBlob);
365
+ rb_define_method(cBlob, "initialize", initializeBlob, 0);
366
+ rb_define_method(cBlob, "initialize_copy", forbidObjectCopy, 1);
367
+ rb_define_method(cBlob, "to_s", getBlobData, 0);
368
+ rb_define_method(cBlob, "close", closeBlob, 0);
369
+ rb_define_method(cBlob, "each", eachBlobSegment, 0);
421
370
  }
data/ext/Blob.h CHANGED
@@ -3,20 +3,20 @@
3
3
  *----------------------------------------------------------------------------*/
4
4
  /**
5
5
  * Copyright � Peter Wood, 2005
6
- *
6
+ *
7
7
  * The contents of this file are subject to the Mozilla Public License Version
8
8
  * 1.1 (the "License"); you may not use this file except in compliance with the
9
- * License. You may obtain a copy of the License at
9
+ * License. You may obtain a copy of the License at
10
10
  *
11
11
  * http://www.mozilla.org/MPL/
12
- *
12
+ *
13
13
  * Software distributed under the License is distributed on an "AS IS" basis,
14
14
  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
15
15
  * the specificlanguage governing rights and limitations under the License.
16
- *
16
+ *
17
17
  * The Original Code is the FireRuby extension for the Ruby language.
18
- *
19
- * The Initial Developer of the Original Code is Peter Wood. All Rights
18
+ *
19
+ * The Initial Developer of the Original Code is Peter Wood. All Rights
20
20
  * Reserved.
21
21
  *
22
22
  * @author Peter Wood
@@ -25,41 +25,40 @@
25
25
  #ifndef FIRERUBY_BLOB_H
26
26
  #define FIRERUBY_BLOB_H
27
27
 
28
- /* Includes. */
28
+ /* Includes. */
29
29
  #ifndef FIRERUBY_FIRE_RUBY_EXCEPTION_H
30
30
  #include "FireRubyException.h"
31
31
  #endif
32
-
32
+
33
33
  #ifndef IBASE_H_INCLUDED
34
34
  #include "ibase.h"
35
35
  #define IBASE_H_INCLUDED
36
36
  #endif
37
-
37
+
38
38
  #ifndef RUBY_H_INCLUDED
39
39
  #include "ruby.h"
40
40
  #define RUBY_H_INCLUDED
41
41
  #endif
42
-
43
- /* Type definitions. */
44
- typedef struct
45
- {
46
- ISC_BLOB_DESC description;
47
- ISC_LONG segments,
48
- size;
49
- isc_blob_handle handle;
50
- } BlobHandle;
51
-
52
- /* Data elements. */
53
- extern VALUE cBlob;
54
-
55
- /* Function prototypes. */
56
- BlobHandle *openBlob(ISC_QUAD,
57
- char *,
58
- char *,
59
- isc_db_handle *,
60
- isc_tr_handle *);
61
- void Init_Blob(VALUE);
62
- void blobFree(void *);
63
- VALUE initializeBlob(VALUE);
42
+
43
+ /* Type definitions. */
44
+ typedef struct {
45
+ ISC_BLOB_DESC description;
46
+ ISC_LONG segments,
47
+ size;
48
+ isc_blob_handle handle;
49
+ } BlobHandle;
50
+
51
+ /* Data elements. */
52
+ extern VALUE cBlob;
53
+
54
+ /* Function prototypes. */
55
+ BlobHandle *openBlob(ISC_QUAD,
56
+ char *,
57
+ char *,
58
+ isc_db_handle *,
59
+ isc_tr_handle *);
60
+ void Init_Blob(VALUE);
61
+ void blobFree(void *);
62
+ VALUE initializeBlob(VALUE);
64
63
 
65
64
  #endif /* FIRERUBY_BLOB_H */