ext/Blob.c in rubyfb-0.5.8 vs ext/Blob.c in rubyfb-0.5.9
- old
+ new
@@ -25,10 +25,11 @@
/* Includes. */
#include "Blob.h"
#include <limits.h>
#include "Common.h"
+#include "rfbstr.h"
/* Function prototypes. */
static VALUE allocateBlob(VALUE);
static VALUE getBlobData(VALUE);
static VALUE closeBlob(VALUE);
@@ -65,16 +66,18 @@
/**
* This function provides the initialize method for the Blob class.
*
- * @param self A reference to the Blob object to be initialized.
+ * @param self A reference to the Blob object to be initialized.
+ * @param connection A reference to the Connection object owning the blob.
*
* @return A reference to the newly initialized Blob object.
*
*/
-VALUE initializeBlob(VALUE self) {
+VALUE initializeBlob(VALUE self, VALUE connection) {
+ rb_iv_set(self, "@connection", connection);
rb_iv_set(self, "@data", Qnil);
return(self);
}
@@ -87,20 +90,21 @@
* @return A reference to a String containing the Blob object data.
*
*/
static VALUE getBlobData(VALUE self) {
VALUE data = rb_iv_get(self, "@data");
+ VALUE connection = rb_iv_get(self, "@connection");
if(data == Qnil) {
BlobHandle *blob = NULL;
Data_Get_Struct(self, BlobHandle, blob);
if(blob->size > 0) {
char *buffer = loadBlobData(blob);
if(buffer != NULL) {
- data = rb_str_new(buffer, blob->size);
+ data = rfbstr(connection, blob->charset, buffer, blob->size);
}
free(buffer);
}
rb_iv_set(self, "@data", data);
}
@@ -152,18 +156,19 @@
*/
static VALUE eachBlobSegment(VALUE self) {
VALUE result = Qnil;
if(rb_block_given_p()) {
+ VALUE connection = rb_iv_get(self, "@connection");
BlobHandle *blob = NULL;
char *segment = NULL;
unsigned short size = 0;
Data_Get_Struct(self, BlobHandle, blob);
segment = loadBlobSegment(blob, &size);
while(segment != NULL) {
- result = rb_yield(rb_str_new(segment, size));
+ result = rb_yield(rfbstr(connection, blob->charset, segment, size));
free(segment);
segment = loadBlobSegment(blob, &size);
}
}
@@ -173,37 +178,39 @@
/**
* This function allocates a BlobHandle structure and opens the structure for
* use.
*
- * @param blobId The unique identifier for the blob to be opened.
+ * @param blobEntry The blob SQLVAR data.
* @param table The name of the table containing the blob being opened.
* @param column The name of the column in the table that contains the
* blob.
* @param connection The connection to be used in accessing the blob.
* @param transaction The transaction to be used in accessing the blob.
*
* @return A pointer to an allocated and opened BlobHandle structure.
*
*/
-BlobHandle *openBlob(ISC_QUAD blobId,
+BlobHandle *openBlob(XSQLVAR *blobEntry,
char *table,
char *column,
VALUE connection,
VALUE transaction) {
ConnectionHandle *cHandle = NULL;
TransactionHandle *tHandle = NULL;
Data_Get_Struct(connection, ConnectionHandle, cHandle);
Data_Get_Struct(transaction, TransactionHandle, tHandle);
+ ISC_QUAD blobId = *(ISC_QUAD *)blobEntry->sqldata;
BlobHandle *blob = ALLOC(BlobHandle);
if(blob != NULL) {
ISC_STATUS status[ISC_STATUS_LENGTH];
/* Extract the blob details and open it. */
blob->handle = 0;
+ blob->charset = blobEntry->sqlscale;
isc_blob_default_desc(&blob->description,
(unsigned char *)table,
(unsigned char *)column);
if(isc_open_blob2(status, &cHandle->handle, &tHandle->handle, &blob->handle, &blobId,
0, NULL) == 0) {
@@ -363,10 +370,10 @@
*
*/
void Init_Blob(VALUE module) {
cBlob = rb_define_class_under(module, "Blob", rb_cObject);
rb_define_alloc_func(cBlob, allocateBlob);
- rb_define_method(cBlob, "initialize", initializeBlob, 0);
+ rb_define_method(cBlob, "initialize", initializeBlob, 1);
rb_define_method(cBlob, "initialize_copy", forbidObjectCopy, 1);
rb_define_method(cBlob, "to_s", getBlobData, 0);
rb_define_method(cBlob, "close", closeBlob, 0);
rb_define_method(cBlob, "each", eachBlobSegment, 0);
}