Solved

Copy a blob from one table to another inside a stored procedure

Posted on 2008-10-31
1
1,247 Views
Last Modified: 2013-12-09
I'm running Firebird 2.1.1 & my applicaton written in .net 2.0
I've become unstuck when trying to write a stored procedure to copy some blob data (a tiff image) from one table to another. For example:

Table 1 contains a field called ImageScan , Type blob , Size 80, Subtype Binary
and row 4  of this contains my image

Table 2 contains a field called FiledScan , Type blob , Size 80 Subtype Binary
and row 6 is where I want the image to be copied to

I dont want to copy the image to the client and have the client reinsert the blob into the new table due to network overhead.

The SP would start with something like this:
Create Procedure CopyBlob (OldImageNumber integer, NewImageNumber integer)
where oldimage is the row number of the existing image and NewImageNumber is the row number of the new image.

Thanks in advance Jon


0
Comment
Question by:JonR01
1 Comment
 
LVL 4

Accepted Solution

by:
dprochownik earned 250 total points
ID: 22852814
I'm not sure what do you mean by "row number". In databases rows are not identify by  row number but by some IDs. Here you have simple script creates procedure which do what you want, but after I changed "row number" to "row id"

SET TERM ^ ;

CREATE OR ALTER PROCEDURE CopyBlob (
    OldRowID integer,
    NewRowID integer)
as
begin
  Update Table2 b
  set b.fieldscan = (select first 1 a.imagescan from Table1 a where a.id=:OldRowID)
  where b.id = :NewRowID;
end^

SET TERM ; ^

GRANT ALL ON Table1 TO PROCEDURE CopyBlob;

GRANT ALL ON Table2 TO PROCEDURE CopyBlob;

GRANT EXECUTE ON PROCEDURE CopyBlob TO PUBLIC;

Of course I assumed that there is a row with specified ID in Table2, before you use procedure. If not you can use "Insert" or "Insert or update" syntax instead "Update".
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In today’s complex data management environments, it is not unusual for UNIX servers to be dedicated to a particular department, purpose, or database.  As a result, a SAS® data analyst often works with multiple servers, each with its own data storage…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now