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 6958925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:12:14+00:00 2026-05-27T15:12:14+00:00

I have a binary column which contains 256-bit checksums. I can store the checksums

  • 0

I have a binary column which contains 256-bit checksums. I can store the checksums ok, but when I try to query via the checksum, nothing is returned.

d = Digest::SHA2.new
d.update "large str i'm creating the hash with"
begin
    codebase = Codebase.find_or_create_by_checksum(d.digest)
rescue ActiveRecord::StatementInvalid => e
    # handle duplicate record error
end

I’ve tried where and different versions of find. Nothing returns. When I use find_or_create_by_checksum, since it doesn’t find anything it tries to create it and an exception is raised since I have a uniq index on the checksum column, but still I need to be able to get the record with the matching checksum.

    create_table :codebases do |t|
        t.binary :checksum, :null => false, :limit => 32
    end

    add_index :codebases, :checksum, :unique => true, :name => 'name_of_the_codebas_uniq_index'

Anybody know how to do 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-05-27T15:12:15+00:00Added an answer on May 27, 2026 at 3:12 pm

    So if its binary on the database, I couldn’t reproduce:

    migration:

    class Checksum < ActiveRecord::Migration
      def up
        create_table :checksums do |t|
            t.binary :checksum, :null => false, :limit => 32
        end
      end
    
      def down
      end
    end
    

    And then trying it on the rails console:

    ruby-1.9.2-p290 :009 > Checksum.create(:checksum => digest.digest)
      SQL (0.4ms)  INSERT INTO "checksums" ("checksum") VALUES (?)  [["checksum", ",&\xB4kh\xFF\xC6\x8F\xF9\x9BE<\x1D0A4\x13B-pd\x83\xBF\xA0\xF9\x8A^\x88bf\xE7\xAE"]]
     => #<Checksum id: 1, checksum: ",&\xB4kh\xFF\xC6\x8F\xF9\x9BE<\x1D0A4\x13B-pd\x83\xBF\xA0\xF9\x8A^\x88bf\xE7\xAE"> 
    
    ruby-1.9.2-p290 :010 > Checksum.first
      Checksum Load (0.2ms)  SELECT "checksums".* FROM "checksums" LIMIT 1
     => #<Checksum id: 1, checksum: ",&\xB4kh\xFF\xC6\x8F\xF9\x9BE<\x1D0A4\x13B-pd\x83\xBF\xA0\xF9\x8A^\x88bf\xE7\xAE"> 
    
    ruby-1.9.2-p290 :011 > Checksum.find_by_checksum(digest.digest)
      Checksum Load (0.1ms)  SELECT "checksums".* FROM "checksums" WHERE "checksums"."checksum" = x'2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae' LIMIT 1
     => #<Checksum id: 1, checksum: ",&\xB4kh\xFF\xC6\x8F\xF9\x9BE<\x1D0A4\x13B-pd\x83\xBF\xA0\xF9\x8A^\x88bf\xE7\xAE"> 
    

    So it works as expected…..

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

Sidebar

Related Questions

I have a table with a binary column which stores files of a number
I have a database with binary objects that contain documents. A separate column contains
I have a MySQL DB which stores data into a column of type 'binary'
I have binary data in a file that I can read into a byte
I have 4 binary bits Bit 3 Bit 2 Bit 1 Bit 0 Normally
I have a binary tree where each node can have a value. I want
I have a binary search loop which gets hit many times in the execution
How can I shift a column in 8x8 area? For example, I have this
I have following procedure which is filling up null values in a column. The
In one SqLite table, I have a BLOB column for saving images (or binary

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.