?
Solved

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

Posted on 2008-10-31
1
Medium Priority
?
1,273 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 4

Accepted Solution

by:
dprochownik earned 1000 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

752 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