You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
## 0.32.0 (unreleased)
4
4
5
-
- Rollback any open transactions when returning a connection to the pool.
5
+
- Rollback any open transactions when an error occurs in a SQL file.
6
6
- Previously, if an error occurred in the middle of a transaction, the transaction would be left open, and the connection would be returned to the pool. The next request could get a connection with an open half-completed transaction, which could lead to hard to debug issues.
7
7
- This allows safely using features that require a transaction, like
8
8
-```sql
@@ -21,6 +21,8 @@
21
21
```
22
22
- Fix `error returned from database: 1295 (HY000): This command is not supported in the prepared statement protocol yet` when trying to use transactions with MySQL. `START TRANSACTION` now works as expected in MySQL.
23
23
- Fix a bug where a multi-select dropdown would unexpectedly open when the form was reset.
24
+
- Add a new optional `sqlpage/on_reset.sql` file that can be used to execute some SQL code after the end of each page execution.
25
+
- Useful to reset a connection to the database after each request.
SQLPage allows you to run a SQL script after a request has been processed,
143
+
by simply creating a `sqlpage/on_reset.sql` file.
144
+
145
+
This can be useful to clean up temporary tables,
146
+
rollback transactions that were left open,
147
+
or other resources that were created during the request.
148
+
149
+
You can also use this script to close database connections that are
150
+
in an undesirable state, such as being in a transaction that was left open.
151
+
To close a connection, write a select statement that returns a single row
152
+
with a single boolean column named `is_healthy`, and set it to false.
153
+
154
+
#### Rollback transactions
155
+
156
+
You can automatically rollback any open transactions
157
+
when a connection is returned to the pool,
158
+
so that a new request is never executed in the context of an open transaction from a previous request.
159
+
160
+
For this to work, you need to create a `sqlpage/on_reset.sql` containing the following line:
161
+
162
+
```sql
163
+
ROLLBACK;
164
+
```
165
+
166
+
#### Cleaning up all connection state
167
+
168
+
Some databases allow you to clean up all the state associatPed with a connection.
169
+
170
+
##### PostgreSQL
171
+
172
+
By creating a `sqlpage/on_disconnect.sql` file containing a [`DISCARD ALL`](https://www.postgresql.org/docs/current/sql-discard.html) statement.
173
+
174
+
```sql
175
+
DISCARD ALL;
176
+
```
177
+
178
+
##### SQL Server
179
+
180
+
By creating a `sqlpage/on_disconnect.sql` file containing a call to the [`sp_reset_connection`](https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/system-stored-procedures-transact-sql?view=sql-server-ver16#api-system-stored-procedures) stored procedure.
181
+
182
+
```sql
183
+
EXEC sp_reset_connection;
184
+
```
185
+
138
186
## Migrations
139
187
140
188
SQLPage allows you to run SQL scripts when the database schema changes, by creating a `sqlpage/migrations` directory.
0 commit comments