Question

Reading/Writing BLOB fields

Asked by: alternativeit

Hi all,

I've been struggling with this problem for some time, and thought the IB gurus here may be able to assist.

Basically, I have a table in an Interbase 6 database that contains two columns; table structure is below.

CREATE TABLE INBOXBLOB
(
  INBLOBKEY      VARCHAR(16) NOT NULL,
  INBLOB      BLOB SUB_TYPE 0 SEGMENT SIZE 80,
CONSTRAINT INBOXBLOBPK PRIMARY KEY (INBLOBKEY)
);

The INBLOBKEY column contains file names; these are referenced back to another table in the DB for identification purposes. The INBLOB column contains a TIFF image, which is programatically accessed from the application that uses this DB and displayed within the GUI.

What I want to do is write a script or app that will loop over all of the rows in the table and extract the data from the INBLOB column out to a file within the filesystem (with the filename from the INBLOBKEY column).

I'll then use a batch graphics conversion app to compress these TIFF's (I don't need any help with this step).

Once all the images have been a) dumped from the table and b) compressed, I then want to run a process of looping over the list of TIFF's within the filesystem, and inserting the image back into a new (clean) DB table, with the same structure as the original table.

I've got a solid programming history, and am comfortable with the filesystem-related aspects of this process. I also have a good experience with T-SQL, but what  I DON'T have much experience with is Interbase, specifically BLOB fields.

What I'm looking for is a code example of how to acheive the steps of:

a) exporting the blob fields from the DB to the filesystem
b) inserting the files from the filesystem back into a BLOB field within a table

