Solved

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

Posted on 2008-10-31
1
1,242 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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction: Often, when running a query with joins, the results show up "duplicates", and often, those duplicates can be "eliminated" in the results using DISTINCT, for example. Using DISTINCT is simple: just add it after the SELECT keyword, an…
I guess that all of us know that caching the data usually increase the performance, but I worried if all of us are aware about the risk that caching the data provides and how to minimize this.  That’s the reason why I decided to write this short art…
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…

744 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

17 Experts available now in Live!

Get 1:1 Help Now