-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_sql_translation.py
More file actions
executable file
·63 lines (53 loc) · 1.76 KB
/
Copy pathtest_sql_translation.py
File metadata and controls
executable file
·63 lines (53 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python3
"""
测试 SQL 转换功能(不需要数据库连接)
这是最快验证系统是否工作的方式
"""
from data_diff.migration import SQLTranslator, DatabaseDialect
def test_sql_translation():
"""测试 SQL 转换"""
print("=" * 60)
print("SQL 转换功能测试(不需要数据库连接)")
print("=" * 60)
translator = SQLTranslator()
# 测试用例
test_cases = [
{
"name": "MySQL LIMIT 语法",
"sql": "SELECT * FROM `users` LIMIT 10, 20",
"from": DatabaseDialect.MYSQL,
"to": DatabaseDialect.POSTGRESQL
},
{
"name": "MySQL 反引号",
"sql": "SELECT `id`, `name` FROM `users`",
"from": DatabaseDialect.MYSQL,
"to": DatabaseDialect.POSTGRESQL
},
{
"name": "MySQL AUTO_INCREMENT",
"sql": "CREATE TABLE test (id INT AUTO_INCREMENT PRIMARY KEY)",
"from": DatabaseDialect.MYSQL,
"to": DatabaseDialect.POSTGRESQL
}
]
for i, test in enumerate(test_cases, 1):
print(f"\n测试 {i}: {test['name']}")
print(f"原始 SQL ({test['from'].value}):")
print(f" {test['sql']}")
try:
translated = translator.translate(
test['sql'],
test['from'],
test['to']
)
print(f"转换后 SQL ({test['to'].value}):")
print(f" {translated}")
print("✓ 转换成功")
except Exception as e:
print(f"✗ 转换失败: {e}")
print("\n" + "=" * 60)
print("✅ SQL 转换功能测试完成")
print("=" * 60)
if __name__ == "__main__":
test_sql_translation()