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

  • Home
  • SEARCH
  • 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 7782871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:40:33+00:00 2026-06-01T19:40:33+00:00

I use SQLite3 and have a table called blobs that stores content and *hash_value*.

  • 0

I use SQLite3 and have a table called blobs that stores content and *hash_value*.

Here is the schema:

CREATE TABLE "blobs" (
  "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  "content" blob,
  "hash_value" text,
  "created_at" datetime NOT NULL,
  "updated_at" datetime NOT NULL
);

Now I inserted some data. that looks like this:

1|--- foo
...
|34dc86f45b3dc92b352fd45f525192c0|2012-04-09 17:02:54.219504|2012-04-09 17:02:54.219504

And I tried the following two queries:

  • select * from blobs where hash_value = '34dc86f45b3dc92b352fd45f525192c0';
  • select * from blobs where hash_value LIKE '34dc86f45b3dc92b352fd45f525192c0';

The first does not work, but the second one does. I do not understand why the = operator does not work.

I tried to break this down to a simple example where my hash is just 'abc' and = works. I mean this string is hardly too long.

EDIT

Ok I actually narrowed it down to this:

  • I am using Ruby to generate the hash like this Digest::MD5.hexdigest("foobar")
  • This generates a string like this: '3858f62230ac3c915f300c664312c63f'
  • My test look somewhat like this: b = Blob.new(...);b.save!;Blob.find_by_hash(b.hash)
  • And the find_hash is Blob.find(:all, :conditions => ["hash_value = ?", hash_value])
  • It works if I set the hash manually to '3858f62230ac3c915f300c664312c63f' (hardcoded string).
  • But if this string is generated I get the following error:

    Failure/Error: Blob.find_by_hash(b.hash_value)[0].load.should == txt
     ArgumentError: wrong number of arguments (0 for 1)
    

And I cannot query SQLite3 as stated above.

Solution

The solution is:

  • Instead of using Digest::MD5.hexdigest(“foobar”) use Digest::MD5.base64digest(“foobar”)

I do not know why sqlite3 has problems with hexdigest but there definitively is something fishy about this.

  • 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-06-01T19:40:34+00:00Added an answer on June 1, 2026 at 7:40 pm

    The difference between the two is encoding:

    Digest::MD5.hexdigest("foobar").encoding #=>  #<Encoding:ASCII-8BIT> 
    Digest::MD5.base64digest("foobar").encoding #=> #<Encoding:US-ASCII> 
    

    I don’t think there’s a particular reason why hexdigest has the 8bit encoding (which effectively means ‘this is raw data’, but that’s what ruby seems to do. When the ruby sqlite3 driver sees something with the ascii-8bit encoding it binds the value to the query as a blob, rather than as text. This in turn affects how sqlite3 does the comparison (although I don’t understand exactly how).

    See also this question

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple SQLite table called message: sequence INTEGER PRIMARY KEY type TEXT
I have a SQlite3 table that has typeless columns like in this example: CREATE
I am learning how to use sqlite3 in python. I have a simple table
I have an app that needs to be able use either an sqlite3 datebase
I am trying to use sqlite3 in cygwin and I notice that the backspace
I have a table of events (in a sqlite3 database for what it's worth)
I have a large sql dump file ... with multiple CREATE TABLE and INSERT
What would be faster; searching a sqlite3 database table for a row whose primary
How is it possible? I have a simple C++ app that is using SQLite3
In my iphone app I use a sqlite db. I have an icon that

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.