vsql-python 1.2.4__tar.gz → 1.2.7__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.4 → vsql_python-1.2.7}/PKG-INFO +35 -5
  2. {vsql_python-1.2.4 → vsql_python-1.2.7}/README.md +34 -4
  3. {vsql_python-1.2.4 → vsql_python-1.2.7}/src/vsql/__init__.py +8 -5
  4. {vsql_python-1.2.4 → vsql_python-1.2.7}/src/vsql/_connection.py +19 -3
  5. {vsql_python-1.2.4 → vsql_python-1.2.7}/src/vsql_python.egg-info/PKG-INFO +35 -5
  6. {vsql_python-1.2.4 → vsql_python-1.2.7}/src/vsql_python.egg-info/scm_version.json +2 -2
  7. {vsql_python-1.2.4 → vsql_python-1.2.7}/tests/test_vsql.py +18 -3
  8. {vsql_python-1.2.4 → vsql_python-1.2.7}/.github/workflows/release.yml +0 -0
  9. {vsql_python-1.2.4 → vsql_python-1.2.7}/.github/workflows/test.yml +0 -0
  10. {vsql_python-1.2.4 → vsql_python-1.2.7}/.gitignore +0 -0
  11. {vsql_python-1.2.4 → vsql_python-1.2.7}/LICENSE +0 -0
  12. {vsql_python-1.2.4 → vsql_python-1.2.7}/MANIFEST.in +0 -0
  13. {vsql_python-1.2.4 → vsql_python-1.2.7}/example/main.py +0 -0
  14. {vsql_python-1.2.4 → vsql_python-1.2.7}/internal/amalgamation/LICENSE +0 -0
  15. {vsql_python-1.2.4 → vsql_python-1.2.7}/internal/amalgamation/LICENSE-V +0 -0
  16. {vsql_python-1.2.4 → vsql_python-1.2.7}/internal/amalgamation/libvsql.c +0 -0
  17. {vsql_python-1.2.4 → vsql_python-1.2.7}/internal/amalgamation/libvsql.h +0 -0
  18. {vsql_python-1.2.4 → vsql_python-1.2.7}/libvsql_flags.json +0 -0
  19. {vsql_python-1.2.4 → vsql_python-1.2.7}/pyproject.toml +0 -0
  20. {vsql_python-1.2.4 → vsql_python-1.2.7}/scripts/update-amalgamation.sh +0 -0
  21. {vsql_python-1.2.4 → vsql_python-1.2.7}/setup.cfg +0 -0
  22. {vsql_python-1.2.4 → vsql_python-1.2.7}/setup.py +0 -0
  23. {vsql_python-1.2.4 → vsql_python-1.2.7}/src/vsql/_convert.py +0 -0
  24. {vsql_python-1.2.4 → vsql_python-1.2.7}/src/vsql/_errors.py +0 -0
  25. {vsql_python-1.2.4 → vsql_python-1.2.7}/src/vsql/_libvsql.c +0 -0
  26. {vsql_python-1.2.4 → vsql_python-1.2.7}/src/vsql_python.egg-info/SOURCES.txt +0 -0
  27. {vsql_python-1.2.4 → vsql_python-1.2.7}/src/vsql_python.egg-info/dependency_links.txt +0 -0
  28. {vsql_python-1.2.4 → vsql_python-1.2.7}/src/vsql_python.egg-info/scm_file_list.json +0 -0
  29. {vsql_python-1.2.4 → vsql_python-1.2.7}/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.4
