1

I am using an ANSI C compiler (LabWindows/CVI version 2010) to extract integer, string and floating point data from an existing Access 2010 database with good success. However, I have not been able to extract image data stored as long binary data into files (.jpg, or .tiff). I suspect this is not a difficult task once the technique is known, I just do not have experience with the code or technique to do this. Any help would be appreciated.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
ryyker
  • 22,849
  • 3
  • 43
  • 87
  • What do you want to extract? I mean, you want to store numbers' graphic representation in a JPG file? –  Jan 23 '12 at 18:34
  • Which data access library are you using? –  Jan 23 '12 at 18:37
  • Without a `jpeg` or `tiff` library, this is not a trivial task. Look into libjepg. – Dave Jan 23 '12 at 18:52
  • H2CO3,My objective is to extract the data, which is stored as long binary data, into its native file type, i.e. either a .jpg file, or as a tiff file. I can read an enumerated value in a different column of the same table to determine what the native file type is, .jpg or .tiff. – ryyker Jan 23 '12 at 19:01
  • Dave, Thanks, I will look into libjepg. I am assuming though (maybe incorrectly) that the process of extracting this binary data from a database would be synonymous in some ways to writing or reading binary data to/from a file in C, i.e. using FILE *fp = fopen("c:\\filename.jpg", "rb+"); I am lost though at the part about getting the binary data from the database into a C type FILE *. – ryyker Jan 23 '12 at 19:07
  • To Martin Broadhurst, National Instruments, LabWindows/CVI has an SQL Toolkit extension for working with databases. It uses a fairly comprehesive family of functions including int handle =DBConnect(ConnectString), DBBindInt(...);, DBBindBinary(...) etc. – ryyker Jan 23 '12 at 19:12
  • If the JPEG data is stored as binary data, all you have to do is copy it from the binary field into a file. `libjpeg`, etc. shouldn't come into it anywhere. This is a question about your SQL Toolkit and how to get binary data out. It's got nothing to do with ANSI C, JPEG or TIFF. – Roger Lipscombe Jan 23 '12 at 19:35
  • To Roger Lipscombe: thanks Roger, I agree with your observation, It is the matter of getting the data from the database into a buffer that has baffled me. However, It looks as if Martin has identified a good option that I did not know existed within the library I was already starting to use. (DBGetColBinaryBuffer() ). – ryyker Jan 23 '12 at 22:28

1 Answers1

1

I would expect that if you retrieve all of the data in the image column successfully, you only need to write it to a file using fwrite().

The usual access pattern for retrieving long data from a column is to use a function that gets it one chunk at a time. This is how the ODBC function SQLGetData works; you pass it a fixed-length buffer and length, and its return value indicates that the data has been truncated, so you write the data you have to the file and then call it again until it returns a success code.

Looking at the documentation for National Instruments LabWindows/CVI SQL Toolkit, the DBGetColBinaryBuffer() function can return the code -1, DB_TRUNCATION, which is described as "The buffer passed in to hold a result is not large enough to hold the result. A partial result has been returned in the buffer.".

I would guess that DBGetColBinaryBuffer() is designed to be used in a loop, and if you do so and write the partial results to a file, you will end up with a valid image.

  • Martin Broadhurst, DBGetColBinaryBuffer() looks like it may do the trick. I will try it as soon as I am able to get back to this project and let you know the results. Thanks! – ryyker Jan 23 '12 at 22:19
  • Thanks, took realizing the BLOB was an encrypted file before finally figuring out how to read it, but in the final steps, your suggestion was right on. – ryyker Jul 23 '13 at 00:02