Opening Blob Data stored in Sqlite as a File with Tcl/Tk -


I use the following tcl code to store a file from my desktop in the form of Blob data in a squat database I'm using ( $ file text is a path to a text file):

  sqlite3 db docs.db set fileID [open $ fileText RDONLY] fconfigure $ FileID-translation binary set content [$ fileID] close $ fileID db eval {Enter in document (DOC) values ​​($ content)} db off  

Read and write me BLOB data has received a number of resources about how to open, but I could not find any resources on the opening of the BLOB data file. For example, if $ fileText was a PDF, then how do I open it with Sqlite as a PDF? When you say "open as a PDF", I believe that you mean that you want some external programs Can I view the data as a file? There is only one way to do this:

  1. Do some clever shenanigans with the user-mode filesystem on Linux (or equivalent on your OS) so that the database can actually be mounted, or
  2. Copy the data to a temporary file with the correct name from the database (hint: keep it as a separate column in that table).

A webserver, but it is actually second with a browser in the mix; Data is still copied.

On the other hand, if you want to do that, the data is in the form of a stream that you can read or write from Tcl, what you need in the sqlite3 package:

  DBCMD   incrblob ?  - Radonly ? ?  db ?  table column row  

which gives a standard channel handle (though the OS is not backed up by the handle, so be careful that exec ). [Edit]: Get data here (replace ... with a clause to get the correct line):

  Open # db sqlite3 db To open the file docs.db # file ID, open [open $ file text] fconfigure $ fileID-translate binary #blob db eval type {document select document from where ... border1} row {puts - Nineway line $ fileID $ line (doctor)} # We did it! Close $ fileID db close  

Do not worry about the size of the blob; Tcl sqlite3 package efficiently passes around if you are still worried, then this is the second way (again, to change you properly ... Open the file to write to set the file to be set to [D.DB # db squid 3D dbx]:


Comments