@@ -475,6 +475,80 @@ async def test_connection_valid_ssl_mode(client, mysql_ssl_off: MySqlContainer):
475
475
assert response .text == '"8.0.40"'
476
476
477
477
478
+ # MySQL specific chinese tests
479
+ # So we dont mess up with the other tests's connection
480
+ async def test_chinese_column_name_and_data (client ):
481
+ mysql = MySqlContainer (image = "mysql:8.0.40" , dialect = "pymysql" ).start ()
482
+ connection_url = mysql .get_connection_url ()
483
+ engine = sqlalchemy .create_engine (connection_url )
484
+
485
+ # Create table with Chinese column name
486
+ with engine .begin () as conn :
487
+ conn .execute (
488
+ text ("""
489
+ CREATE TABLE chinese_test (
490
+ id INT PRIMARY KEY,
491
+ `中文` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
492
+ data VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
493
+ )
494
+ """ )
495
+ )
496
+
497
+ # Insert data with Chinese characters
498
+ conn .execute (
499
+ text ("""
500
+ INSERT INTO chinese_test (id, `中文`, data)
501
+ VALUES
502
+ (1, '一', '天'),
503
+ (2, '二', '地'),
504
+ (3, '三', '人')
505
+ """ )
506
+ )
507
+
508
+ chinese_manifest = {
509
+ "catalog" : "my_catalog" ,
510
+ "schema" : "my_schema" ,
511
+ "models" : [
512
+ {
513
+ "name" : "ChineseTest" ,
514
+ "refSql" : "select * from chinese_test" ,
515
+ "columns" : [
516
+ {"name" : "id" , "expression" : "id" , "type" : "integer" },
517
+ {"name" : "中文" , "expression" : '"中文"' , "type" : "varchar" },
518
+ {"name" : "data" , "expression" : "data" , "type" : "varchar" },
519
+ ],
520
+ "primaryKey" : "id" ,
521
+ }
522
+ ],
523
+ }
524
+
525
+ chinese_manifest_str = base64 .b64encode (orjson .dumps (chinese_manifest )).decode (
526
+ "utf-8"
527
+ )
528
+
529
+ connection_info = _to_connection_info (mysql )
530
+ response = await client .post (
531
+ url = f"{ base_url } /query" ,
532
+ json = {
533
+ "connectionInfo" : connection_info ,
534
+ "manifestStr" : chinese_manifest_str ,
535
+ "sql" : 'SELECT * FROM "ChineseTest" ORDER BY id' ,
536
+ },
537
+ )
538
+
539
+ assert response .status_code == 200
540
+ result = response .json ()
541
+
542
+ assert len (result ["columns" ]) == 3
543
+ assert "中文" in result ["columns" ]
544
+ assert len (result ["data" ]) == 3
545
+
546
+ assert result ["data" ][0 ][1 ] == "一"
547
+
548
+ conn .close ()
549
+ mysql .stop ()
550
+
551
+
478
552
def _to_connection_info (mysql : MySqlContainer ):
479
553
return {
480
554
"host" : mysql .get_container_host_ip (),
0 commit comments