Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 804595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:56:42+00:00 2026-05-14T23:56:42+00:00

I am using the following tcl code to store a file from my deskstop

  • 0

I am using the following tcl code to store a file from my deskstop into a Sqlite database as blob data ($fileText is a path to a text file):

sqlite3 db Docs.db
set fileID [open $fileText RDONLY]
fconfigure $fileID -translation binary
set content [read $fileID]
close $fileID
db eval {insert into Document (Doc) VALUES ($content)}
db close

I have found many resources on how to open the blob data to read and write to it, but I cannot find any resources on opening the blob data as a file. For example, if $fileText was a pdf, how would I open it, from Sqlite, as a pdf?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T23:56:43+00:00Added an answer on May 14, 2026 at 11:56 pm

    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:

    1. 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
    2. 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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using following code to get bitmap from url. This function is used
Android: I am using following code to insert image into album According to description
I created a DB using following code. Dim conn As New SqlConnection(Server=.\SQLExpress;Data Source=;Integrated Security=SSPI)
I am using following code to attach my database to SQL Server. The problem
I am using following code to detach my DB from SQL Server express. Please
Using following code: db.changes({'include_docs':true}).on('response', function (res) { res.on('data', function (change) { console.log(change); }); });
I am using following code I found from in the web to authenticate users
I am using following PHP code to connect to MS Access database: $odb_conn =
I am using following code. <% response.addHeader(Cache-Control,no-cache); response.addHeader(Pragma,no-cache,no-store,private,must-revalidate,max-stale=0,post-check=0,pre-check=0 ); response.addDateHeader (Expires, 0); %> It
im using following code to send sms to all the students in the database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.