vsql-python 1.2.0__tar.gz → 1.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. {vsql_python-1.2.0 → vsql_python-1.2.1}/PKG-INFO +1 -1
  2. {vsql_python-1.2.0 → vsql_python-1.2.1}/src/vsql/_connection.py +40 -13
  3. {vsql_python-1.2.0 → vsql_python-1.2.1}/src/vsql/_libvsql.c +17 -0
  4. {vsql_python-1.2.0 → vsql_python-1.2.1}/src/vsql_python.egg-info/PKG-INFO +1 -1
  5. {vsql_python-1.2.0 → vsql_python-1.2.1}/src/vsql_python.egg-info/scm_version.json +2 -2
  6. {vsql_python-1.2.0 → vsql_python-1.2.1}/tests/test_vsql.py +37 -0
  7. {vsql_python-1.2.0 → vsql_python-1.2.1}/.github/workflows/release.yml +0 -0
  8. {vsql_python-1.2.0 → vsql_python-1.2.1}/.github/workflows/test.yml +0 -0
  9. {vsql_python-1.2.0 → vsql_python-1.2.1}/.gitignore +0 -0
  10. {vsql_python-1.2.0 → vsql_python-1.2.1}/LICENSE +0 -0
  11. {vsql_python-1.2.0 → vsql_python-1.2.1}/MANIFEST.in +0 -0
  12. {vsql_python-1.2.0 → vsql_python-1.2.1}/README.md +0 -0
  13. {vsql_python-1.2.0 → vsql_python-1.2.1}/example/main.py +0 -0
  14. {vsql_python-1.2.0 → vsql_python-1.2.1}/internal/amalgamation/LICENSE +0 -0
  15. {vsql_python-1.2.0 → vsql_python-1.2.1}/internal/amalgamation/LICENSE-V +0 -0
  16. {vsql_python-1.2.0 → vsql_python-1.2.1}/internal/amalgamation/libvsql.c +0 -0
  17. {vsql_python-1.2.0 → vsql_python-1.2.1}/internal/amalgamation/libvsql.h +0 -0
  18. {vsql_python-1.2.0 → vsql_python-1.2.1}/libvsql_flags.json +0 -0
  19. {vsql_python-1.2.0 → vsql_python-1.2.1}/pyproject.toml +0 -0
  20. {vsql_python-1.2.0 → vsql_python-1.2.1}/scripts/update-amalgamation.sh +0 -0
  21. {vsql_python-1.2.0 → vsql_python-1.2.1}/setup.cfg +0 -0
  22. {vsql_python-1.2.0 → vsql_python-1.2.1}/setup.py +0 -0
  23. {vsql_python-1.2.0 → vsql_python-1.2.1}/src/vsql/__init__.py +0 -0
  24. {vsql_python-1.2.0 → vsql_python-1.2.1}/src/vsql/_convert.py +0 -0
  25. {vsql_python-1.2.0 → vsql_python-1.2.1}/src/vsql/_errors.py +0 -0
  26. {vsql_python-1.2.0 → vsql_python-1.2.1}/src/vsql_python.egg-info/SOURCES.txt +0 -0
  27. {vsql_python-1.2.0 → vsql_python-1.2.1}/src/vsql_python.egg-info/dependency_links.txt +0 -0
  28. {vsql_python-1.2.0 → vsql_python-1.2.1}/src/vsql_python.egg-info/scm_file_list.json +0 -0
  29. {vsql_python-1.2.0 → vsql_python-1.2.1}/src/vsql_python.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vsql-python
3
- Version: 1.2.0
3
+ Version: 1.2.1
4
4
  Summary: A DB-API 2.0 (PEP 249) driver for vsql, a single file or in-memory SQL database.
5
5
  Author-email: Elliot Chance <elliotchance@gmail.com>
6
6
  License-Expression: MIT
@@ -3,7 +3,7 @@ import weakref
3
3
 
4
4
  from . import _convert
5
5
  from . import _libvsql as lib
6
- from ._errors import InterfaceError, ProgrammingError
6
+ from ._errors import DatabaseError, InterfaceError, ProgrammingError
7
7
 
8
8
  _isolation_levels = {
9
9
  "READ UNCOMMITTED": lib.SQL_TRANSACTION_READ_UNCOMMITTED,
@@ -103,6 +103,17 @@ class Connection:
103
103
  lib.start_tran(self._dbc, self._access_mode, self._isolation_level)
104
104
  self._in_transaction = True
105
105
 
106
+ def _check_transaction(self, handle_type, handle):
107
+ """Checks whether the transaction is still active after an error. vsql
108
+ rolls back the whole transaction for some errors (such as a 40001
109
+ serialization failure), which closes the cursors, and then the next
110
+ statement starts a new transaction."""
111
+
112
+ if self._in_transaction and not lib.transaction_active(handle_type, handle):
113
+ self._in_transaction = False
114
+ for cursor in list(self._cursors):
115
+ cursor._open = False
116
+
106
117
  def _end(self, commit):
107
118
  self._check()
108
119
  if not self._in_transaction:
@@ -111,8 +122,12 @@ class Connection:
111
122
  # The cursors of the transaction are closed by it.
112
123
  for cursor in list(self._cursors):
113
124
  cursor._close_results()
114
- self._in_transaction = False
115
- lib.end_tran(self._dbc, commit)
125
+ try:
126
+ lib.end_tran(self._dbc, commit)
127
+ finally:
128
+ # A commit that fails may leave the transaction active, or roll
129
+ # it back.
130
+ self._in_transaction = lib.transaction_active(lib.SQL_HANDLE_DBC, self._dbc)
116
131
 
117
132
  def commit(self):
118
133
  """Commits the transaction, if there is one."""
@@ -138,7 +153,11 @@ class Connection:
138
153
  self._check()
139
154
  for cursor in list(self._cursors):
140
155
  cursor._close_results()
141
- lib.end_savepoint(self._dbc, name, True)
156
+ try:
157
+ lib.end_savepoint(self._dbc, name, True)
158
+ except DatabaseError:
159
+ self._check_transaction(lib.SQL_HANDLE_DBC, self._dbc)
160
+ raise
142
161
 
143
162
  def cursor(self):
144
163
  self._check()
@@ -242,15 +261,19 @@ class Cursor:
242
261
  if self._stmt is None:
243
262
  self._stmt = lib.alloc_handle(lib.SQL_HANDLE_STMT, self.connection._dbc)
244
263
 
245
- if params or operation == self._prepared:
246
- if operation != self._prepared:
264
+ try:
265
+ if params or operation == self._prepared:
266
+ if operation != self._prepared:
267
+ self._prepared = None
268
+ lib.prepare(self._stmt, operation)
269
+ self._prepared = operation
270
+ lib.execute(self._stmt, params)
271
+ else:
247
272
  self._prepared = None
248
- lib.prepare(self._stmt, operation)
249
- self._prepared = operation
250
- lib.execute(self._stmt, params)
251
- else:
252
- self._prepared = None
253
- lib.exec_direct(self._stmt, operation)
273
+ lib.exec_direct(self._stmt, operation)
274
+ except DatabaseError:
275
+ self.connection._check_transaction(lib.SQL_HANDLE_STMT, self._stmt)
276
+ raise
254
277
 
255
278
  n = lib.num_result_cols(self._stmt)
256
279
  if n == 0:
@@ -298,7 +321,11 @@ class Cursor:
298
321
  raise ProgrammingError("the last statement wasn't a query")
299
322
  return None
300
323
 
301
- row = lib.fetch_row(self._stmt, self._kinds)
324
+ try:
325
+ row = lib.fetch_row(self._stmt, self._kinds)
326
+ except DatabaseError:
327
+ self.connection._check_transaction(lib.SQL_HANDLE_STMT, self._stmt)
328
+ raise
302
329
  if row is None:
303
330
  self._close_results()
304
331
  return None
@@ -323,6 +323,22 @@ static PyObject *end_savepoint(PyObject *self, PyObject *args) {
323
323
  Py_RETURN_NONE;
324
324
  }
325
325
 
326
+ // transaction_active(handle_type, handle) -> bool is whether a transaction was
327
+ // active after the last routine called with the handle
328
+ // (SQL_DIAG_TRANSACTION_ACTIVE).
329
+ static PyObject *transaction_active(PyObject *self, PyObject *args) {
330
+ int handle_type;
331
+ SQLINTEGER handle, active = 0;
332
+ if (!PyArg_ParseTuple(args, "ii", &handle_type, &handle)) {
333
+ return NULL;
334
+ }
335
+
336
+ CALL(handle_type, handle,
337
+ SQLGetDiagField((SQLSMALLINT)handle_type, handle, 0, SQL_DIAG_TRANSACTION_ACTIVE, &active,
338
+ 0, NULL));
339
+ return PyBool_FromLong(active);
340
+ }
341
+
326
342
  // exec_direct(stmt, query)
327
343
  static PyObject *exec_direct(PyObject *self, PyObject *args) {
328
344
  SQLINTEGER stmt;
@@ -729,6 +745,7 @@ static PyMethodDef methods[] = {
729
745
  {"start_tran", start_tran, METH_VARARGS, NULL},
730
746
  {"end_tran", end_tran, METH_VARARGS, NULL},
731
747
  {"end_savepoint", end_savepoint, METH_VARARGS, NULL},
748
+ {"transaction_active", transaction_active, METH_VARARGS, NULL},
732
749
  {"get_info", get_info, METH_VARARGS, NULL},
733
750
  {"exec_direct", exec_direct, METH_VARARGS, NULL},
734
751
  {"prepare", prepare, METH_VARARGS, NULL},
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vsql-python
3
- Version: 1.2.0
3
+ Version: 1.2.1
4
4
  Summary: A DB-API 2.0 (PEP 249) driver for vsql, a single file or in-memory SQL database.
5
5
  Author-email: Elliot Chance <elliotchance@gmail.com>
6
6
  License-Expression: MIT
@@ -1,7 +1,7 @@
1
1
  {
2
- "tag": "1.2.0",
2
+ "tag": "1.2.1",
3
3
  "distance": 0,
4
- "node": "g64f93fcf088912ead1fa9b18103c1f87bd234fd9",
4
+ "node": "ga14960414cf8972ec07269bb1f727886249b10ba",
5
5
  "dirty": false,
6
6
  "branch": "HEAD",
7
7
  "node_date": "2026-11-27"
@@ -520,6 +520,43 @@ def test_transactions(path):
520
520
  assert count() == 4
521
521
 
522
522
 
523
+
524
+ def test_transaction_rolled_back_by_vsql(path):
525
+ """A 40001 rolls back the whole transaction, so the next statement starts a
526
+ new one (which rollback undoes). Other errors only undo the statement."""
527
+
528
+ with vsql.connect(path) as conn:
529
+ conn.execute("CREATE TABLE t (x INTEGER PRIMARY KEY)")
530
+ conn.execute("INSERT INTO t (x) VALUES (1)")
531
+
532
+ a, b = vsql.connect(path), vsql.connect(path)
533
+ a.execute("UPDATE t SET x = 100 WHERE x = 1")
534
+ b.execute("INSERT INTO t (x) VALUES (50)")
535
+ cur = b.execute("SELECT x FROM t")
536
+ with pytest.raises(vsql.OperationalError) as e:
537
+ b.execute("UPDATE t SET x = 200 WHERE x = 1")
538
+ assert e.value.sqlstate == "40001"
539
+ assert not b.in_transaction
540
+ assert cur.fetchone() is None
541
+ a.commit()
542
+
543
+ b.execute("INSERT INTO t (x) VALUES (60)")
544
+ assert b.in_transaction
545
+ b.rollback()
546
+ assert not b.in_transaction
547
+
548
+ # A unique violation only undoes the statement.
549
+ b.execute("INSERT INTO t (x) VALUES (70)")
550
+ with pytest.raises(vsql.IntegrityError):
551
+ b.execute("INSERT INTO t (x) VALUES (70)")
552
+ assert b.in_transaction
553
+ b.commit()
554
+ a.close()
555
+ b.close()
556
+
557
+ with vsql.connect(path) as conn:
558
+ assert conn.execute("SELECT x FROM t ORDER BY x").fetchall() == [(70,), (100,)]
559
+
523
560
  def test_savepoints(path):
524
561
  conn = vsql.connect(path)
525
562
  conn.execute("CREATE TABLE foo (x INTEGER)")
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes