(self)
| 297 | c.close() |
| 298 | |
| 299 | def test_json(self): |
| 300 | args = self.databases[0].copy() |
| 301 | args["charset"] = "utf8mb4" |
| 302 | conn = pymysql.connect(**args) |
| 303 | # MariaDB only has limited JSON support, stores data as longtext |
| 304 | # https://mariadb.com/kb/en/json-data-type/ |
| 305 | if not self.mysql_server_is(conn, (5, 7, 0)): |
| 306 | pytest.skip("JSON type is only supported on MySQL >= 5.7") |
| 307 | |
| 308 | self.safe_create_table( |
| 309 | conn, |
| 310 | "test_json", |
| 311 | """\ |
| 312 | create table test_json ( |
| 313 | id int not null, |
| 314 | json JSON not null, |
| 315 | primary key (id) |
| 316 | );""", |
| 317 | ) |
| 318 | cur = conn.cursor() |
| 319 | |
| 320 | json_str = '{"hello": "こんにちは"}' |
| 321 | cur.execute("INSERT INTO test_json (id, `json`) values (42, %s)", (json_str,)) |
| 322 | cur.execute("SELECT `json` from `test_json` WHERE `id`=42") |
| 323 | res = cur.fetchone()[0] |
| 324 | self.assertEqual(json.loads(res), json.loads(json_str)) |
| 325 | |
| 326 | if self.get_mysql_vendor(conn) == "mysql": |
| 327 | cur.execute("SELECT CAST(%s AS JSON) AS x", (json_str,)) |
| 328 | res = cur.fetchone()[0] |
| 329 | self.assertEqual(json.loads(res), json.loads(json_str)) |
| 330 | |
| 331 | |
| 332 | class TestBulkInserts(base.PyMySQLTestCase): |
nothing calls this directly
no test coverage detected