Skip to content

Commit 6a1169d

Browse files
committed
Merge pull request #442 from sodabrew/large_insert_id
Test for insert_id above 32-bit max
2 parents 9210a9b + aa768da commit 6a1169d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

spec/mysql2/client_spec.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ def connect *args
647647
context 'write operations api' do
648648
before(:each) do
649649
@client.query "USE test"
650-
@client.query "CREATE TABLE IF NOT EXISTS lastIdTest (`id` int(11) NOT NULL AUTO_INCREMENT, blah INT(11), PRIMARY KEY (`id`))"
650+
@client.query "CREATE TABLE IF NOT EXISTS lastIdTest (`id` BIGINT NOT NULL AUTO_INCREMENT, blah INT(11), PRIMARY KEY (`id`))"
651651
end
652652

653653
after(:each) do
@@ -674,6 +674,15 @@ def connect *args
674674
@client.query "UPDATE lastIdTest SET blah=4321 WHERE id=1"
675675
@client.affected_rows.should eql(1)
676676
end
677+
678+
it "#last_id should handle BIGINT auto-increment ids above 32 bits" do
679+
# The id column type must be BIGINT. Surprise: INT(x) is limited to 32-bits for all values of x.
680+
# Insert a row with a given ID, this should raise the auto-increment state
681+
@client.query "INSERT INTO lastIdTest (id, blah) VALUES (5000000000, 5000)"
682+
@client.last_id.should eql(5000000000)
683+
@client.query "INSERT INTO lastIdTest (blah) VALUES (5001)"
684+
@client.last_id.should eql(5000000001)
685+
end
677686
end
678687

679688
it "should respond to #thread_id" do

0 commit comments

Comments
 (0)