Skip to content

Commit 7b1df54

Browse files
committed
fix: add docs for transactions
1 parent eca055e commit 7b1df54

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

docs/README.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,84 @@ adbc_disconnect(connection_id) -> BOOLEAN
134134
SELECT adbc_disconnect(getvariable('conn')::BIGINT);
135135
```
136136

137+
### adbc_set_autocommit
138+
139+
Enables or disables autocommit mode on a connection. When autocommit is disabled, changes require an explicit `adbc_commit()` call.
140+
141+
```sql
142+
adbc_set_autocommit(connection_id, enabled) -> BOOLEAN
143+
```
144+
145+
**Parameters:**
146+
- `connection_id`: Connection handle from `adbc_connect`
147+
- `enabled`: `true` to enable autocommit, `false` to disable
148+
149+
**Returns:** `true` on success.
150+
151+
**Example:**
152+
153+
```sql
154+
-- Disable autocommit to start a transaction
155+
SELECT adbc_set_autocommit(getvariable('conn')::BIGINT, false);
156+
157+
-- Make changes...
158+
SELECT adbc_execute(getvariable('conn')::BIGINT, 'INSERT INTO users VALUES (1, ''Alice'')');
159+
160+
-- Commit or rollback
161+
SELECT adbc_commit(getvariable('conn')::BIGINT);
162+
163+
-- Re-enable autocommit
164+
SELECT adbc_set_autocommit(getvariable('conn')::BIGINT, true);
165+
```
166+
167+
### adbc_commit
168+
169+
Commits the current transaction. Only applicable when autocommit is disabled.
170+
171+
```sql
172+
adbc_commit(connection_id) -> BOOLEAN
173+
```
174+
175+
**Parameters:**
176+
- `connection_id`: Connection handle from `adbc_connect`
177+
178+
**Returns:** `true` on success.
179+
180+
**Example:**
181+
182+
```sql
183+
SELECT adbc_commit(getvariable('conn')::BIGINT);
184+
```
185+
186+
### adbc_rollback
187+
188+
Rolls back the current transaction, discarding all uncommitted changes. Only applicable when autocommit is disabled.
189+
190+
```sql
191+
adbc_rollback(connection_id) -> BOOLEAN
192+
```
193+
194+
**Parameters:**
195+
- `connection_id`: Connection handle from `adbc_connect`
196+
197+
**Returns:** `true` on success.
198+
199+
**Example:**
200+
201+
```sql
202+
-- Start a transaction
203+
SELECT adbc_set_autocommit(getvariable('conn')::BIGINT, false);
204+
205+
-- Make changes
206+
SELECT adbc_execute(getvariable('conn')::BIGINT, 'DELETE FROM users WHERE id = 1');
207+
208+
-- Oops, rollback!
209+
SELECT adbc_rollback(getvariable('conn')::BIGINT);
210+
211+
-- Re-enable autocommit
212+
SELECT adbc_set_autocommit(getvariable('conn')::BIGINT, true);
213+
```
214+
137215
### adbc_scan
138216

139217
Executes a SELECT query and returns the results as a table.
@@ -560,6 +638,14 @@ SELECT * FROM adbc_scan(
560638
params := row('Engineering', 90000.0)
561639
);
562640

641+
-- Transaction control
642+
SELECT adbc_set_autocommit(getvariable('sqlite_conn')::BIGINT, false); -- Start transaction
643+
SELECT adbc_execute(getvariable('sqlite_conn')::BIGINT,
644+
'INSERT INTO employees VALUES (4, ''Diana'', ''Marketing'', 85000)');
645+
SELECT adbc_commit(getvariable('sqlite_conn')::BIGINT); -- Commit changes
646+
-- Or use: SELECT adbc_rollback(getvariable('sqlite_conn')::BIGINT); -- To discard changes
647+
SELECT adbc_set_autocommit(getvariable('sqlite_conn')::BIGINT, true); -- Back to autocommit
648+
563649
-- Clean up
564650
SELECT adbc_disconnect(getvariable('sqlite_conn')::BIGINT);
565651
```

0 commit comments

Comments
 (0)