|
1 |
| -import pymysql.cursors |
2 |
| - |
3 |
| -from pymysql.tests import base |
4 |
| -from pymysql import util |
5 |
| -from pymysql.err import ProgrammingError |
6 |
| - |
7 |
| -import time |
| 1 | +# coding: utf-8 |
8 | 2 | import datetime
|
| 3 | +import json |
| 4 | +import time |
9 | 5 | import warnings
|
10 | 6 |
|
11 | 7 | from unittest2 import SkipTest
|
12 | 8 |
|
| 9 | +from pymysql import util |
| 10 | +import pymysql.cursors |
| 11 | +from pymysql.tests import base |
| 12 | +from pymysql.err import ProgrammingError |
| 13 | + |
13 | 14 |
|
14 | 15 | __all__ = ["TestConversion", "TestCursor", "TestBulkInserts"]
|
15 | 16 |
|
@@ -238,6 +239,26 @@ def test_single_tuple(self):
|
238 | 239 | self.assertEqual([(1,)], list(c.fetchall()))
|
239 | 240 | c.close()
|
240 | 241 |
|
| 242 | + def test_json(self): |
| 243 | + args = self.databases[0].copy() |
| 244 | + args["charset"] = "utf8mb4" |
| 245 | + conn = pymysql.connect(**args) |
| 246 | + if not self.mysql_server_is(conn, (5, 7, 0)): |
| 247 | + raise SkipTest("JSON type is not supported on MySQL <= 5.6") |
| 248 | + |
| 249 | + self.safe_create_table(conn, "test_json", """\ |
| 250 | +create table test_json ( |
| 251 | + id int not null, |
| 252 | + json JSON not null, |
| 253 | + primary key (id) |
| 254 | +);""") |
| 255 | + cur = conn.cursor() |
| 256 | + json_str = u'{"hello": "こんにちは"}' |
| 257 | + cur.execute("INSERT INTO test_json (id, `json`) values (42, %s)", (json_str,)) |
| 258 | + cur.execute("SELECT `json` from `test_json` WHERE `id`=42") |
| 259 | + res = cur.fetchone()[0] |
| 260 | + self.assertEqual(json.loads(res), json.loads(json_str)) |
| 261 | + |
241 | 262 |
|
242 | 263 | class TestBulkInserts(base.PyMySQLTestCase):
|
243 | 264 |
|
|
0 commit comments