Created
May 23, 2009 01:27
-
-
Save smathy/116460 to your computer and use it in GitHub Desktop.
Scary SQLite bug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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