Bug #89

instance SqlType Bool, fromSql (SqlString x) incorrect

Added by Tomáš Janoušek 119 days ago. Updated 116 days ago.

Status :Feedback Start :08/06/2008
Priority :Normal Due date :
Assigned to :- % Done :

0%

Category :-
Target version :1.1.5.0
Resolution :


Description

The fromSql (SqlString x) case does not handle "0" and "1", as returned by MySQL. One has to use fromSql.iToSql.fromSql instead.

Associated revisions

Revision ed98a2220f5a1436b4df42d8645365c314fa3965
Added by John Goerzen 116 days ago

Accept '0' and '1' as False and True for SqlValue Bools

refs #89

History

08/06/2008 10:04 AM - Tomáš Janoušek

Also, mysql does not handle True/False as returned by fromSql in bindCol (Statement.hsc, HDBC-odbc-1.1.4.4), so I have to use iToSql.fromSql.toSql. Please, fix it someday :).

08/07/2008 09:36 PM - John Goerzen

  • Status changed from New to Feedback

Hi,

I'm not quite sure I'm following the problem. Could you include a brief example program that demonstrates it, and explain what you expected and what you received? It seems that fromSql on a string, even if it is "0", should return a String just fine; or were you using it in some other context?

08/08/2008 02:58 AM - Tomáš Janoušek

I'm using it to store/retrieve a Bool from a MySQL database. The column was created as bool, which maps to tinyint(1) in MySQL.

So, I call the quickQuery function and pass it (toSql True). bindCol calls fromSql on this value, getting "True", which MySQL is unable to parse and treats it as zero.

Then, when I do a SELECT query, I get lists of SqlString values. One of them, the "bool" column, contains "1". Calling fromSql (SqlString "1") :: Bool results in an error.

08/08/2008 04:13 PM - John Goerzen

OK, I think I understand the problem.

Sigh to mysql.

Over at http://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html, I see:

"We intend to implement full boolean type handling, in accordance with standard SQL, in a future MySQL release. "

It will be fairly easy to make the HDBC parser for Bool accept 0 and 1 as true or false.

Being able to pass 0 or 1 instead of True or False to MySQL is potentially more complicated.

Over at http://www.ncb.ernet.in/education/modules/dbms/SQL99/ansi-iso-9075-1-1999.pdf we see that SQL boolean columns accept 'true' or 'false', which is what HDBC is giving them. Strangely, the MySQL URL above suggests that MySQL honors the TRUE and FALSE aliases, so we ought to work. What version of MySQL do you have?

I will implement the 0 and 1 handling in the parser shortly, but the question of what to send to MySQL could be trickier, especially since the example you sent suggests it isn't complying with its documentation.

08/08/2008 04:22 PM - Tomáš Janoušek

The server version is 5.0.62.

Using the mysql command line client, true works, but 'true' does not.

Also available in: Atom PDF