Skip to content

Commit 0308366

Browse files
committed
docs: add about BaseConnection::transException()
1 parent ff2d8b7 commit 0308366

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

user_guide_src/source/changelogs/v4.3.0.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ Others
235235
- Improved data returned by :ref:`BaseConnection::getForeignKeyData() <metadata-getforeignkeydata>`. All DBMS returns the same structure.
236236
- SQLite :ref:`BaseConnection::getIndexData() <db-metadata-getindexdata>` now can return pseudo index named ``PRIMARY`` for `AUTOINCREMENT` column, and each returned index data has ``type`` property.
237237
- ``BasePreparedQuery::close()`` now deallocates the prepared statement in all DBMS. Previously, they were not deallocated in Postgre, SQLSRV and OCI8. See :ref:`database-queries-stmt-close`.
238+
- Added ``BaseConnection::transException()`` to throw exceptinons during transactions.
239+
See :ref:`transactions-throwing-exceptions`
238240

239241
Model
240242
=====

user_guide_src/source/database/transactions.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,25 @@ If the ``DBDebug`` is false, you can manage your own errors like this:
7575

7676
.. literalinclude:: transactions/003.php
7777

78+
.. _transactions-throwing-exceptions:
79+
80+
Throwing Exceptions
81+
===================
82+
83+
.. versionadded:: 4.3.0
84+
85+
.. note::
86+
Since v4.3.0, during transactions, exceptions are not thrown by default
87+
even if ``DBDebug`` is true.
88+
89+
If you want an exception to be thrown when a query error occurs, you can use
90+
``$this->db->transException(true)``:
91+
92+
.. literalinclude:: transactions/008.php
93+
94+
If a query error occurs, all the queries will be rolled backed, and a
95+
``DatabaseException`` will be thrown.
96+
7897
Disabling Transactions
7998
======================
8099

user_guide_src/source/installation/upgrade_430.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ Database Exception Changes
5151
- The exception classes may be changed when database errors occur. If you catch the exceptions,
5252
you must confirm that your code can catch the exceptions.
5353
- Now a few exceptions will be thrown even if ``CI_DEBUG`` is false.
54+
- During transactions, exceptions are not thrown by default even if ``DBDebug`` is true. If you want
55+
exceptions to be thrown, you need to call ``transException(true)``.
56+
See :ref:`transactions-throwing-exceptions`.
5457
- See :ref:`exceptions-when-database-errors-occur` for details.
5558

5659
HTTP Status Code and Exit Code of Uncaught Exceptions

0 commit comments

Comments
 (0)