Skip to content

Instantly share code, notes, and snippets.

@smathy
Created May 23, 2009 01:27
Show Gist options
  • Save smathy/116460 to your computer and use it in GitHub Desktop.
Save smathy/116460 to your computer and use it in GitHub Desktop.
Scary SQLite bug
#!/usr/bin/env ruby
require 'rubygems'
require 'sqlite'
file = 'foo.sqlite'
File.unlink(file)
db = SQLite::Database.new( file )
db.execute( "CREATE TABLE foos ( id INTEGER PRIMARY KEY NOT NULL, name VARCHAR(255))" )
x = 2 ** 30 - 1
y = 2 ** 30
[ x, y ].each do |v|
db.execute( "INSERT INTO foos ( id, name ) VALUES ( #{v}, 'Foobar' )" )
db.execute( "SELECT last_insert_rowid()") do |r|
puts "#{db.last_insert_row_id} should equal #{r}"
end
end
db.close
I'm on OSX:
sqlite 2.8.17 (MacPorts)
sqlite-ruby 2.2.3 (rubygem)
The above produces this:
1073741823 should equal 1073741823
-1073741824 should equal 1073741824
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment