When you say “open as a PDF”, I assume that you mean that you want some external program to see the data as a file? The only ways to do that are either:
- Do some clever shenanigans with user-mode filesystems on Linux (or the equivalent on your OS) so that the database can be actually mounted, or
- Copy the data from the database into a temporary file with the right name (hint: keep that as a separate column in that table).
There's also presenting it all as a webserver, but that's really the second with a browser in the mix; the data is still copied.
On the other hand, if all you want to do is have the data as a stream that you can read or write from Tcl, the sqlite3 package has what you need:
dbcmd incrblob ?-readonly? ?db? table column rowid
Which returns a standard channel handle (though not one backed up by an OS handle, so be careful if using as a redirection with exec
).
[EDIT]: Here's how to getthe data out (replace ...
with a clause to get the right row, of course):
# Open the DB
sqlite3 db Docs.db
# Open the file to write to
set fileID [open $fileText w]
fconfigure $fileID -translation binary
# Write the BLOB
db eval {SELECT Doc FROM Document WHERE ... LIMIT 1} row {
puts -nonewline $fileID $row(Doc)
}
# We're done!
close $fileID
db close
Don't worry about the size of the BLOB; the Tcl sqlite3
package passes it around efficiently. If you're still concerned, here's the other way (again, you'll need to replace ...
appropriately):
# Open the DB
sqlite3 db Docs.db
# Open the file to write to
set fileOut [open $fileText w]
fconfigure $fileOut -translation binary
# Get the BLOB as a (read-only) channel
set fdBlob [db incrblob -readonly Document Doc ...]
fconfigure $fdBlob -translation binary
# Do the copy
fcopy $fileOut $fdBlob
# We're done!
close $fdBlob
close $fileOut
db close