skaidb 1.5.0 → 1.5.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c1684623cac79f6c62a066686a0a6f6af3af9141a7434eb4b3a297a7c0d4d9f1
4
- data.tar.gz: 62a78c8e58e4ce110e2ae3ce52ccc2dd246bb9481aeee68d80292b46e17c2d2f
3
+ metadata.gz: 818a2b6adaefda4048711f0eed371dd8ab73a05ec59edbd46cef8e390e2cc909
4
+ data.tar.gz: 7dbffebfc11f59072c55ae18f8a350a5ae0e4e21446449d40db074fc891b5d12
5
5
  SHA512:
6
- metadata.gz: c85ce23da9ad6e8fb7a372190ace6ef40226319fa601ecbbc2477d891a272a1303b919494d2b10f98aae441c0583802b2ce729c381b000da021bbdef12933f5d
7
- data.tar.gz: 82d387c4e1ce106331ac57dc8cf20225018f8fa491fc73ab8954062eb3624d3b191882b32ca801cdc7edbffd2922990bebbd83050e2ee8cceef24a6712491046
6
+ metadata.gz: 9a97060e9ff4ae284d56eeeaf8f06ab1c817726696ada1dda2ef2eb5137fddbd11385d6cdb92493612740b79a87bebe1c9e285102aa63f9b053b9a681793c3eb
7
+ data.tar.gz: 2a992604955c5ceba123fe3b5ea4b9a054b3d7360d8caf1c5de839a8c9bda79e5129b4152d30e74ccf754bd230a7f574c699f0672dd79ba49200d9772a1911d1
data/CHANGELOG.md CHANGED
@@ -4,6 +4,171 @@ All notable changes to the skaidb Ruby driver. The format follows
4
4
  [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); versions follow
5
5
  [Semantic Versioning](https://semver.org/).
6
6
 
7
+ ## [1.5.2] - 2026-11-16
8
+
9
+ ### Fixed
10
+ - **A connection the server closed while it sat idle costs no statement.**
11
+ A member restart, a failover or an idle timeout closes idle connections,
12
+ and the first statement on each of them raised `ConnectionError` — once
13
+ per idle connection, after every restart; only the statement after it
14
+ re-dialled. The driver now looks at the socket before it writes a request
15
+ (one peek that does not wait, no round trip): an idle connection has
16
+ nothing to read, so an end-of-file, a reset or bytes nobody asked for
17
+ mean it is gone, and the statement runs on a new connection with the
18
+ session restored on it. A pool does not hand out an idle connection that
19
+ was lost. Under TLS the TCP socket is looked at, and bytes the TLS layer
20
+ has already decrypted count too. A connection lost *under* a statement —
21
+ request written, no reply — still raises `ConnectionError`, since the
22
+ statement may have run.
23
+ - **A pool hands every borrower its own session state.** A pooled
24
+ connection kept what its last borrower had done to the session: a `USE`
25
+ (on a pool without `database:`), a `SET CONSISTENCY`, a `SET SCAN BUDGET`,
26
+ a transaction left open. The next borrower read another database's
27
+ tables, was refused for someone else's scan budget, or had its writes
28
+ swallowed by a transaction it knew nothing of. A connection now reaches
29
+ each borrower in the pool's database (`database:`, or `default` when the
30
+ pool names none) with no transaction open and neither setting: what a
31
+ borrower changed is put back when the connection is returned (`ROLLBACK`,
32
+ `USE`, `SET SCAN BUDGET DEFAULT`, `SET CONSISTENCY DEFAULT`, only the
33
+ ones needed), and a connection that cannot be put back is closed.
34
+ - **`SET CONSISTENCY` and `SET SCAN BUDGET` survive a re-dial.** Both are
35
+ state of the server's session, and a re-dialled connection came back
36
+ without them: a scan the application had limited ran unlimited, a read
37
+ asked for at `ALL` ran at the request's own level. The last one of each
38
+ the server accepted is now sent again on every dial, after the database
39
+ and before the statement; `… DEFAULT` clears it. A setting the new
40
+ session refuses fails the statement instead of letting it run without.
41
+ - **A transaction written by hand is a transaction to the driver too.**
42
+ Only `transaction` kept a lost connection from being replaced. After
43
+ `exec("BEGIN")` a lost connection was re-dialled, and the rest of the
44
+ statements — and the `COMMIT` — ran on a new session, each committed on
45
+ its own. A `BEGIN` the server accepted is now followed until `COMMIT` or
46
+ `ROLLBACK` ends it: while it is open a lost connection is not replaced,
47
+ every statement raises `ConnectionError`, `ROLLBACK` succeeds without
48
+ being sent and `COMMIT` raises (`COMMIT was not sent and nothing was
49
+ committed`). A connection lost under the `COMMIT` itself says that the
50
+ outcome is not known, from `transaction` as well.
51
+ - **A `USE` gets a connection out of a database that is gone.** When the
52
+ session's database had been dropped and the connection was lost, every
53
+ statement failed at the re-dial's `USE` — and so did a `USE` of another
54
+ database, because the old one was entered first. A `USE` is now sent to
55
+ the new session without that.
56
+ - **`transaction` cut short between two statements leaves no transaction
57
+ open.** A `Timeout` or an `Interrupt` landing just after the opening
58
+ statement's reply, or with the block done and `COMMIT` not yet written,
59
+ left the transaction open on a connection that went on being used. The
60
+ socket is now closed unless the server has answered a `ROLLBACK` or the
61
+ `COMMIT`.
62
+ - **A reply that cannot be read drops the connection.** An unknown
63
+ response tag or a message shorter than its own fields say raised
64
+ `ConnectionError` and left the connection usable, with whatever followed
65
+ on the socket for the next statement to read as its reply.
66
+ - A stream cut short between its header frame and its first row (a
67
+ `Timeout`, an `Interrupt`) left the rest of the stream on a connection
68
+ that looked idle. It is now marked broken.
69
+ - A dial that moved on from an endpoint whose handshake failed to one that
70
+ answered left the connection marked broken: `usable?` was false on a
71
+ healthy socket, the next statement dialled again, and a pool threw the
72
+ connection away and dialled once more.
73
+ - A connect that failed after its handshake (a `database:` the server
74
+ refuses, a connect cut short) left its socket open until the collector
75
+ closed it. It is closed at once.
76
+ - Under `ruby -w` on Ruby 2.7, a dial whose first endpoint refused the
77
+ connection printed `instance variable @sock not initialized`.
78
+
79
+ ### Changed
80
+ - On a pool without a `database:` option a borrower's `USE` no longer
81
+ carries over to later borrowers: the connection goes back to `default`
82
+ when it is returned. Send `USE` after each checkout, or give the
83
+ database a pool of its own (`database:`).
84
+ - A pool puts a connection back in its own state when the connection is
85
+ returned, not when it is next handed out; a borrower that left a
86
+ transaction open has it rolled back there.
87
+ - The statement that finds its connection closed by a restart no longer
88
+ raises `ConnectionError`: code that caught it and ran the statement again
89
+ keeps working, and no longer needs to.
90
+ - After a connection is lost inside a hand-written `BEGIN` … `COMMIT`, every
91
+ statement raises `ConnectionError` until `ROLLBACK` or `COMMIT` ends the
92
+ transaction; they used to run on a new session.
93
+
94
+ ### Added
95
+ - `Connection#lost_while_idle?` — the look at the socket on its own.
96
+ - `examples/transaction.rb`; the opt-in live test covers transactions and
97
+ session state.
98
+
99
+ ## [1.5.1] - 2026-11-16
100
+
101
+ ### Fixed
102
+ - **A connection marked broken closes its socket at once.** A connection
103
+ whose transport failed, or that was left in the middle of a reply
104
+ (`Timeout.timeout`, an `Interrupt`, `Thread#kill`), kept its socket open
105
+ until its next statement re-dialled or it was closed. The server keeps a
106
+ session for as long as its socket is open, so a statement that timed out
107
+ inside a transaction left that transaction open on the server until the
108
+ application came back to the connection. The socket is now closed when
109
+ the connection is marked broken.
110
+ - **A stream the `transaction` block leaves open no longer leaves a
111
+ transaction to join.** A block that returned or raised with an Enumerator
112
+ from `stream` advanced by `next` and not read to its end left `COMMIT` and
113
+ `ROLLBACK` unable to be sent (`COMMIT` raised `ThreadError`), and the
114
+ transaction open; once the Enumerator was read to its end, every later
115
+ statement on the connection ran inside that transaction and was lost
116
+ with it. The helper now closes the socket — the server drops the
117
+ transaction — and ends the stream, so the next statement re-dials; a
118
+ block that ran to its end gets `ConnectionError`, one that was leaving
119
+ with an exception, `break` or `throw` leaves with that.
120
+ - **The session database survives a re-dial when it was entered with a
121
+ `USE` statement.** Only `database:` was re-entered; after `USE app` sent
122
+ with `exec`, a re-dialled connection was in the default database, and its
123
+ statements ran against that database's tables of the same names. The
124
+ connection now follows the last `USE [DATABASE] <name>` the server
125
+ accepted — written with a `--` comment or without — and re-enters it on
126
+ every dial before anything else is sent; if the server refuses, the
127
+ statement raises that error instead of running elsewhere. A pool with
128
+ `database:` puts a connection a borrower moved with `USE` back in that
129
+ database before it hands it out again.
130
+ - **Any number of distinct parameterised statements on one connection.**
131
+ The server holds 256 prepared statements per connection, and the driver
132
+ never closed one: from the 257th distinct statement on, the prepare was
133
+ refused and `exec_params` silently sent the statement as text with
134
+ client-side literals — a `Time` stored as a number, bytes as a hex
135
+ string — or failed for an Array or Hash parameter. The cache now closes
136
+ its least recently used statement on the server before it would pass 240,
137
+ and a prepare refused with `too many prepared statements` raises
138
+ `QueryError` instead of falling back.
139
+ - **An id from `prepare_server` never runs another statement.** An id held
140
+ across a re-dial was sent to the new socket, where the server did not
141
+ know it or, worse, had given the number to a different statement since.
142
+ An id now carries the socket that issued it: `exec_prepared` prepares the
143
+ statement again on the current socket when the connection has re-dialled
144
+ (re-dialling first if it is broken, where it used to raise `connection is
145
+ broken; prepare the statement again`), and raises `QueryError` for an id
146
+ another connection issued. Ids are larger numbers than before; statements
147
+ handed out by `prepare_server` are never closed by the driver's cache.
148
+ - **A stream Enumerator dropped half-read no longer crashes the process.**
149
+ `conn.stream(sql).next` runs the stream in the Enumerator's Fiber, inside
150
+ the connection's lock. Dropped there, the Fiber was collected still
151
+ owning the lock, and Ruby (3.3.8 measured) crashed when the lock was
152
+ freed after it: a segfault or an abort at a later garbage collection or
153
+ at exit, or a spin at exit. The driver now keeps the lock of a stream in
154
+ flight alive until the stream ends. The connection of a stream left that
155
+ way is still lost — read the Enumerator to its end to keep it.
156
+ - **`Timeout.timeout` around a stream times out.** A stream cut short while
157
+ it waited for a frame (a `Timeout`, an `Interrupt`, `Thread#kill`) went on
158
+ to drain the rest of the result before the exception could propagate —
159
+ for as long as the server took, or for ever — and could read on from the
160
+ middle of a frame. It now marks the connection broken and raises at once.
161
+ - A drain cut short the same way (a stream whose block breaks out, under a
162
+ timeout) left the rest of the stream on a connection that was not marked
163
+ broken: the next statements read the leftover chunks, and after them each
164
+ statement got the reply of an earlier one. The connection is now marked
165
+ broken.
166
+ - A re-dial cut short the same way left a half-made connection whose next
167
+ statement read the handshake's or `Hello`'s reply as its own. It is now
168
+ marked broken and dialled again.
169
+ - A re-dial that fails because no member is reachable no longer closes the
170
+ connection for good: the next statement dials again, as documented.
171
+
7
172
  ## [1.5.0] - 2026-11-15
