Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mysql 1 and 0 are incorrectly automatically converted to true and false. #47907

Closed
xys2015 opened this issue Sep 13, 2024 · 1 comment
Closed

Comments

@xys2015
Copy link

xys2015 commented Sep 13, 2024

Describe the bug

image

use_type tinyint(1)

To Reproduce

  1. Go to SQL Query
  2. create test table and include filed 'use_type tinyint(1)'
  3. select * from xxx_table
  4. see error

Expected behavior

0 or 1

Logs

No response

Information about your Metabase installation

{
  "browser-info": {
    "language": "en-US",
    "platform": "MacIntel",
    "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36",
    "vendor": "Google Inc."
  },
  "metabase-info": {
    "databases": [
      "h2",
      "mysql"
    ],
    "run-mode": "prod",
    "plan-alias": "",
    "version": {
      "date": "2024-09-06",
      "tag": "v0.50.24.4",
      "hash": "3b502f8"
    },
    "settings": {
      "report-timezone": "Asia/Shanghai"
    },
    "hosting-env": "unknown",
    "application-database": "h2",
    "application-database-details": {
      "database": {
        "name": "H2",
        "version": "2.1.214 (2022-06-13)"
      },
      "jdbc-driver": {
        "name": "H2 JDBC Driver",
        "version": "2.1.214 (2022-06-13)"
      }
    }
  },
  "system-info": {
    "file.encoding": "UTF-8",
    "java.runtime.name": "OpenJDK Runtime Environment",
    "java.runtime.version": "11.0.24+8",
    "java.vendor": "Eclipse Adoptium",
    "java.vendor.url": "https://adoptium.net/",
    "java.version": "11.0.24",
    "java.vm.name": "OpenJDK 64-Bit Server VM",
    "java.vm.version": "11.0.24+8",
    "os.name": "Linux",
    "os.version": "3.10.0-1160.el7.x86_64",
    "user.language": "en",
    "user.timezone": "US/Pacific"
  }
}

Severity

I hope it can be displayed consistently with MySQL Console

Additional context

No response

@xys2015 xys2015 added .Needs Triage Type:Bug Product defects labels Sep 13, 2024
@bshepherdson
Copy link
Contributor

There may not be much we can do here, since this behaviour is coming directly from the JDBC driver.

;; Create a basic table with a tinyint(1) column.
(jdbc/execute! mysql ["create table boolean_demo (number tinyint(1), description text)"])
(jdbc/execute! mysql ["insert into boolean_demo values (1, 'true?'), (0, 'false?')"])

;; Using the MySQL JDBC driver directly, nothing from Metabase.
(with-open [connection (java.sql.DriverManager/getConnection conn-string)
            statement  (.prepareStatement connection "select * from boolean_demo")
            rs (.executeQuery statement)]
  (let [column-count (.getColumnCount (.getMetaData rs))]
    (into []
          (take-while some?)
          (repeatedly
            (fn []
              (when (.next rs)
                (into [] (for [i (range 1 (inc column-count))]
                           (.getObject rs i)))))))))

;; which returns
[[true "true?"] [false "false?"]]

(Hat tip to @dpsutton for the exploration.)

That is, the JDBC driver interprets tinyint(1) as booleans and returns Java boolean values in the results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants