Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-26497

PyMySQL syntax error in prepared statement - behaviour different from MySQL

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Not a Bug
    • 10.0.38, 10.2.40, 10.3.32, 10.5.13
    • N/A
    • Prepared Statements
    • None

    Description

      From:

      https://github.com/grooverdan/PyMySQL/runs/3458715957?check_suite_focus=true#step:8:181

      https://github.com/grooverdan/PyMySQL/runs/3458715926?check_suite_focus=true#step:8:179

      10.5.13-MariaDB-4b6ef03dcda608109f0455732ab9ed65f32b06bb, 10.3.32-MariaDB-b378ddb3d3c3af75195d328018259369671bb029

      =================================== FAILURES ===================================
      _____________________________ TestCursor.test_json _____________________________
       
      self = <pymysql.tests.test_basic.TestCursor testMethod=test_json>
       
              def test_json(self):
                  args = self.databases[0].copy()
                  args["charset"] = "utf8mb4"
                  conn = pymysql.connect(**args)
                  if not self.mysql_server_is(conn, (5, 7, 0)):
                      pytest.skip("JSON type is not supported on MySQL <= 5.6")
          
                  self.safe_create_table(
                      conn,
                      "test_json",
                      """\
          create table test_json (
              id int not null,
              json JSON not null,
              primary key (id)
          );""",
                  )
                  cur = conn.cursor()
          
                  json_str = '{"hello": "こんにちは"}'
                  cur.execute("INSERT INTO test_json (id, `json`) values (42, %s)", (json_str,))
                  cur.execute("SELECT `json` from `test_json` WHERE `id`=42")
                  res = cur.fetchone()[0]
                  self.assertEqual(json.loads(res), json.loads(json_str))
          
      >           cur.execute("SELECT CAST(%s AS JSON) AS x", (json_str,))
       
      pymysql/tests/test_basic.py:309: 
      _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
      pymysql/cursors.py:158: in execute
          result = self._query(query)
      pymysql/cursors.py:325: in _query
          conn.query(q)
      pymysql/connections.py:546: in query
          self._affected_rows = self._read_query_result(unbuffered=unbuffered)
      pymysql/connections.py:775: in _read_query_result
          result.read()
      pymysql/connections.py:1152: in read
          first_packet = self.connection._read_packet()
      pymysql/connections.py:725: in _read_packet
          packet.raise_for_error()
      pymysql/protocol.py:221: in raise_for_error
          err.raise_mysql_exception(self._data)
      _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
       
      data = b"\xff(\x04#42000You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'JSON) AS x' at line 1"
      

      These test passed on 10.3.31, 10.5.12 (version in "Set up MySQL" step)
      https://github.com/PyMySQL/PyMySQL/runs/3448912434?check_suite_focus=true

      Attachments

        Activity

          People

            serg Sergei Golubchik
            danblack Daniel Black
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.