As for the language, I'd be happy with VB, VBScript, JScript, PHP, ASP, or Perl... or <other>, if that's what you know.  I just want to make this happen :)  (I'm currently dealing with databases of 10-20GB in size, which are full of uncompressed TIFF's; If I can get the above process working, I'm looking at reducing those database sizes by around 90%!!!)

Cheers all...
alternativeit

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2005-08-11 at 17:48:36ID21524611
Tags

blob

Topic

Interbase / Firebird Database

Participating Experts
2
Points
500
Comments
4

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Non-blob column in table required to perform operation
    Hi, I am developing an application with Delphi 5 and Interbas 6, and there is a table with a blob column and when I try to post a new register in the table with the Delphi application, it generates the error: Non-blob column in table required to perform operation But somet...
  2. REading a blob field in the SQL
    I have few blob fields in my interbase database. They only store cahracter data. I want to read them along with the other normal fields so that I can export them into Excel or something. When I use the normal SQL with the blob field name included, the data is not comming( no ...
  3. IB 5.6 update text in blob
    Hello I have a problem with update text in ib 5.6 read is no problem. first I tried this: Set RS=myadoDBconn.Execute("UPDATE PMMEMO SET TEKST='jaap'") I get the error Error Type: Microsoft OLE DB Provider for ODBC Drivers (0x80004005) [INTERSOLV][ODBC InterBase ...
  4. WHERE part in IB sql
    I am implementing row-level security. How? I have Owner_id field (VARCHAR) where I store comma-separated list of USER names like 'SYSDBA', 'JOHN', 'BHANZ' so when I am looking for records that user is supposed to see I do WHERE Owner_id LIKE USER. Reason to store QUOTED User...
  5. Insert Blob field for Interbase
    Hi all... As through Delphi using IB components to add the text in Blob a field. Whether it is possible to add through ' insert into ' when creates inquiry. Thank

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: NickUpsonPosted on 2005-08-12 at 14:23:38ID: 14664724

Please start by looking at the API Guide and the Embedded SQL Guide from the interbase 6 manual set on writing blob filters.

you should be able to write one that does the compression so that you just have to use it to update the blob fields, avoiding the export and insert.

Please bear in mind that intberase 6 is fairly old and has several known bugs, consider upgrading to interbase 7.5 (Borland) or Firebird (1.5)
from www.ibphoenix.com (OpenSource)

 

by: alternativeitPosted on 2005-08-15 at 01:48:51ID: 14673114

Thanks NickUpson... comments appreciated.

I've just found the the guides you referred to on the 'net (thanks Google!) -- I'm working with a version of Interbase that was distributed with an application that depends on it, so I don't have the full docs available. They seem useful, but I'm not a C programmer, and I was hoping for something a little more... immediate... than having to pick up another language. Not to mention I don't have the IDE.

We'd love to move away from IB6, but unfortunately we are forced to wait for our software supplier to stop procrastinating and validate IB7.5 for the application in question. So for now I'm stuck with IB6.

If you, or anyone else, has some code samples for one of the languages I mentioned above, please share them! Obviously, if I can get the compression done without needing to export/import, that'd be great - I hadn't considered this as an option.

Cheers
alternativeit :)

 

by: kacorPosted on 2005-08-16 at 02:27:11ID: 14681108

In IB the following commands are allowed for BLOB fields: SELECT, UPDATE, INSERT and DELETE. If you'd like to know the BLOB identifier you can execute a query which gives the BLOB field (Description) as part of the query:
 
SELECT Name, Description
      FROM Products;
 
The commands INSERT and  UPDATE are not usable directly to insert or modify the BLOB data. Embedded SQL is used to manipulate Blob data in these ways. To insert or update Blob data, we must declare insert or read Blob cursors. Blob cursors can only be associated with a single BLOB column. Several host variables are declared to store the BLOB ID, the BLOB segment data, and the length of the segment (CR_ --> for identifying CursoR).
 
EXEC SQL
      BEGIN DECLARE SECTION;
      BASED ON Products.Description CRblobID;
      BASED ON Products.Description.SEGMENT CRBlobSegmentBuffer;
      unsigned short CRBlobSegmentLength;

EXEC SQL
      END DECLARE SECTION;

The following step is declaring and opening a BLOB insert cursor to be able to insert the BLOB data. The BLOB ID is stored in the host variable CRblobID.

EXEC SQL
      DECLARE BlobCursor FOR INSERT BLOB ProductDescription INTO Products;

EXEC SQL
      OPEN BlobCursor INTO :CRblobID;
 
The next INSERT CURSOR statement is used to insert in segments the BLOB data (stored in the buffer called CRblobID_buf) into the BLOB insert cursor.
This commands should be repeated until all segments will be written into the table. For each segment of data stored in the segment buffer you have to calculate in your program the length of the segment (CRBlobSegmentLength).
 
EXEC SQL
      INSERT CURSOR BlobCursor
      VALUES(:CRblobID :CRBlobSegmentBuffer);
 
After succesful written of all segments you can close the BLOB cursor.

EXEC SQL
      CLOSE BlobCursor;

We can now use the INSERT statement to insert a new row into the Products table:

EXEC SQL
      INSERT INTO Products (Name, Description)
            VALUES (’Metall Case’, :CRblobID);

To update a BLOB is an other case. First we have to create a new BLOB then read the earlier data into buffer. When all data are in the buffer you can modify and then insert the changed data into this new BLOB.

In your program you read the old data segments into the CRBlobSegmentBuffer then calculate the CRBlobSegmentLength. You can modify this data segment as needed then you insert this changed segment into the cursor using the insert cursor command:


EXEC SQL
      INSERT CURSOR BlobCursor
            VALUES(:CRBlobSegmentBuffer, :CRBlobSegmentLength);

After you changed all and you witten all segments into the buffer you can close the BlobCursor as above.

EXEC SQL
      CLOSE BlobCursor;

The cursor is created with the changed BLOB data. Now you can update the BLOB by replacing the original BLOB data.

EXEC SQL
      UPDATE Products
            SET Description = :CRblobID;
      WHERE CURRENT OF TableCursor;

The TableCursor points to the target row in the Products table.

You can find more detailled on working with BLOB data in Data Definition Guide Chapter 4, Programmer's Guide Ch. 8 and in Developer’s Guide Ch. 6.

I hope this gives some support. If you don't have them I'll give where you can download from.

wbr Janos

 

by: alternativeitPosted on 2005-08-16 at 17:28:56ID: 14688092

Thanks guys.... managed to work this out myself using VB.NET and a whole lotta spare time ;)

50/50 split for pointing me in some helpful directions.

Cheers!

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...