Skip to content

Commit 7a78fd3

Browse files
committed
a couple of fixes for 64bit platforms
1 parent 3be91f8 commit 7a78fd3

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

ext/mysql2/result.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ static rb_encoding *binaryEncoding;
2626
* (0*31557600) + (1*2592000) + (1*86400) + (0*3600) + (0*60) + 0
2727
*/
2828
#define MYSQL2_MIN_TIME 2678400ULL
29+
#elif SIZEOF_INT < SIZEOF_LONG // 64bit Ruby 1.8
30+
/* 0139-1-1 00:00:00 UTC
31+
*
32+
* (139*31557600) + (1*2592000) + (1*86400) + (0*3600) + (0*60) + 0
33+
*/
34+
#define MYSQL2_MIN_TIME 4389184800ULL
2935
#elif defined(NEGATIVE_TIME_T)
3036
/* 1901-12-13 20:45:52 UTC : The oldest time in 32-bit signed time_t.
3137
*

spec/mysql2/result_spec.rb

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,31 @@
200200
r.first['test'].class.should eql(klass)
201201
end
202202
elsif 1.size == 8 # 64bit
203-
it "should return Time when timestamp is < 1901-12-13 20:45:52" do
204-
r = @client.query("SELECT CAST('1901-12-13 20:45:51' AS DATETIME) as test")
205-
r.first['test'].class.should eql(Time)
206-
end
203+
if RUBY_VERSION =~ /1.9/
204+
it "should return Time when timestamp is < 1901-12-13 20:45:52" do
205+
r = @client.query("SELECT CAST('1901-12-13 20:45:51' AS DATETIME) as test")
206+
r.first['test'].class.should eql(Time)
207+
end
207208

208-
it "should return Time when timestamp is > 2038-01-19T03:14:07" do
209-
r = @client.query("SELECT CAST('2038-01-19 03:14:08' AS DATETIME) as test")
210-
r.first['test'].class.should eql(Time)
209+
it "should return Time when timestamp is > 2038-01-19T03:14:07" do
210+
r = @client.query("SELECT CAST('2038-01-19 03:14:08' AS DATETIME) as test")
211+
r.first['test'].class.should eql(Time)
212+
end
213+
else
214+
it "should return Time when timestamp is > 0138-12-31 11:59:59" do
215+
r = @client.query("SELECT CAST('0139-1-1 00:00:00' AS DATETIME) as test")
216+
r.first['test'].class.should eql(Time)
217+
end
218+
219+
it "should return DateTime when timestamp is < 0139-1-1T00:00:00" do
220+
r = @client.query("SELECT CAST('0138-12-31 11:59:59' AS DATETIME) as test")
221+
r.first['test'].class.should eql(DateTime)
222+
end
223+
224+
it "should return Time when timestamp is > 2038-01-19T03:14:07" do
225+
r = @client.query("SELECT CAST('2038-01-19 03:14:08' AS DATETIME) as test")
226+
r.first['test'].class.should eql(Time)
227+
end
211228
end
212229
end
213230

0 commit comments

Comments
 (0)