Skip to content

Commit 5594d1f

Browse files
AI Translate python to Simplified-Chinese (#2472)
* [INIT] Start translation to Simplified-Chinese * 🌐 Translate integrating-with-databend-cloud-using-databend-sqlalchemy.md to Simplified-Chinese --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 02a2282 commit 5594d1f

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

.translation-init

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Translation initialization: 2025-06-27T07:21:00.624160
1+
Translation initialization: 2025-06-30T10:40:52.497220

docs/cn/tutorials/programming/python/integrating-with-databend-cloud-using-databend-sqlalchemy.md

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,41 @@
22
title: 使用 databend-sqlalchemy 集成 Databend Cloud
33
---
44

5-
在本教程中,我们将引导您了解如何使用 `databend-sqlalchemy` 库连接到 Databend Cloud,创建表,插入数据以及使用 Python 查询结果
5+
在本教程中,我们将引导你使用 `databend-sqlalchemy` 库连接 Databend Cloud,并通过 Python 创建表、插入数据及查询结果
66

7-
## 准备工作
7+
## 在开始之前
88

9-
在开始之前,请确保您已成功创建计算集群并获得了连接信息。有关如何执行此操作,请参见 [连接到计算集群](/guides/cloud/using-databend-cloud/warehouses#connecting)
9+
开始前,请确保已成功创建计算集群(Warehouse)并获取连接信息。具体操作请参阅[连接计算集群(Warehouse)](/guides/cloud/using-databend-cloud/warehouses#connecting)
1010

11-
## 步骤 1:使用 pip 安装依赖项
11+
## 第一步:使用 pip 安装依赖项
1212

1313
```shell
1414
pip install databend-sqlalchemy
1515
```
1616

17-
## 步骤 2:使用 databend_sqlalchemy 连接
17+
## 第二步:使用 databend_sqlalchemy 连接
1818

19-
1. 复制以下代码并粘贴到文件 `main.py`
19+
1. 复制以下代码至文件 `main.py`
2020

2121
```python
22-
from databend_sqlalchemy import connector
23-
24-
# 使用您的凭据连接到 Databend Cloud(替换 PASSWORD、HOST、DATABASE 和 WAREHOUSE_NAME)
25-
cursor = connector.connect(f"databend://cloudapp:{PASSWORD}@{HOST}:443/{DATABASE}?warehouse={WAREHOUSE_NAME}").cursor()
26-
cursor.execute('DROP TABLE IF EXISTS data')
27-
cursor.execute('CREATE TABLE IF NOT EXISTS data( Col1 TINYINT, Col2 VARCHAR )')
28-
cursor.execute("INSERT INTO data (Col1, Col2) VALUES (%s, %s), (%s, %s)", [1, 'yy', 2, 'xx'])
29-
cursor.execute("SELECT * FROM data")
30-
print(cursor.fetchall())
22+
from sqlalchemy import create_engine, text
23+
from sqlalchemy.engine.base import Connection, Engine
24+
25+
# Connecting to Databend Cloud with your credentials (replace PASSWORD, HOST, DATABASE, and WAREHOUSE_NAME)
26+
engine = create_engine(
27+
f"databend://{username}:{password}@{host_port_name}/{database_name}?sslmode=disable"
28+
)
29+
cursor = engine.connect()
30+
cursor.execute(text('DROP TABLE IF EXISTS data'))
31+
cursor.execute(text('CREATE TABLE IF NOT EXISTS data( Col1 TINYINT, Col2 VARCHAR )'))
32+
cursor.execute(text("INSERT INTO data VALUES (1,'zz')"))
33+
res = cursor.execute(text("SELECT * FROM data"))
34+
print(res.fetchall())
3135
```
3236

3337
2. 运行 `python main.py`
3438

3539
```bash
3640
python main.py
37-
[(1, 'yy'), (2, 'xx')]
41+
[(1, 'zz')]
3842
```

0 commit comments

Comments
 (0)