Skip to content

Commit c074e1d

Browse files
authored
Merge pull request #16 from pangpang20/master
Add Demo and Update Database Compatibility Mode to Default Mode A
2 parents 84d5244 + 95a69e7 commit c074e1d

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

README.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ Installation from PyPI:
5555
pip install gaussdb-pool
5656
python -c "import gaussdb; print(gaussdb.__version__)" # Outputs: 1.0.0.dev2
5757

58+
# Run demo
59+
python ./example/demo.py
60+
5861
You can also clone this repository to develop GaussDB::
5962

6063
# Create a new Python virtual environment in the .venv directory
@@ -111,8 +114,8 @@ Please add ``--config-settings editable_mode=strict`` to the ``pip install
111114

112115
Now hack away! You can run the tests using on GaussDB::
113116

114-
# Create a new database named "test" with PostgreSQL compatibility enabled
115-
gsql -c 'CREATE DATABASE test DBCOMPATIBILITY 'PG' ;'
117+
# Create a new database named "test" with Default compatibility with Oracle enabled
118+
gsql -c 'CREATE DATABASE test;'
116119

117120
# Set the Python import path to include your local GaussDB Python project
118121
# Replace your_path with actual values
@@ -154,8 +157,8 @@ Recommended Steps to Run OpenGauss with Python GaussDB Driver Testing (Assuming
154157
# Connect to the OpenGauss database using the gsql client
155158
gsql -d postgres -p 5432 -U omm
156159

157-
-- Create a new database named "test" with PostgreSQL compatibility enabled
158-
CREATE DATABASE test DBCOMPATIBILITY 'PG';
160+
-- Create a new database named "test" with Default compatibility with Oracle enabled
161+
CREATE DATABASE test;
159162

160163

161164
# Set the Python import path to include your local GaussDB Python project

example/demo.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import os
4+
import sys
5+
6+
from gaussdb import connect
7+
8+
os.environ["GAUSSDB_IMPL"] = "python"
9+
10+
11+
def main():
12+
dsn = os.environ.get("GAUSSDB_TEST_DSN")
13+
if not dsn:
14+
print("❌ Please set the GAUSSDB_TEST_DSN environment variable, for example:")
15+
print(
16+
' export GAUSSDB_TEST_DSN="dbname=test01 user=root password=***'
17+
'host=** port=8000"'
18+
)
19+
sys.exit(1)
20+
21+
drop_table_sql = "DROP TABLE IF EXISTS test"
22+
create_table_sql = (
23+
"CREATE TABLE test (id serial PRIMARY KEY, num integer, data text)"
24+
)
25+
insert_data_sql = "INSERT INTO test (num, data) VALUES (%s, %s)"
26+
update_data_sql = "UPDATE test SET data = 'gaussdb' WHERE num = 2"
27+
select_sql = "SELECT * FROM test"
28+
29+
with connect(dsn, connect_timeout=10, application_name="gaussdb-demo") as conn:
30+
31+
with conn.cursor() as cur:
32+
server_version = conn.execute("select version()").fetchall()[0][0]
33+
print(f"✅ Connected. Server version: {server_version}")
34+
print(f"Vendor: {conn.info.vendor}, Version: {conn.info.server_version}")
35+
36+
cur.execute(drop_table_sql)
37+
cur.execute(create_table_sql)
38+
cur.execute(insert_data_sql, (1, "hello"))
39+
cur.execute(insert_data_sql, (2, "world"))
40+
41+
cur.execute(select_sql)
42+
print("📄origin: ", cur.fetchall())
43+
44+
cur.execute(update_data_sql)
45+
cur.execute(select_sql)
46+
print("📄update: ", cur.fetchall())
47+
48+
49+
if __name__ == "__main__":
50+
main()

0 commit comments

Comments
 (0)