3
+ Version: 1.2.7
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
@@ -61,7 +61,35 @@ the connection rolls it back). With `vsql.connect(..., autocommit=True)` (or
61
61
  when all the rows of a query have been fetched. `START TRANSACTION`, `COMMIT`
62
62
  and `ROLLBACK` can't be executed as statements.
63
63
 
64
- vsql's transactions are `READ COMMITTED`.
64
+ With autocommit on, a query's transaction lasts until all of its rows have
65
+ been fetched (or its cursor is closed, or executes another statement), so a
66
+ cursor that's left part way through a query can block other connections that
67
+ write to the database file.
68
+
69
+ ### Isolation levels
70
+
71
+ ```python
72
+ conn = vsql.connect("test.vsql", isolation_level="SERIALIZABLE", read_only=False)
73
+ ```
74
+
75
+ `isolation_level` is `"READ COMMITTED"` (the default), `"SERIALIZABLE"`,
76
+ `"REPEATABLE READ"` (which vsql runs as `SERIALIZABLE`) or
77
+ `"READ UNCOMMITTED"` (which vsql runs as `READ COMMITTED`, and is always read
78
+ only), in any case. `read_only=True` starts `READ ONLY` transactions, where a
79
+ change is `25006`. They're for the transactions that the driver starts when
80
+ autocommit is off.
81
+
82
+ vsql's own default is `SERIALIZABLE`, but a `SERIALIZABLE` transaction waits
83
+ for the other transactions on the same file to finish (for up to 5 seconds,
84
+ then it's `40001`). With autocommit off, a connection is in a transaction from
85
+ its first statement until it commits or rolls back, so the driver's default is
86
+ `READ COMMITTED` instead, which only fails (`40001`) when two transactions
87
+ change the same row.
88
+
89
+ ### Statements
90
+
91
+ Each `execute` is one statement (a `;` between statements is `42601`), and vsql
92
+ doesn't allow `--` comments (`42000`), but `/* ... */` comments work.
65
93
 
66
94
  ### Savepoints
67
95
 
@@ -140,9 +168,11 @@ The `type_code` in `cursor.description` is the name of the type (such as
140
168
  `vsql.NUMBER`, `vsql.STRING`, `vsql.BINARY` or `vsql.DATETIME` (which includes
141
169
  the intervals). The `internal_size` is the length of a string (in octets, 4 for
142
170
  each character) or a binary string, the precision of a number, or the length of
143
- a datetime or interval. The `precision` and `scale` are those of a `DECIMAL`
144
- or `NUMERIC`, the precision of a `DECFLOAT` (16 or 34), or the leading field
145
- precision and the fractional seconds precision of an interval.
171
+ a datetime or interval (which is also its `display_size`). The `precision` and
172
+ `scale` are those of a `DECIMAL` or `NUMERIC`, the precision of a `DECFLOAT`
173
+ (16 or 34), or the leading field precision and the fractional seconds
174
+ precision of an interval. The `scale` of a `TIME` or `TIMESTAMP` is its
175
+ fractional seconds precision.
146
176
 
147
177
  ## Errors
148
178
 
@@ -42,7 +42,35 @@ the connection rolls it back). With `vsql.connect(..., autocommit=True)` (or
42
42
  when all the rows of a query have been fetched. `START TRANSACTION`, `COMMIT`
43
43
  and `ROLLBACK` can't be executed as statements.
44
44
 
45
- vsql's transactions are `READ COMMITTED`.
45
+ With autocommit on, a query's transaction lasts until all of its rows have
46
+ been fetched (or its cursor is closed, or executes another statement), so a
47
+ cursor that's left part way through a query can block other connections that
48
+ write to the database file.
49
+
50
+ ### Isolation levels
51
+
52
+ ```python
53
+ conn = vsql.connect("test.vsql", isolation_level="SERIALIZABLE", read_only=False)
54
+ ```
55
+
56
+ `isolation_level` is `"READ COMMITTED"` (the default), `"SERIALIZABLE"`,
57
+ `"REPEATABLE READ"` (which vsql runs as `SERIALIZABLE`) or
58
+ `"READ UNCOMMITTED"` (which vsql runs as `READ COMMITTED`, and is always read
59
+ only), in any case. `read_only=True` starts `READ ONLY` transactions, where a
60
+ change is `25006`. They're for the transactions that the driver starts when
61
+ autocommit is off.
62
+
63
+ vsql's own default is `SERIALIZABLE`, but a `SERIALIZABLE` transaction waits
64
+ for the other transactions on the same file to finish (for up to 5 seconds,
65
+ then it's `40001`). With autocommit off, a connection is in a transaction from
66
+ its first statement until it commits or rolls back, so the driver's default is
67
+ `READ COMMITTED` instead, which only fails (`40001`) when two transactions
68
+ change the same row.
69
+
70
+ ### Statements
71
+
72
+ Each `execute` is one statement (a `;` between statements is `42601`), and vsql
73
+ doesn't allow `--` comments (`42000`), but `/* ... */` comments work.
46
74
 
47
75
  ### Savepoints
48
76
 
@@ -121,9 +149,11 @@ The `type_code` in `cursor.description` is the name of the type (such as
121
149
  `vsql.NUMBER`, `vsql.STRING`, `vsql.BINARY` or `vsql.DATETIME` (which includes
122
150
  the intervals). The `internal_size` is the length of a string (in octets, 4 for
123
151
  each character) or a binary string, the precision of a number, or the length of
124
- a datetime or interval. The `precision` and `scale` are those of a `DECIMAL`
125
- or `NUMERIC`, the precision of a `DECFLOAT` (16 or 34), or the leading field
126
- precision and the fractional seconds precision of an interval.
152
+ a datetime or interval (which is also its `display_size`). The `precision` and
153
+ `scale` are those of a `DECIMAL` or `NUMERIC`, the precision of a `DECFLOAT`
154
+ (16 or 34), or the leading field precision and the fractional seconds
155
+ precision of an interval. The `scale` of a `TIME` or `TIMESTAMP` is its
156
+ fractional seconds precision.
127
157
 
128
158
  ## Errors
129
159
 
@@ -19,7 +19,8 @@ Like PEP 249 requires, autocommit is off: the first statement starts a
19
19
  transaction, which is ended by commit or rollback (or closing the connection,
20
20
  which rolls it back). With autocommit on, each statement is committed when it
21
21
  finishes, or when the rows of a query have all been fetched. START TRANSACTION,
22
- COMMIT and ROLLBACK can't be executed as statements.
22
+ COMMIT and ROLLBACK can't be executed as statements. Each execute is one
23
+ statement, and vsql doesn't allow "--" comments.
23
24
 
24
25
  A savepoint is made by executing SAVEPOINT, and released by executing RELEASE
25
26
  SAVEPOINT. ROLLBACK TO SAVEPOINT can't be executed as a statement either, so
@@ -121,10 +122,12 @@ def connect(database, autocommit=False, isolation_level="READ COMMITTED", read_o
121
122
  exist) or ":memory:".
122
123
 
123
124
  isolation_level ("READ UNCOMMITTED", "READ COMMITTED", "REPEATABLE READ"
124
- or "SERIALIZABLE") and read_only are for the transactions that are started
125
- when autocommit is off. vsql runs READ UNCOMMITTED as READ COMMITTED, and
126
- REPEATABLE READ as SERIALIZABLE. A READ UNCOMMITTED transaction is always
127
- read only.
125
+ or "SERIALIZABLE", in any case) and read_only are for the transactions
126
+ that are started when autocommit is off. vsql runs READ UNCOMMITTED as
127
+ READ COMMITTED, and REPEATABLE READ as SERIALIZABLE. A READ UNCOMMITTED
128
+ transaction is always read only. The default is READ COMMITTED, rather
129
+ than vsql's SERIALIZABLE, since a SERIALIZABLE transaction waits for the
130
+ other transactions on the file to finish.
128
131
  """
129
132
 
130
133
  return Connection(database, autocommit, isolation_level, read_only)
@@ -23,13 +23,14 @@ class Connection:
23
23
 
24
24
  def __init__(self, database, autocommit=False, isolation_level="READ COMMITTED",
25
25
  read_only=False):
26
+ level = isolation_level.upper() if isinstance(isolation_level, str) else None
26
27
  try:
27
- self._isolation_level = _isolation_levels[isolation_level]
28
+ self._isolation_level = _isolation_levels[level]
28
29
  except KeyError:
29
30
  raise ProgrammingError(f"unknown isolation level: {isolation_level!r}") from None
30
31
  # A READ UNCOMMITTED transaction must be READ ONLY.
31
32
  self._access_mode = (lib.SQL_TRANSACTION_READ_ONLY
32
- if read_only or isolation_level == "READ UNCOMMITTED"
33
+ if read_only or level == "READ UNCOMMITTED"
33
34
  else lib.SQL_TRANSACTION_READ_WRITE)
34
35
  self._autocommit = bool(autocommit)
35
36
  self._in_transaction = False
@@ -171,6 +172,12 @@ class Connection:
171
172
 
172
173
  return self.cursor().execute(operation, parameters)
173
174
 
175
+ def executemany(self, operation, seq_of_parameters):
176
+ """Executes a statement for each sequence of parameters with a new
177
+ cursor, which is returned."""
178
+
179
+ return self.cursor().executemany(operation, seq_of_parameters)
180
+
174
181
  def close(self):
175
182
  """Closes the connection and its cursors. A transaction that hasn't been
176
183
  committed is rolled back. It does nothing if it's already closed."""
@@ -302,8 +309,9 @@ class Cursor:
302
309
 
303
310
  def executemany(self, operation, seq_of_parameters):
304
311
  """Executes a statement for each sequence of parameters. rowcount is
305
- the total of the rows affected."""
312
+ the total of the rows affected. It returns the cursor."""
306
313
 
314
+ self._check()
307
315
  total = 0
308
316
  for parameters in seq_of_parameters:
309
317
  self.execute(operation, parameters)
@@ -312,6 +320,8 @@ class Cursor:
312
320
  total += max(self.rowcount, 0)
313
321
  self.rowcount = total
314
322
 
323
+ return self
324
+
315
325
  def fetchone(self):
316
326
  """The next row as a tuple, or None if there are no more."""
317
327
 
@@ -414,6 +424,12 @@ def _column(name, type_name, size, digits, nullable, leading=None):
414
424
  precision, scale = size, digits
415
425
  elif type_name == "DECFLOAT":
416
426
  precision = size
427
+ elif type_name.startswith(("TIME", "DATE")):
428
+ # The size is the length of the datetime in positions, and the scale
429
+ # is the fractional seconds precision (a DATE has none).
430
+ display_size = size
431
+ if type_name != "DATE":
432
+ scale = digits
417
433
  elif leading is not None:
418
434
  # An interval's precision is the leading field precision, and its scale
419
435
  # is the fractional seconds precision (if it ends with SECOND). The
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vsql-python
3
- Version: 1.2.4
3
+ Version: 1.2.7
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
@@ -61,7 +61,35 @@ the connection rolls it back). With `vsql.connect(..., autocommit=True)` (or
61
61
  when all the rows of a query have been fetched. `START TRANSACTION`, `COMMIT`
62
62
  and `ROLLBACK` can't be executed as statements.
63
63
 
64
- vsql's transactions are `READ COMMITTED`.
64
+ With autocommit on, a query's transaction lasts until all of its rows have
65
+ been fetched (or its cursor is closed, or executes another statement), so a
66
+ cursor that's left part way through a query can block other connections that
67
+ write to the database file.
68
+
69
+ ### Isolation levels
70
+
71
+ ```python
72
+ conn = vsql.connect("test.vsql", isolation_level="SERIALIZABLE", read_only=False)
73
+ ```
74
+
75
+ `isolation_level` is `"READ COMMITTED"` (the default), `"SERIALIZABLE"`,
76
+ `"REPEATABLE READ"` (which vsql runs as `SERIALIZABLE`) or
77
+ `"READ UNCOMMITTED"` (which vsql runs as `READ COMMITTED`, and is always read
78
+ only), in any case. `read_only=True` starts `READ ONLY` transactions, where a
79
+ change is `25006`. They're for the transactions that the driver starts when
80
+ autocommit is off.
81
+
82
+ vsql's own default is `SERIALIZABLE`, but a `SERIALIZABLE` transaction waits
83
+ for the other transactions on the same file to finish (for up to 5 seconds,
84
+ then it's `40001`). With autocommit off, a connection is in a transaction from
85
+ its first statement until it commits or rolls back, so the driver's default is
86
+ `READ COMMITTED` instead, which only fails (`40001`) when two transactions
87
+ change the same row.
88
+
89
+ ### Statements
90
+
91
+ Each `execute` is one statement (a `;` between statements is `42601`), and vsql
92
+ doesn't allow `--` comments (`42000`), but `/* ... */` comments work.
65
93
 
66
94
  ### Savepoints
67
95
 
@@ -140,9 +168,11 @@ The `type_code` in `cursor.description` is the name of the type (such as
140
168
  `vsql.NUMBER`, `vsql.STRING`, `vsql.BINARY` or `vsql.DATETIME` (which includes
141
169
  the intervals). The `internal_size` is the length of a string (in octets, 4 for
142
170
  each character) or a binary string, the precision of a number, or the length of
143
- a datetime or interval. The `precision` and `scale` are those of a `DECIMAL`
144
- or `NUMERIC`, the precision of a `DECFLOAT` (16 or 34), or the leading field
145
- precision and the fractional seconds precision of an interval.
171
+ a datetime or interval (which is also its `display_size`). The `precision` and
172
+ `scale` are those of a `DECIMAL` or `NUMERIC`, the precision of a `DECFLOAT`
173
+ (16 or 34), or the leading field precision and the fractional seconds
174
+ precision of an interval. The `scale` of a `TIME` or `TIMESTAMP` is its
175
+ fractional seconds precision.
146
176
 
147
177
  ## Errors
148
178
 
@@ -1,7 +1,7 @@
1
1
  {
2
- "tag": "1.2.4",
2
+ "tag": "1.2.7",
3
3
  "distance": 0,
4
- "node": "g0b0758702b056f82af03c38364865fd90bee905a",
4
+ "node": "gb80bd041eedd2fe41cd10171ed6b5a77ca59f954",
5
5
  "dirty": false,
6
6
  "branch": "HEAD",
7
7
  "node_date": "2026-11-27"
@@ -147,6 +147,16 @@ def test_description(conn):
147
147
  assert y[1:6] == ("INTERVAL YEAR TO MONTH", 7, 7, 3, None)
148
148
  assert s[1:6] == ("INTERVAL DAY TO SECOND", 18, 18, 4, 3)
149
149
 
150
+ # The scale of a TIME or TIMESTAMP is the fractional seconds precision.
151
+ conn.execute("""CREATE TABLE baz (d DATE, t TIME, tz TIME(6) WITH TIME ZONE,
152
+ ts TIMESTAMP(3), tsz TIMESTAMP WITH TIME ZONE)""")
153
+ d, t, tz, ts, tsz = conn.execute("SELECT * FROM baz").description
154
+ assert d[1:6] == ("DATE", 10, 10, None, None)
155
+ assert t[1:6] == ("TIME", 8, 8, None, 0)
156
+ assert tz[1:6] == ("TIME WITH TIME ZONE", 21, 21, None, 6)
157
+ assert ts[1:6] == ("TIMESTAMP", 23, 23, None, 3)
158
+ assert tsz[1:6] == ("TIMESTAMP WITH TIME ZONE", 32, 32, None, 6)
159
+
150
160
  # A statement that isn't a query has no description.
151
161
  conn.execute("DELETE FROM foo")
152
162
  cur = conn.execute("DELETE FROM foo")
@@ -414,8 +424,10 @@ def test_rowcount(conn):
414
424
  assert cur.lastrowid is None
415
425
  assert conn.execute("SELECT * FROM foo").rowcount == -1
416
426
 
417
- cur.executemany("INSERT INTO foo (x) VALUES (?)", [[3], [4], [5]])
427
+ assert cur.executemany("INSERT INTO foo (x) VALUES (?)", [[3], [4], [5]]) is cur
418
428
  assert cur.rowcount == 3
429
+ assert conn.executemany("INSERT INTO foo (x) VALUES (?)", [[6], [7]]).rowcount == 2
430
+ assert conn.executemany("INSERT INTO foo (x) VALUES (?)", []).rowcount == 0
419
431
 
420
432
 
421
433
  def test_fetch(conn):
@@ -636,14 +648,15 @@ def test_commit_closes_cursors(path):
636
648
 
637
649
 
638
650
  def test_isolation_levels(path):
639
- for level in ["READ COMMITTED", "REPEATABLE READ", "SERIALIZABLE"]:
651
+ for level in ["READ COMMITTED", "REPEATABLE READ", "SERIALIZABLE", "serializable"]:
640
652
  with vsql.connect(path, isolation_level=level) as conn:
641
653
  assert scalar(conn, "VALUES 1") == 1
642
654
  conn.execute("CREATE TABLE t (x INT)")
643
655
  conn.rollback()
644
656
 
645
657
  # READ UNCOMMITTED is always read only.
646
- for options in [{"isolation_level": "READ UNCOMMITTED"}, {"read_only": True}]:
658
+ for options in [{"isolation_level": "READ UNCOMMITTED"},
659
+ {"isolation_level": "read uncommitted"}, {"read_only": True}]:
647
660
  with vsql.connect(path, **options) as conn:
648
661
  assert scalar(conn, "VALUES 1") == 1
649
662
  with pytest.raises(vsql.OperationalError) as e:
@@ -652,6 +665,8 @@ def test_isolation_levels(path):
652
665
 
653
666
  with pytest.raises(vsql.ProgrammingError):
654
667
  vsql.connect(path, isolation_level="SNAPSHOT")
668
+ with pytest.raises(vsql.ProgrammingError):
669
+ vsql.connect(path, isolation_level=None)
655
670
 
656
671
 
657
672
  def test_persistence(path):
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes