Skip to content

Commit cda648f

Browse files
committed
test(sqlserver): add savepoint/pool-transaction bridges and fix SQL Server DDL in tests
- Add bridge files for test_pool_transaction_paths, test_savepoint_api, and test_async_owner_task (feature/basic) - Replace AUTO_INCREMENT with IDENTITY(1,1) in providers and test DDL - Switch SQL placeholders from MySQL %s to ? for pyodbc/aioodbc - Drop illegal TINYINT(1) width in column mapping DDL
1 parent 5ae09dd commit cda648f

19 files changed

Lines changed: 102 additions & 76 deletions

‎tests/providers/basic_connection.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def _create_test_table(self, backend):
5656

5757
backend.execute("""
5858
CREATE TABLE test_users (
59-
id INT AUTO_INCREMENT PRIMARY KEY,
59+
id INT IDENTITY(1,1) PRIMARY KEY,
6060
name VARCHAR(255) NOT NULL,
6161
email VARCHAR(255) NOT NULL
6262
)
@@ -71,7 +71,7 @@ async def _create_test_table_async(self, backend):
7171

7272
await backend.execute("""
7373
CREATE TABLE test_users (
74-
id INT AUTO_INCREMENT PRIMARY KEY,
74+
id INT IDENTITY(1,1) PRIMARY KEY,
7575
name VARCHAR(255) NOT NULL,
7676
email VARCHAR(255) NOT NULL
7777
)

‎tests/providers/query_connection.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def _create_test_table(self, backend):
5656

5757
backend.execute("""
5858
CREATE TABLE test_users (
59-
id INT AUTO_INCREMENT PRIMARY KEY,
59+
id INT IDENTITY(1,1) PRIMARY KEY,
6060
name VARCHAR(255) NOT NULL,
6161
email VARCHAR(255) NOT NULL
6262
)
@@ -71,7 +71,7 @@ async def _create_test_table_async(self, backend):
7171

7272
await backend.execute("""
7373
CREATE TABLE test_users (
74-
id INT AUTO_INCREMENT PRIMARY KEY,
74+
id INT IDENTITY(1,1) PRIMARY KEY,
7575
name VARCHAR(255) NOT NULL,
7676
email VARCHAR(255) NOT NULL
7777
)

‎tests/rhosocial/activerecord_sqlserver_test/feature/backend/test_async_column_mapping_backend.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ async def setup_mapped_users_table(async_sqlserver_backend):
1313
await async_sqlserver_backend.execute("DROP TABLE IF EXISTS mapped_users")
1414
await async_sqlserver_backend.execute("""
1515
CREATE TABLE mapped_users (
16-
user_id INT AUTO_INCREMENT PRIMARY KEY,
16+
user_id INT IDENTITY(1,1) PRIMARY KEY,
1717
name VARCHAR(255) NOT NULL,
1818
email VARCHAR(255) NOT NULL UNIQUE,
1919
created_at DATETIME NOT NULL,
2020
user_uuid VARCHAR(36),
21-
is_active TINYINT(1)
21+
is_active TINYINT
2222
)
2323
""")
2424
yield
@@ -34,7 +34,7 @@ async def test_async_insert_with_mapping(async_sqlserver_backend, setup_mapped_u
3434
now = datetime.now()
3535
now_str = now.strftime('%Y-%m-%d %H:%M:%S')
3636

37-
sql = "INSERT INTO mapped_users (name, email, created_at, user_uuid, is_active) VALUES (%s, %s, %s, %s, %s)"
37+
sql = "INSERT INTO mapped_users (name, email, created_at, user_uuid, is_active) VALUES (?, ?, ?, ?, ?)"
3838
params = ("John Doe Async", "john.doe.async@example.com", now_str, str(uuid.uuid4()), 1)
3939

4040
result = await backend.execute(sql=sql, params=params)
@@ -51,10 +51,10 @@ async def test_async_update_with_backend(async_sqlserver_backend, setup_mapped_u
5151
backend = async_sqlserver_backend
5252
now_str = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
5353

54-
await backend.execute("INSERT INTO mapped_users (name, email, created_at, user_uuid, is_active) VALUES (%s, %s, %s, %s, %s)",
54+
await backend.execute("INSERT INTO mapped_users (name, email, created_at, user_uuid, is_active) VALUES (?, ?, ?, ?, ?)",
5555
("Jane Doe Async", "jane.doe.async@example.com", now_str, str(uuid.uuid4()), 1))
5656

57-
sql = "UPDATE mapped_users SET name = %s WHERE user_id = %s"
57+
sql = "UPDATE mapped_users SET name = ? WHERE user_id = ?"
5858
params = ("Jane Smith Async", 1)
5959
result = await backend.execute(sql, params)
6060

@@ -89,7 +89,7 @@ async def test_async_fetch_with_combined_mapping_and_adapters(async_sqlserver_ba
8989
}
9090

9191
await backend.execute(
92-
"INSERT INTO mapped_users (name, email, created_at, user_uuid, is_active) VALUES (%s, %s, %s, %s, %s)",
92+
"INSERT INTO mapped_users (name, email, created_at, user_uuid, is_active) VALUES (?, ?, ?, ?, ?)",
9393
("Async Combined", "asynccombined@example.com", now_str, str(test_uuid), 1)
9494
)
9595

‎tests/rhosocial/activerecord_sqlserver_test/feature/backend/test_async_concurrency.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class ConcurrentTask(AsyncActiveRecord):
6767

6868
USERS_SCHEMA = """
6969
CREATE TABLE `concurrent_users` (
70-
`id` INT AUTO_INCREMENT PRIMARY KEY,
70+
`id` INT IDENTITY(1,1) PRIMARY KEY,
7171
`username` VARCHAR(191) NOT NULL UNIQUE,
7272
`email` VARCHAR(191) NOT NULL,
7373
`value` INT NOT NULL DEFAULT 0,
@@ -77,7 +77,7 @@ class ConcurrentTask(AsyncActiveRecord):
7777

7878
TASKS_SCHEMA = """
7979
CREATE TABLE `concurrent_tasks` (
80-
`id` INT AUTO_INCREMENT PRIMARY KEY,
80+
`id` INT IDENTITY(1,1) PRIMARY KEY,
8181
`task_name` VARCHAR(191) NOT NULL,
8282
`status` VARCHAR(50) NOT NULL DEFAULT 'pending',
8383
`worker_id` INT,

‎tests/rhosocial/activerecord_sqlserver_test/feature/backend/test_async_transaction_backend.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ async def setup_test_table(async_sqlserver_backend):
88
await async_sqlserver_backend.execute("DROP TABLE IF EXISTS test_table")
99
await async_sqlserver_backend.execute("""
1010
CREATE TABLE test_table (
11-
id INT AUTO_INCREMENT PRIMARY KEY,
11+
id INT IDENTITY(1,1) PRIMARY KEY,
1212
name VARCHAR(255),
1313
age INT
1414
)
@@ -21,10 +21,10 @@ async def setup_test_table(async_sqlserver_backend):
2121
async def test_transaction_commit(async_sqlserver_backend, setup_test_table):
2222
"""Test transaction commit"""
2323
async with async_sqlserver_backend.transaction():
24-
sql = "INSERT INTO test_table (name, age) VALUES (%s, %s)"
24+
sql = "INSERT INTO test_table (name, age) VALUES (?, ?)"
2525
params = ("test", 20)
2626
await async_sqlserver_backend.execute(sql, params)
27-
row = await async_sqlserver_backend.fetch_one("SELECT * FROM test_table WHERE name = %s", ("test",))
27+
row = await async_sqlserver_backend.fetch_one("SELECT * FROM test_table WHERE name = ?", ("test",))
2828
assert row is not None
2929

3030

@@ -33,25 +33,25 @@ async def test_transaction_rollback(async_sqlserver_backend, setup_test_table):
3333
"""Test transaction rollback"""
3434
try:
3535
async with async_sqlserver_backend.transaction():
36-
sql = "INSERT INTO test_table (name, age) VALUES (%s, %s)"
36+
sql = "INSERT INTO test_table (name, age) VALUES (?, ?)"
3737
params = ("test", 20)
3838
await async_sqlserver_backend.execute(sql, params)
3939
raise Exception("Force rollback")
4040
except Exception:
4141
pass
42-
row = await async_sqlserver_backend.fetch_one("SELECT * FROM test_table WHERE name = %s", ("test",))
42+
row = await async_sqlserver_backend.fetch_one("SELECT * FROM test_table WHERE name = ?", ("test",))
4343
assert row is None
4444

4545

4646
@pytest.mark.asyncio
4747
async def test_nested_transaction(async_sqlserver_backend, setup_test_table):
4848
"""Test nested transactions"""
4949
async with async_sqlserver_backend.transaction():
50-
sql_outer = "INSERT INTO test_table (name, age) VALUES (%s, %s)"
50+
sql_outer = "INSERT INTO test_table (name, age) VALUES (?, ?)"
5151
params_outer = ("outer", 20)
5252
await async_sqlserver_backend.execute(sql_outer, params_outer)
5353
async with async_sqlserver_backend.transaction():
54-
sql_inner = "INSERT INTO test_table (name, age) VALUES (%s, %s)"
54+
sql_inner = "INSERT INTO test_table (name, age) VALUES (?, ?)"
5555
params_inner = ("inner", 30)
5656
await async_sqlserver_backend.execute(sql_inner, params_inner)
5757
rows = await async_sqlserver_backend.fetch_all("SELECT * FROM test_table ORDER BY age")

‎tests/rhosocial/activerecord_sqlserver_test/feature/backend/test_async_transaction_isolation_effect.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async def async_isolation_test_table(async_sqlserver_backend):
2121
await async_sqlserver_backend.execute("drop table if exists async_isolation_test")
2222
await async_sqlserver_backend.execute("""
2323
create table async_isolation_test (
24-
id INT AUTO_INCREMENT PRIMARY KEY,
24+
id INT IDENTITY(1,1) PRIMARY KEY,
2525
name VARCHAR(255),
2626
balance DECIMAL(10, 2),
2727
version INT DEFAULT 1
@@ -41,7 +41,7 @@ async def async_mode_test_table(async_sqlserver_backend):
4141
await async_sqlserver_backend.execute("drop table if exists async_mode_test")
4242
await async_sqlserver_backend.execute("""
4343
create table async_mode_test (
44-
id INT AUTO_INCREMENT PRIMARY KEY,
44+
id INT IDENTITY(1,1) PRIMARY KEY,
4545
name VARCHAR(255),
4646
balance DECIMAL(10, 2)
4747
)
@@ -60,7 +60,7 @@ async def async_combo_test_table(async_sqlserver_backend):
6060
await async_sqlserver_backend.execute("drop table if exists async_combo_test")
6161
await async_sqlserver_backend.execute("""
6262
create table async_combo_test (
63-
id INT AUTO_INCREMENT PRIMARY KEY,
63+
id INT IDENTITY(1,1) PRIMARY KEY,
6464
name VARCHAR(255),
6565
balance DECIMAL(10, 2)
6666
)
@@ -79,7 +79,7 @@ async def async_nested_test_table(async_sqlserver_backend):
7979
await async_sqlserver_backend.execute("drop table if exists async_nested_test")
8080
await async_sqlserver_backend.execute("""
8181
create table async_nested_test (
82-
id INT AUTO_INCREMENT PRIMARY KEY,
82+
id INT IDENTITY(1,1) PRIMARY KEY,
8383
name VARCHAR(255),
8484
value INT
8585
)

‎tests/rhosocial/activerecord_sqlserver_test/feature/backend/test_column_mapping_backend.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ def setup_mapped_users_table(sqlserver_backend):
1414
sqlserver_backend.execute("DROP TABLE IF EXISTS mapped_users")
1515
sqlserver_backend.execute("""
1616
CREATE TABLE mapped_users (
17-
user_id INT AUTO_INCREMENT PRIMARY KEY,
17+
user_id INT IDENTITY(1,1) PRIMARY KEY,
1818
name VARCHAR(255) NOT NULL,
1919
email VARCHAR(255) NOT NULL UNIQUE,
2020
created_at DATETIME NOT NULL,
2121
user_uuid VARCHAR(36),
22-
is_active TINYINT(1)
22+
is_active TINYINT
2323
)
2424
""")
2525
yield
@@ -36,7 +36,7 @@ def test_insert_with_mapping(sqlserver_backend, setup_mapped_users_table):
3636
now_str = now.strftime('%Y-%m-%d %H:%M:%S')
3737

3838
# Data for insertion must use database column names and compatible types
39-
sql = "INSERT INTO mapped_users (name, email, created_at, user_uuid, is_active) VALUES (%s, %s, %s, %s, %s)"
39+
sql = "INSERT INTO mapped_users (name, email, created_at, user_uuid, is_active) VALUES (?, ?, ?, ?, ?)"
4040
params = ("John Doe", "john.doe@example.com", now_str, str(uuid.uuid4()), 1)
4141

4242
result = backend.execute(sql=sql, params=params)
@@ -52,10 +52,10 @@ def test_update_with_backend(sqlserver_backend, setup_mapped_users_table):
5252
backend = sqlserver_backend
5353
now_str = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
5454

55-
backend.execute("INSERT INTO mapped_users (name, email, created_at, user_uuid, is_active) VALUES (%s, %s, %s, %s, %s)",
55+
backend.execute("INSERT INTO mapped_users (name, email, created_at, user_uuid, is_active) VALUES (?, ?, ?, ?, ?)",
5656
("Jane Doe", "jane.doe@example.com", now_str, str(uuid.uuid4()), 1))
5757

58-
sql = "UPDATE mapped_users SET name = %s WHERE user_id = %s"
58+
sql = "UPDATE mapped_users SET name = ? WHERE user_id = ?"
5959
params = ("Jane Smith", 1)
6060
result = backend.execute(sql, params)
6161

@@ -92,7 +92,7 @@ def test_fetch_with_combined_mapping_and_adapters(sqlserver_backend, setup_mappe
9292

9393
# Insert data in DB-compatible format
9494
backend.execute(
95-
"INSERT INTO mapped_users (name, email, created_at, user_uuid, is_active) VALUES (%s, %s, %s, %s, %s)",
95+
"INSERT INTO mapped_users (name, email, created_at, user_uuid, is_active) VALUES (?, ?, ?, ?, ?)",
9696
("Combined Test", "combined@example.com", now_str, str(test_uuid), 1)
9797
)
9898

‎tests/rhosocial/activerecord_sqlserver_test/feature/backend/test_crud_backend.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_table(self, sqlserver_backend):
1919
sqlserver_backend.execute("DROP TABLE IF EXISTS test_crud_table")
2020
sqlserver_backend.execute("""
2121
CREATE TABLE test_crud_table (
22-
id INT AUTO_INCREMENT PRIMARY KEY,
22+
id INT IDENTITY(1,1) PRIMARY KEY,
2323
name VARCHAR(255),
2424
age INT,
2525
balance DECIMAL(10, 2)
@@ -133,7 +133,7 @@ async def async_test_table(self, async_sqlserver_backend):
133133
await async_sqlserver_backend.execute("DROP TABLE IF EXISTS test_crud_table")
134134
await async_sqlserver_backend.execute("""
135135
CREATE TABLE test_crud_table (
136-
id INT AUTO_INCREMENT PRIMARY KEY,
136+
id INT IDENTITY(1,1) PRIMARY KEY,
137137
name VARCHAR(255),
138138
age INT,
139139
balance DECIMAL(10, 2)

‎tests/rhosocial/activerecord_sqlserver_test/feature/backend/test_enum_adapter_backend.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def test_enum_with_sql_execution(self, sqlserver_backend):
6868
"""Test enum handling in actual SQL execution."""
6969
sqlserver_backend.execute("""
7070
CREATE TEMPORARY TABLE test_enum_table (
71-
id INT AUTO_INCREMENT PRIMARY KEY,
71+
id INT IDENTITY(1,1) PRIMARY KEY,
7272
status VARCHAR(20),
7373
priority INT
7474
)
@@ -93,7 +93,7 @@ def test_enum_null_handling_with_database(self, sqlserver_backend):
9393
"""Test NULL enum handling with database."""
9494
sqlserver_backend.execute("""
9595
CREATE TEMPORARY TABLE test_enum_null (
96-
id INT AUTO_INCREMENT PRIMARY KEY,
96+
id INT IDENTITY(1,1) PRIMARY KEY,
9797
status VARCHAR(20) NULL
9898
)
9999
""")
@@ -115,7 +115,7 @@ def test_native_sqlserver_enum_type(self, sqlserver_backend):
115115
"""Test integration with SQLServer native ENUM column type."""
116116
sqlserver_backend.execute("""
117117
CREATE TEMPORARY TABLE test_native_enum (
118-
id INT AUTO_INCREMENT PRIMARY KEY,
118+
id INT IDENTITY(1,1) PRIMARY KEY,
119119
status ENUM('draft', 'published', 'archived')
120120
)
121121
""")
@@ -190,7 +190,7 @@ async def test_async_enum_with_sql_execution(self, async_sqlserver_backend):
190190
"""Test enum handling in actual SQL execution (async)."""
191191
await async_sqlserver_backend.execute("""
192192
CREATE TEMPORARY TABLE test_async_enum_table (
193-
id INT AUTO_INCREMENT PRIMARY KEY,
193+
id INT IDENTITY(1,1) PRIMARY KEY,
194194
status VARCHAR(20),
195195
priority INT
196196
)
@@ -216,7 +216,7 @@ async def test_async_enum_null_handling_with_database(self, async_sqlserver_back
216216
"""Test NULL enum handling with database (async)."""
217217
await async_sqlserver_backend.execute("""
218218
CREATE TEMPORARY TABLE test_async_enum_null (
219-
id INT AUTO_INCREMENT PRIMARY KEY,
219+
id INT IDENTITY(1,1) PRIMARY KEY,
220220
status VARCHAR(20) NULL
221221
)
222222
""")

‎tests/rhosocial/activerecord_sqlserver_test/feature/backend/test_json_functions_backend.py‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_create_table_with_json_column(self, sqlserver_backend, json_column_adap
2727

2828
sqlserver_backend.execute("""
2929
CREATE TEMPORARY TABLE test_json_table (
30-
id INT AUTO_INCREMENT PRIMARY KEY,
30+
id INT IDENTITY(1,1) PRIMARY KEY,
3131
data JSON
3232
)
3333
""")
@@ -52,7 +52,7 @@ def test_json_extract_function(self, sqlserver_backend):
5252

5353
sqlserver_backend.execute("""
5454
CREATE TEMPORARY TABLE test_json_extract (
55-
id INT AUTO_INCREMENT PRIMARY KEY,
55+
id INT IDENTITY(1,1) PRIMARY KEY,
5656
data JSON
5757
)
5858
""")
@@ -100,7 +100,7 @@ def test_json_contains_function(self, sqlserver_backend):
100100

101101
sqlserver_backend.execute("""
102102
CREATE TEMPORARY TABLE test_json_contains (
103-
id INT AUTO_INCREMENT PRIMARY KEY,
103+
id INT IDENTITY(1,1) PRIMARY KEY,
104104
data JSON
105105
)
106106
""")
@@ -124,7 +124,7 @@ def test_format_json_extract_integration(self, sqlserver_backend):
124124

125125
sqlserver_backend.execute("""
126126
CREATE TEMPORARY TABLE test_format_json_extract (
127-
id INT AUTO_INCREMENT PRIMARY KEY,
127+
id INT IDENTITY(1,1) PRIMARY KEY,
128128
data JSON
129129
)
130130
""")
@@ -166,7 +166,7 @@ async def test_async_create_table_with_json_column(self, async_sqlserver_backend
166166

167167
await async_sqlserver_backend.execute("""
168168
CREATE TEMPORARY TABLE test_async_json_table (
169-
id INT AUTO_INCREMENT PRIMARY KEY,
169+
id INT IDENTITY(1,1) PRIMARY KEY,
170170
data JSON
171171
)
172172
""")
@@ -192,7 +192,7 @@ async def test_async_json_extract_function(self, async_sqlserver_backend):
192192

193193
await async_sqlserver_backend.execute("""
194194
CREATE TEMPORARY TABLE test_async_json_extract (
195-
id INT AUTO_INCREMENT PRIMARY KEY,
195+
id INT IDENTITY(1,1) PRIMARY KEY,
196196
data JSON
197197
)
198198
""")
@@ -243,7 +243,7 @@ async def test_async_json_contains_function(self, async_sqlserver_backend):
243243

244244
await async_sqlserver_backend.execute("""
245245
CREATE TEMPORARY TABLE test_async_json_contains (
246-
id INT AUTO_INCREMENT PRIMARY KEY,
246+
id INT IDENTITY(1,1) PRIMARY KEY,
247247
data JSON
248248
)
249249
""")
@@ -268,7 +268,7 @@ async def test_async_format_json_extract_integration(self, async_sqlserver_backe
268268

269269
await async_sqlserver_backend.execute("""
270270
CREATE TEMPORARY TABLE test_async_format_json_extract (
271-
id INT AUTO_INCREMENT PRIMARY KEY,
271+
id INT IDENTITY(1,1) PRIMARY KEY,
272272
data JSON
273273
)
274274
""")

0 commit comments

Comments
 (0)