From: David Landrith Date: 2003-01-08T02:50:36+09:00 Subject: bug in Ruby DBI --Apple-Mail-6--769876791 Content-Transfer-Encoding: 7bit Content-Type: text/plain; delsp=yes; charset=US-ASCII; format=flowed I am using a dateTime field in mysql, the default value of which is 0000-00-00 00:00:00, and I am running into the a problem with dbi/sql.rb, my version of which reads $Id: sql.rb,v 1.12 2002/02/06 14:24:21 in the file header. The problem and (a duplicatable method of generating it) is as follows: Say I have a database table called 'ppl' that looks like this: +--------+----------------------+-----+--------------------- +----------------+ | Field | Type | Key | Default | Extra | +--------+----------------------+-----+--------------------- +----------------+ | ID | smallint(5) unsigned | PRI | NULL | auto_increment | | name | char(8) | | | | | mdate | datetime | | 0000-00-00 00:00:00 | | +--------+----------------------+-----+--------------------- +----------------+ Then I insert a row as follows: insert into ppl (name) values ('tom') I'll get the following row: +----+------+---------------------+ | ID | name | mdate | +----+------+---------------------+ | 1 | Tom | 0000-00-00 00:00:00 | +----+------+---------------------+ Now, say I try to access this via ruby and load in into an array of DBI::Rows as follows: dbh = DBI.connect(dsn, user, auth, params) a = Array.new() ssh = dbh.execute("select ID, name, mdate from ppl") sth.each { |val| a << val } sth.finish dbh.disconnect Executing this gets the following error: /usr/lib/site_ruby/1.6/dbi/sql.rb:59:in `gm': argument out of range (ArgumentError) from /usr/lib/site_ruby/1.6/dbi/sql.rb:59:in `as_timestamp' from /usr/lib/site_ruby/1.6/dbi/sql.rb:79:in `send' from /usr/lib/site_ruby/1.6/dbi/sql.rb:79:in `coerce' from /usr/lib/site_ruby/1.6/DBD/Mysql/Mysql.rb:377:in `fill_array' from /usr/lib/site_ruby/1.6/DBD/Mysql/Mysql.rb:374:in `each_with_index' from /usr/lib/site_ruby/1.6/DBD/Mysql/Mysql.rb:374:in `each' from /usr/lib/site_ruby/1.6/DBD/Mysql/Mysql.rb:374:in `each_with_index' from /usr/lib/site_ruby/1.6/DBD/Mysql/Mysql.rb:374:in `fill_array' from /usr/lib/site_ruby/1.6/DBD/Mysql/Mysql.rb:384:in `fetch' from /usr/lib/site_ruby/1.6/dbi/dbi.rb:786:in `fetch' from /usr/lib/site_ruby/1.6/dbi/dbi.rb:811:in `each' There erroneous line in "/usr/lib/site_ruby/1.6/dbi/sql.rb" is: time = ::Time.gm(*(ary[0,6])) It appears that the problem is being caused by the zero values in the mdate field. I changed the mdate field as follows: update ppl set mdate="2003-1-2 12:16:31" And this fixed the problem. ------------------------------------------------------- David King Landrith (w) 617.227.4469x213 (h) 617.696.7133 One useless man is a disgrace, two are called a law firm, and three or more become a congress -- John Adams ------------------------------------------------------- public key available upon request --Apple-Mail-6--769876791 content-type: application/pgp-signature; x-mac-type=70674453; name=PGP.sig content-disposition: inline content-transfer-encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (Darwin) iD8DBQE+GxNpRdirey0+rJARAhNvAKCczW5F5o40nSN106BGij0yS2CDCQCffjg/ ff/n0qPPPnJorE0YS82nf4A= =WF62 -----END PGP SIGNATURE----- --Apple-Mail-6--769876791--