Subject | RE: [firebird-support] BLOB Filters |
---|---|
Author | Paul Beach |
Post date | 2004-05-13T08:51:06Z |
<< This will probably show my ignorance :)
Is the implication here that one could use them with Stored Procedures?
SO the stored procedure could input and return the correct result? >>
Nope.
Time for you to start reading:-)
Blobs Generally:
http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_blobs
Off list I can send you the ppt I did at Fulda last year, plus some
samples of DSQL code that do a select/insert that call the blob filter.
The only down side, is that although the code below works...
I haven't integrated all of the pieces together properly. I meant to do this, but
you know how things are, you get sidetacked and forget. I really should
come back to this and write it all up.
The key to filters is the DSQL statement extension for blobs:
FILTER FROM sub_type TO subtype
This isn't available in ISQL or procedures currently, although I suspect it could
be done.
filterInsert.e
#include <stdio.h>
#include <string.h>
EXEC SQL BEGIN DECLARE SECTION;
EXEC SQL
SET DATABASE DB = "COMPRESS.GDB";
BASED ON BLOB_COMPRESS.COMPRESS blob_id;
BASED ON BLOB_COMPRESS.COMPRESS.SEGMENT blob_segment_buf;
EXEC SQL END DECLARE SECTION;
int main(int argc, char* argv[])
{
FILE *text_file;
int i;
unsigned short blob_segment_len;
EXEC SQL
CONNECT DB;
printf("Database Connection Established\n");
EXEC SQL
SET TRANSACTION;
text_file=fopen("foo.txt","rb");
EXEC SQL
DECLARE WRITE_TEST CURSOR FOR
INSERT BLOB COMPRESS INTO DB.BLOB_COMPRESS FILTER FROM 1 TO -2;
EXEC SQL
OPEN WRITE_TEST INTO :blob_id;
while (!feof (text_file))
{
for (i = 0; i < 80 && !feof (text_file); i++)
blob_segment_buf[i] = fgetc (text_file);
if (feof (text_file))
i--;
blob_segment_len=i;
EXEC SQL
INSERT CURSOR WRITE_TEST VALUES (:blob_segment_buf:blob_segment_len);
}
EXEC SQL
CLOSE WRITE_TEST;
EXEC SQL
INSERT INTO DB.BLOB_COMPRESS (COMPRESS) VALUES (:blob_id);
EXEC SQL
COMMIT;
EXEC SQL
DISCONNECT DB;
return 0;
}
filterSelect.e
#include <stdio.h>
#include <string.h>
EXEC SQL BEGIN DECLARE SECTION;
EXEC SQL
SET DATABASE DB = "COMPRESS.GDB";
BASED ON BLOB_COMPRESS.COMPRESS blob_id;
BASED ON BLOB_COMPRESS.COMPRESS.SEGMENT blob_segment_buf;
EXEC SQL END DECLARE SECTION;
int main(int argc, char* argv[])
{
nsigned short blob_segment_len;
EXEC SQL
CONNECT DB;
EXEC SQL
SET TRANSACTION;
EXEC SQL
DECLARE READ_TEST CURSOR FOR SELECT
COMPRESS FROM DB.BLOB_COMPRESS WHERE PKEY=50;
EXEC SQL DECLARE BLOB_TEST CURSOR FOR READ
BLOB COMPRESS FROM DB.BLOB_COMPRESS FILTER FROM -2 TO 1;
EXEC SQL
OPEN READ_TEST;
EXEC SQL
FETCH READ_TEST INTO :blob_id;
EXEC SQL
OPEN BLOB_TEST USING :blob_id;
memset (blob_segment_buf, 0, sizeof blob_segment_buf);
EXEC SQL
FETCH BLOB_TEST INTO :blob_segment_buf :blob_segment_len;
while (SQLCODE != 100 || SQLCODE == 101)
{
printf ("%*s", blob_segment_len, blob_segment_buf);
memset (blob_segment_buf, 0, blob_segment_len);
EXEC SQL
FETCH BLOB_TEST INTO :blob_segment_buf :blob_segment_len ;
}
EXEC SQL
CLOSE BLOB_TEST;
EXEC SQL
CLOSE READ_TEST;
EXEC SQL
COMMIT;
EXEC SQL
DISCONNECT DB;
return 0;
}
Reality of it was, somewhere between 4.0 and 6.01 someone broke blob filters.
They now work....
Blob Filter Sample Code:
http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_blob_filter
Regards
Paul
Is the implication here that one could use them with Stored Procedures?
SO the stored procedure could input and return the correct result? >>
Nope.
Time for you to start reading:-)
Blobs Generally:
http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_blobs
Off list I can send you the ppt I did at Fulda last year, plus some
samples of DSQL code that do a select/insert that call the blob filter.
The only down side, is that although the code below works...
I haven't integrated all of the pieces together properly. I meant to do this, but
you know how things are, you get sidetacked and forget. I really should
come back to this and write it all up.
The key to filters is the DSQL statement extension for blobs:
FILTER FROM sub_type TO subtype
This isn't available in ISQL or procedures currently, although I suspect it could
be done.
filterInsert.e
#include <stdio.h>
#include <string.h>
EXEC SQL BEGIN DECLARE SECTION;
EXEC SQL
SET DATABASE DB = "COMPRESS.GDB";
BASED ON BLOB_COMPRESS.COMPRESS blob_id;
BASED ON BLOB_COMPRESS.COMPRESS.SEGMENT blob_segment_buf;
EXEC SQL END DECLARE SECTION;
int main(int argc, char* argv[])
{
FILE *text_file;
int i;
unsigned short blob_segment_len;
EXEC SQL
CONNECT DB;
printf("Database Connection Established\n");
EXEC SQL
SET TRANSACTION;
text_file=fopen("foo.txt","rb");
EXEC SQL
DECLARE WRITE_TEST CURSOR FOR
INSERT BLOB COMPRESS INTO DB.BLOB_COMPRESS FILTER FROM 1 TO -2;
EXEC SQL
OPEN WRITE_TEST INTO :blob_id;
while (!feof (text_file))
{
for (i = 0; i < 80 && !feof (text_file); i++)
blob_segment_buf[i] = fgetc (text_file);
if (feof (text_file))
i--;
blob_segment_len=i;
EXEC SQL
INSERT CURSOR WRITE_TEST VALUES (:blob_segment_buf:blob_segment_len);
}
EXEC SQL
CLOSE WRITE_TEST;
EXEC SQL
INSERT INTO DB.BLOB_COMPRESS (COMPRESS) VALUES (:blob_id);
EXEC SQL
COMMIT;
EXEC SQL
DISCONNECT DB;
return 0;
}
filterSelect.e
#include <stdio.h>
#include <string.h>
EXEC SQL BEGIN DECLARE SECTION;
EXEC SQL
SET DATABASE DB = "COMPRESS.GDB";
BASED ON BLOB_COMPRESS.COMPRESS blob_id;
BASED ON BLOB_COMPRESS.COMPRESS.SEGMENT blob_segment_buf;
EXEC SQL END DECLARE SECTION;
int main(int argc, char* argv[])
{
nsigned short blob_segment_len;
EXEC SQL
CONNECT DB;
EXEC SQL
SET TRANSACTION;
EXEC SQL
DECLARE READ_TEST CURSOR FOR SELECT
COMPRESS FROM DB.BLOB_COMPRESS WHERE PKEY=50;
EXEC SQL DECLARE BLOB_TEST CURSOR FOR READ
BLOB COMPRESS FROM DB.BLOB_COMPRESS FILTER FROM -2 TO 1;
EXEC SQL
OPEN READ_TEST;
EXEC SQL
FETCH READ_TEST INTO :blob_id;
EXEC SQL
OPEN BLOB_TEST USING :blob_id;
memset (blob_segment_buf, 0, sizeof blob_segment_buf);
EXEC SQL
FETCH BLOB_TEST INTO :blob_segment_buf :blob_segment_len;
while (SQLCODE != 100 || SQLCODE == 101)
{
printf ("%*s", blob_segment_len, blob_segment_buf);
memset (blob_segment_buf, 0, blob_segment_len);
EXEC SQL
FETCH BLOB_TEST INTO :blob_segment_buf :blob_segment_len ;
}
EXEC SQL
CLOSE BLOB_TEST;
EXEC SQL
CLOSE READ_TEST;
EXEC SQL
COMMIT;
EXEC SQL
DISCONNECT DB;
return 0;
}
Reality of it was, somewhere between 4.0 and 6.01 someone broke blob filters.
They now work....
Blob Filter Sample Code:
http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_blob_filter
Regards
Paul