@@ -96,6 +96,84 @@ adbc_disconnect(connection_id) -> BOOLEAN
9696SELECT adbc_disconnect(getvariable(' conn' )::BIGINT );
9797```
9898
99+ ### adbc_set_autocommit
100+
101+ Enables or disables autocommit mode on a connection. When autocommit is disabled, changes require an explicit ` adbc_commit() ` call.
102+
103+ ``` sql
104+ adbc_set_autocommit(connection_id, enabled) - > BOOLEAN
105+ ```
106+
107+ ** Parameters:**
108+ - ` connection_id ` : Connection handle from ` adbc_connect `
109+ - ` enabled ` : ` true ` to enable autocommit, ` false ` to disable
110+
111+ ** Returns:** ` true ` on success.
112+
113+ ** Example:**
114+
115+ ``` sql
116+ -- Disable autocommit to start a transaction
117+ SELECT adbc_set_autocommit(getvariable(' conn' )::BIGINT , false);
118+
119+ -- Make changes...
120+ SELECT adbc_execute(getvariable(' conn' )::BIGINT , ' INSERT INTO users VALUES (1, ' ' Alice' ' )' );
121+
122+ -- Commit or rollback
123+ SELECT adbc_commit(getvariable(' conn' )::BIGINT );
124+
125+ -- Re-enable autocommit
126+ SELECT adbc_set_autocommit(getvariable(' conn' )::BIGINT , true);
127+ ```
128+
129+ ### adbc_commit
130+
131+ Commits the current transaction. Only applicable when autocommit is disabled.
132+
133+ ``` sql
134+ adbc_commit(connection_id) - > BOOLEAN
135+ ```
136+
137+ ** Parameters:**
138+ - ` connection_id ` : Connection handle from ` adbc_connect `
139+
140+ ** Returns:** ` true ` on success.
141+
142+ ** Example:**
143+
144+ ``` sql
145+ SELECT adbc_commit(getvariable(' conn' )::BIGINT );
146+ ```
147+
148+ ### adbc_rollback
149+
150+ Rolls back the current transaction, discarding all uncommitted changes. Only applicable when autocommit is disabled.
151+
152+ ``` sql
153+ adbc_rollback(connection_id) - > BOOLEAN
154+ ```
155+
156+ ** Parameters:**
157+ - ` connection_id ` : Connection handle from ` adbc_connect `
158+
159+ ** Returns:** ` true ` on success.
160+
161+ ** Example:**
162+
163+ ``` sql
164+ -- Start a transaction
165+ SELECT adbc_set_autocommit(getvariable(' conn' )::BIGINT , false);
166+
167+ -- Make changes
168+ SELECT adbc_execute(getvariable(' conn' )::BIGINT , ' DELETE FROM users WHERE id = 1' );
169+
170+ -- Oops, rollback!
171+ SELECT adbc_rollback(getvariable(' conn' )::BIGINT );
172+
173+ -- Re-enable autocommit
174+ SELECT adbc_set_autocommit(getvariable(' conn' )::BIGINT , true);
175+ ```
176+
99177### adbc_scan
100178
101179Executes a SELECT query and returns the results as a table.
@@ -475,6 +553,14 @@ SELECT * FROM adbc_scan(
475553 params := row(' Engineering' , 90000 .0 )
476554);
477555
556+ -- Transaction control
557+ SELECT adbc_set_autocommit(getvariable(' sqlite_conn' )::BIGINT , false); -- Start transaction
558+ SELECT adbc_execute(getvariable(' sqlite_conn' )::BIGINT ,
559+ ' INSERT INTO employees VALUES (4, ' ' Diana' ' , ' ' Marketing' ' , 85000)' );
560+ SELECT adbc_commit(getvariable(' sqlite_conn' )::BIGINT ); -- Commit changes
561+ -- Or use: SELECT adbc_rollback(getvariable('sqlite_conn')::BIGINT); -- To discard changes
562+ SELECT adbc_set_autocommit(getvariable(' sqlite_conn' )::BIGINT , true); -- Back to autocommit
563+
478564-- Clean up
479565SELECT adbc_disconnect(getvariable(' sqlite_conn' )::BIGINT );
480566```
0 commit comments