8
173
 
9
174
  ### Added
@@ -280,6 +445,8 @@ batches, a 2 500-row stream, error handling, and the `drivers` table showing
280
445
  because it is a bundled gem since Ruby 3.4.
281
446
  - The example moved to `examples/basic.rb`.
282
447
 
448
+ [1.5.2]: https://github.com/porcupin26/skaidb-ruby/compare/v1.5.1...v1.5.2
449
+ [1.5.1]: https://github.com/porcupin26/skaidb-ruby/compare/v1.5.0...v1.5.1
283
450
  [1.5.0]: https://github.com/porcupin26/skaidb-ruby/compare/v1.4.1...v1.5.0
284
451
  [1.4.1]: https://github.com/porcupin26/skaidb-ruby/compare/v1.4.0...v1.4.1
285
452
  [1.4.0]: https://github.com/porcupin26/skaidb-ruby/compare/v1.3.0...v1.4.0
data/README.md CHANGED
@@ -55,13 +55,13 @@ Xcode command-line tools on macOS). `gem install skaidb` and vendoring reuse
55
55
  the `bigdecimal` already installed.
56
56
 
57
57
  Or vendor the single file: copy
58
- [`lib/skaidb.rb`](https://github.com/porcupin26/skaidb-ruby/blob/v1.5.0/lib/skaidb.rb)
58
+ [`lib/skaidb.rb`](https://github.com/porcupin26/skaidb-ruby/blob/v1.5.2/lib/skaidb.rb)
59
59
  into your project and `require_relative` it. It has no dependencies beyond
60
60
  Ruby's standard library.
61
61
 
62
62
  Every release is also attached as a `.gem` to its
63
63
  [GitHub release](https://github.com/porcupin26/skaidb-ruby/releases) for
64
- installs without registry access: `gem install ./skaidb-1.5.0.gem`.
64
+ installs without registry access: `gem install ./skaidb-1.5.2.gem`.
65
65
 
66
66
  ## Quick start
67
67
 
@@ -146,10 +146,33 @@ conn = Skaidb.connect(seeds: ["db1", "db2:7000", "db3"], database: "app")
146
146
  Each seed is `"host"` or `"host:port"` (the port after the last colon wins; a
147
147
  seed without a port uses `port:`). When a connection's transport dies, the
148
148
  **next statement re-dials** across the same seeds, re-authenticates, re-sends
149
- `Hello`, re-runs `USE`, and drops the connection's prepared statements — a
150
- recovered connection is indistinguishable from a fresh one. The statement that
151
- discovered the loss raises `Skaidb::ConnectionError`; the one after it goes
152
- through.
149
+ `Hello`, re-enters the session's database, and drops the connection's prepared
150
+ statements.
151
+
152
+ A connection the server closed **while it sat idle** — a member restart, a
153
+ failover, an idle timeout — costs no statement. Before a request is written
154
+ the driver looks at the socket (one peek that does not wait, no round trip): an idle connection
155
+ has nothing to read, so an end-of-file, a reset or stray bytes there mean it
156
+ is gone, and the statement goes out on a new connection instead. A
157
+ connection lost **under a statement** — the request was written and the
158
+ reply did not come — raises `Skaidb::ConnectionError`: the statement may
159
+ have run, so the driver does not send it again. The one after it re-dials.
160
+
161
+ The database re-entered is the one the session was last in: `database:`, or
162
+ the one a later `USE <name>` statement sent with `exec` moved it to. It is
163
+ entered before anything else is sent on the new socket, and if the server
164
+ refuses it the statement raises that error instead of running in another
165
+ database. The one statement that does not wait for it is a `USE`: when the
166
+ session's database is gone — dropped while the connection was down — a
167
+ `USE` of another database is sent to the new session without the old one
168
+ being entered first, so the connection can always be moved out of it.
169
+
170
+ Session settings come back with it. The last `SET CONSISTENCY …` and the
171
+ last `SET SCAN BUDGET …` the server accepted are sent again on the new
172
+ socket, after the database and before the statement; one cleared with
173
+ `… DEFAULT` is not. If the server refuses a setting there, the statement
174
+ raises that error: it never runs under other settings than the ones you
175
+ set.
153
176
 
154
177
  ### Timeout
155
178
 
@@ -159,6 +182,9 @@ not take the connection's lock, so another thread can break a stuck read by
159
182
  closing the connection. A statement cut short while its reply is outstanding
160
183
  — by `Timeout.timeout`, an `Interrupt`, `Thread#kill` — leaves the connection
161
184
  marked broken, so the next statement re-dials instead of reading that reply.
185
+ A connection marked broken closes its socket there and then: the server
186
+ drops the session, and a transaction open on it, without waiting for that
187
+ next statement.
162
188
 
163
189
  ### TLS
164
190
 
@@ -202,11 +228,19 @@ conn.stream("SELECT …", consistency: :one) { |row| … }
202
228
  integer and raises `Skaidb::Error` otherwise. DDL is always run at quorum by
203
229
  the server regardless of this setting.
204
230
 
231
+ These are the level each request carries. A `SET CONSISTENCY { ONE | QUORUM
232
+ | ALL }` statement is something else: it makes the server run every
233
+ statement of the session at that level whatever the request says, until
234
+ `SET CONSISTENCY DEFAULT` (server ≥ 0.349). The driver follows it, and
235
+ `SET SCAN BUDGET`, across re-dials — see
236
+ [Seeds and failover](#seeds-and-failover).
237
+
205
238
  ### Health
206
239
 
207
240
  - `conn.usable?` — no round-trip. `true` unless the connection is closed, was
208
- left out of sync by a transport error, a round trip cut short or an
209
- undrainable abandoned stream, or is currently mid-stream.
241
+ left out of sync by a transport error, a reply that could not be read, a
242
+ round trip cut short or an undrainable abandoned stream, or is currently
243
+ mid-stream.
210
244
  - `conn.closed` / `conn.finished?` — `true` after `close`.
211
245
 
212
246
  ## Statements and parameters
@@ -235,9 +269,12 @@ conn.exec_params("INSERT INTO docs (id, meta) VALUES ($1, $2)",
235
269
  conn.exec_params("SELECT id FROM users WHERE id IN ($1)", [[1, 2, 3]]) # set membership
236
270
  ```
237
271
 
238
- Prepared statements are cached per connection (up to 240 entries, under the
239
- server's 256-per-connection limit) and reused. The cache is dropped when the
240
- connection re-dials.
272
+ Prepared statements are cached per connection and reused. The server holds
273
+ at most 256 per connection, so the cache keeps to 240: before a new statement
274
+ would exceed that, the least recently used one is closed on the server. A
275
+ connection can therefore run any number of distinct parameterised statements,
276
+ every one with typed values. The cache is dropped when the connection
277
+ re-dials.
241
278
 
242
279
  Statement kinds the server refuses to prepare (DDL and session control such
243
280
  as `USE`) fall back to **client-side text binding** for scalar parameters: a
@@ -321,8 +358,9 @@ form — drains the frames the server is still sending so the socket sits at a
321
358
  request boundary again. Draining transfers the rest of the result: if you only
322
359
  want the first rows, say so with `LIMIT`. External iteration (`next`/`peek`)
323
360
  on the Enumerator form cannot unwind and leaves the connection marked busy;
324
- iterate with a block or `each`. A frame that makes no sense mid-stream, or a
325
- dead socket, marks the connection broken instead; `usable?` turns `false`
361
+ iterate with a block or `each`. A frame that makes no sense mid-stream, a
362
+ dead socket, or a stream cut short while it waits for a frame (a `Timeout`,
363
+ an `Interrupt`) marks the connection broken instead; `usable?` turns `false`
326
364
  and the next statement re-dials. Details: [docs/streaming.md](https://github.com/porcupin26/skaidb-ruby/blob/main/docs/streaming.md).
327
365
 
328
366
  ## Connection pool
@@ -341,7 +379,16 @@ pool.close # closes idle connections
341
379
  blocks — when no idle connection is available a new one is dialed, and a
342
380
  returned connection beyond `maxsize` is closed. Connections are validated with
343
381
  `usable?` on checkout and check-in, so one broken by a transport error or an
344
- undrained stream is closed and replaced.
382
+ undrained stream is closed and replaced; and an idle connection the server
383
+ closed while it sat in the pool is found by a look at its socket (no round
384
+ trip) and replaced before it is handed out.
385
+
386
+ Every borrower gets the pool's own session state: the pool's database
387
+ (`database:`, or `default` when it names none), no transaction open, and no
388
+ `SET CONSISTENCY` or `SET SCAN BUDGET` of an earlier borrower. Whatever a
389
+ borrower changed is put back when the connection is returned — a `ROLLBACK`,
390
+ a `USE`, a `SET … DEFAULT`, only the ones needed — and a connection that
391
+ cannot be put back is closed.
345
392
 
346
393
  The pool spreads its connections across the members by the rules every skaidb
347
394
  driver shares
@@ -441,8 +488,10 @@ StandardError
441
488
  `TransactionConflict`, from every call that runs a statement. It is a
442
489
  `QueryError`, so `rescue Skaidb::QueryError` catches it too; see
443
490
  [Transactions](#transactions).
444
- - A transport failure (`ConnectionError`) marks the connection broken; the
445
- next statement re-dials, or a pool replaces it. So does anything else that
491
+ - A transport failure (`ConnectionError`) marks the connection broken and
492
+ closes its socket; the next statement re-dials, or a pool replaces it. So
493
+ does a reply that cannot be read (a tag the protocol does not have, a
494
+ message shorter than its own fields say), and so does anything else that
446
495
  cuts a statement short between its request and its reply (an `Interrupt`,
447
496
  a `Timeout`); that exception propagates as it is.
448
497
  - `ArgumentError` for `Pool.new(maxsize: 0)` or an unknown
@@ -501,7 +550,24 @@ What else `transaction` does:
501
550
  block still runs after rescuing the failure raises `ConnectionError`
502
551
  instead of running on a new session. The same goes for a block cut short
503
552
  in the middle of a round trip (an `Interrupt`, a `Timeout`): the reply is
504
- still on its way, so nothing more is written to that socket.
553
+ still on its way, so nothing more is written to that socket. Either way
554
+ the socket is closed at once, and the server drops the transaction with
555
+ it.
556
+ - Such an exception can also land between two statements — just after the
557
+ opening statement's reply, or with the block done and `COMMIT` not yet
558
+ written. `transaction` never leaves a transaction open on a connection
559
+ that goes on being used: unless the server has answered a `ROLLBACK` or
560
+ the `COMMIT`, the socket is closed, the server drops the transaction with
561
+ it, and the connection's next statement re-dials.
562
+ - A stream the block leaves open — an Enumerator from `stream` advanced with
563
+ `next` or `peek` and not read to its end — sits in the middle of its
564
+ reply, so neither `COMMIT` nor `ROLLBACK` can be sent. The socket is
565
+ closed instead, the server drops the transaction with it, and
566
+ `transaction` raises `ConnectionError` — unless the block was itself
567
+ leaving with an exception, `break` or `throw`, which carries on. The
568
+ stream is ended too, so the connection's next statement re-dials as after
569
+ any lost connection. Read a stream to its end, or give `stream` a block,
570
+ before the transaction's block returns.
505
571
  - `pool.transaction(attempts: 3, begin: "BEGIN", affinity: nil)` checks one
506
572
  connection out, runs every attempt on it, and returns it afterwards.
507
573
 
@@ -514,7 +580,7 @@ begin
514
580
  conn.exec_params("UPDATE accounts SET balance = balance + $1 WHERE id = $2", [10, 2])
515
581
  rescue StandardError
516
582
  begin
517
- conn.exec("ROLLBACK") if conn.usable?
583
+ conn.exec("ROLLBACK")
518
584
  rescue Skaidb::Error
519
585
  nil # the clean-up never replaces the error it follows
520
586
  end
@@ -523,15 +589,34 @@ end
523
589
  conn.exec("COMMIT") # Skaidb::TransactionConflict: nothing was applied; run it again from BEGIN
524
590
  ```
525
591
 
592
+ The driver follows a transaction written this way: a statement the server
593
+ accepted whose first word is `BEGIN` opens it, and `COMMIT [TRANSACTION]` or
594
+ `ROLLBACK [TRANSACTION]` ends it once the server has answered, with success
595
+ or with an error (sent with `exec`, `query`, `exec_params` or `stream`; `--`
596
+ comments are skipped). While it is open **a lost connection is not
597
+ replaced**, exactly as inside `transaction`: a new session has no
598
+ transaction open, and the rest of the statements, and the `COMMIT`, would
599
+ each be committed on their own there.
600
+
601
+ - The statement under which the connection is lost raises
602
+ `Skaidb::ConnectionError`, and so does every statement after it; none is
603
+ sent.
604
+ - `ROLLBACK` then succeeds without being sent — the server discarded the
605
+ transaction with the connection — and `COMMIT` raises `ConnectionError`
606
+ (`connection lost inside a transaction: COMMIT was not sent and nothing
607
+ was committed`). Either one ends the transaction for the driver; the next
608
+ statement re-dials as after any lost connection.
609
+ - A connection lost under the `COMMIT` itself leaves the outcome unknown —
610
+ the server may have applied it before its reply went missing — and the
611
+ `ConnectionError` says so (`connection lost under COMMIT: whether the
612
+ transaction was committed is not known`).
613
+
526
614
  Two rules hold however the statements are sent:
527
615
 
528
616
  - **One connection for the whole transaction.** Statements sent on another
529
617
  connection are not part of it, so with a pool check one connection out
530
618
  (`pool.with`) and keep it until the `COMMIT`; a statement another thread
531
- sends on that connection meanwhile is part of it. A `ConnectionError` ends
532
- the transaction with its socket; the connection's next statement re-dials
533
- and runs on a new session, in autocommit. That is why the example sends
534
- `ROLLBACK` only while the connection is `usable?`.
619
+ sends on that connection meanwhile is part of it.
535
620
  - **Stop if `BEGIN` fails.** No transaction is open, so every statement sent
536
621
  after it would be committed on its own.
537
622
 
@@ -556,7 +641,7 @@ frame after every handshake. It shows up as `client_name = 'ruby'` /
556
641
 
557
642
  ```sql
558
643
  SELECT client_name, client_version FROM drivers;
559
- -- ruby | 1.5.0
644
+ -- ruby | 1.5.2
560
645
  ```
561
646
 
562
647
  The server records the row asynchronously, so a `SELECT` immediately after
@@ -606,11 +691,12 @@ fails when the vendored `vectors.json` differs from the published
606
691
 
607
692
  [`examples/`](https://github.com/porcupin26/skaidb-ruby/tree/main/examples)
608
693
  contains runnable scripts: `basic.rb`, `prepared_batch.rb`, `stream.rb`,
609
- `pool.rb`, `tls.rb`, `subscribe.rb`. Each takes
694
+ `transaction.rb`, `pool.rb`, `tls.rb`, `subscribe.rb`. Each takes
610
695
  `host port user password` on the command line and defaults to
611
696
  `localhost:7000`; the arguments after those differ per script:
612
697
 
613
- - `basic.rb`, `prepared_batch.rb`, `stream.rb`, `pool.rb`: `[database]`
698
+ - `basic.rb`, `prepared_batch.rb`, `stream.rb`, `transaction.rb`, `pool.rb`:
699
+ `[database]`
614
700
  - `subscribe.rb`: `[database] [stream]` (the stream defaults to
615
701
  `orders_stream`)
616
702
  - `tls.rb`: `[ca.crt]`, a CA file to trust; without it the script uses the