Subject | RES: [firebird-support] How to copy Blob in SP |
---|---|
Author | Eduardo Resek |
Post date | 2006-10-17T04:20:58Z |
I stored files in Table blobs, in SP i want to copy records from table
to another, or in same table with the contents of its blob.
How, i can do it
Thanks in advance.
---------------------
Just as straight as it can be. Declare a blob variable, select some blob
into it and insert it into another record. For instance, I have a table
where I store report templates. Each new record is created with a non-empty
version of the template.
Table REPORT_TEMPLATE:
Id bigint not null (primary key),
RptName varchar(30) not null,
Template blob subtype o segment size 80
Procedure SP_NEWREPORT
INPUT PARAMS : RPTNAME VARCHAR(30),
ID_MODEL BIGINT /* ID TO COPY FROM (USED AS MODEL
FOR NEW TEMPLATE */
OUTPUT PARAM: ID BIGINT
...
DECLARE VARIABLE TMPL BLOB SUB_TYPE 0 SEGMENT SIZE 80; /* ONLY USED IN
OPTION 1 */
BEGIN
ID = GEN_ID( GEN_TEMPLATE, 1); -- GET GEN_TEMPLATE
/* OPTION 1 */
/* SELECT FROM MODEL */
SELECT TEMPLATE FROM REPORT_TEMPLATE WHERE ID = :ID_MODEL INTO
:TMPL;
/* INSERT AS NEW */
INSERT INTO REPORT_TEMPLATE (ID, RPTNAME, TEMPLATE) VALUES (:ID,
:RPTNAME, :TMPL);
/* OPTION 2 */
INSERT INTO REPORT_TEMPLATE (ID, RPTNAME, TEMPLATE)
SELECT :ID, :RPTNAME, TEMPLATE FROM REPORT_TEMPLATE WHERE ID =
:ID_MODEL;
END
HIH,
Eduardo Resek
to another, or in same table with the contents of its blob.
How, i can do it
Thanks in advance.
---------------------
Just as straight as it can be. Declare a blob variable, select some blob
into it and insert it into another record. For instance, I have a table
where I store report templates. Each new record is created with a non-empty
version of the template.
Table REPORT_TEMPLATE:
Id bigint not null (primary key),
RptName varchar(30) not null,
Template blob subtype o segment size 80
Procedure SP_NEWREPORT
INPUT PARAMS : RPTNAME VARCHAR(30),
ID_MODEL BIGINT /* ID TO COPY FROM (USED AS MODEL
FOR NEW TEMPLATE */
OUTPUT PARAM: ID BIGINT
...
DECLARE VARIABLE TMPL BLOB SUB_TYPE 0 SEGMENT SIZE 80; /* ONLY USED IN
OPTION 1 */
BEGIN
ID = GEN_ID( GEN_TEMPLATE, 1); -- GET GEN_TEMPLATE
/* OPTION 1 */
/* SELECT FROM MODEL */
SELECT TEMPLATE FROM REPORT_TEMPLATE WHERE ID = :ID_MODEL INTO
:TMPL;
/* INSERT AS NEW */
INSERT INTO REPORT_TEMPLATE (ID, RPTNAME, TEMPLATE) VALUES (:ID,
:RPTNAME, :TMPL);
/* OPTION 2 */
INSERT INTO REPORT_TEMPLATE (ID, RPTNAME, TEMPLATE)
SELECT :ID, :RPTNAME, TEMPLATE FROM REPORT_TEMPLATE WHERE ID =
:ID_MODEL;
END
HIH,
Eduardo Resek