You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Germán Rivas (JIRA)" <ji...@apache.org> on 2016/03/03 15:24:18 UTC

[jira] [Issue Comment Deleted] (GROOVY-7082) groovy.sql: TINYINT(1) returns boolean instead of numeric

     [ https://issues.apache.org/jira/browse/GROOVY-7082?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Germán Rivas updated GROOVY-7082:
---------------------------------
    Comment: was deleted

(was: I faced the same problem and after checking rows metadata I found that although mysqltype was set to 1 (TINYINT) jdbc sql type was set to -7 (bit) instead of -6 (tinyint).
This seems to be related to mysql driver. When doing the same query using pure jdbc, I found that although in the resultset metadata the ColumnTypeName was "TINYINT" the column type code was -7 (bit). I am not sure what is the motivation for such a behavior.
My work around this on groovy was:
{code}
def rows = sql.rows(query, queryBindings) {
                meta ->
                    meta.fields.each { it ->
                        if (it.mysqlType == 1) {
                            it.sqlType = -6
                        }
                    }
            }
{code})

> groovy.sql: TINYINT(1) returns boolean instead of numeric
> ---------------------------------------------------------
>
>                 Key: GROOVY-7082
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7082
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Gordon Myers
>
> I have a column in MySQL that is TINYINT(1) and is used for storing the ISO-8601 "day of week" (i.e. an integer in the range 1 to 7). However, when I run a simple SELECT query using groovy.sql, it always comes back as a boolean true. I don't want groovy typecasting my TINYINT(1) to a boolean. Is this a bug or just a (mis)configuration option?
> Example:
> {code}
> /*
> -- Sample table structure
> CREATE TABLE `records` (`dayOfWeek` TINYINT(1) UNSIGNED NOT NULL, PRIMARY KEY (`dayOfWeek`));
> INSERT INTO `records` (`dayOfWeek`) VALUES (1), (2), (3);
> */
> final String query = "SELECT `dayOfWeek` FROM `records`"
> final results = groovySql.rows(query)
> --> returns true; true; true in Groovy
> --> should return 1; 2; 3
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)