Skip to content

Commit

Permalink
docs: update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Nov 27, 2022
1 parent a28fee0 commit 2ca5a70
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 38 deletions.
10 changes: 5 additions & 5 deletions user_guide_src/source/changelogs/v4.3.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Exceptions when Database Errors Occur

- The exceptions thrown by the database connection classes have been changed to ``CodeIgniter\Database\Exceptions\DatabaseException``. Previously, different database drivers threw different exception classes, but these have been unified into ``DatabaseException``.
- The exceptions thrown by the ``execute()`` method of Prepared Queries have been changed to ``DatabaseException``. Previously, different database drivers might throw different exception classes or did not throw exceptions, but these have been unified into ``DatabaseException``.
- During transactions, exceptions are not thrown by default even if ``DBDebug`` is true.
- ``DBDebug`` and ``CI_DEBUG`` Changes

- To be consistent in behavior regardless of environments, ``Config\Database::$default['DBDebug']``
Expand All @@ -38,11 +39,10 @@ Exceptions when Database Errors Occur
- The default value of ``BaseConnection::$DBDebug`` has been changed to ``true``.
- With these changes, ``DBDebug`` **now means whether or not to throw an exception when an error occurs**.
Although unrelated to debugging, the name has not been changed.
- When running transactions with ``DBDebug`` is ``true``, if a query error occurs, all the queries
will be rolled backed, and an exception will be thrown. :ref:`transactions-managing-errors` or
:ref:`transactions-manual-transactions` won't work. This is no different from previous versions,
but changing the ``DBDebug`` setting from the previous default value to ``true`` will change the
behavior in the production environment.
- When running transactions with ``DBDebug`` is ``true``, even if a query error occurs, exceptions
are not thrown by default. Previously, if a query error occurs, all the queries
will be rolled backed, and an exception will be thrown, so :ref:`transactions-managing-errors` or
:ref:`transactions-manual-transactions` won't work.
- Now when you delete without WHERE clause in ``Model``, ``DatabaseException`` is thrown even if
``CI_DEBUG`` is false. Previously, it is thrown if ``CI_DEBUG`` is true.

Expand Down
30 changes: 5 additions & 25 deletions user_guide_src/source/database/transactions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ contrast, we've implemented a smart transaction system that does all
this for you automatically (you can also manage your transactions
manually if you choose to, but there's really no benefit).

.. note:: Since v4.3.0, ``DBDebug`` is true by default in all environments.
When ``DBDebug`` is true, if a query error occurs, all the queries
will be rolled backed, and a ``DatabaseException`` will be thrown.
In previous versions, ``DBDebug`` was false only in production environment,
and different database drivers might throw different exception classes.
.. note::
Since v4.3.0, during transactions, exceptions are not thrown by default
even if ``DBDebug`` is true.

Running Transactions
====================
Expand All @@ -45,8 +43,6 @@ To run your queries using transactions you will use the
``$this->db->transStart()`` and ``$this->db->transComplete()`` functions as
follows:

.. literalinclude:: transactions/008.php

.. literalinclude:: transactions/001.php

You can run as many queries as you want between the start/complete
Expand All @@ -66,30 +62,15 @@ Strict Mode can be disabled as follows:

.. literalinclude:: transactions/002.php

.. note:: Since v4.3.0, ``DBDebug`` is true by default in all environments.
When ``DBDebug`` is true, if a query error occurs, all the queries
will be rolled backed, and a ``DatabaseException`` will be thrown.
In previous versions, ``DBDebug`` was false only in production environment,
and different database drivers might throw different exception classes.

.. _transactions-managing-errors:

Managing Errors
===============

If you have ``DBDebug`` true in your **app/Config/Database.php** file
you'll see a ``DatabaseException`` thrown if a query error occurs.

If ``DBDebug`` is false, you can manage your own errors like this:
You can manage your own errors like this:

.. literalinclude:: transactions/003.php

.. note:: Since v4.3.0, ``DBDebug`` is true by default in all environments.
When ``DBDebug`` is true, if a query error occurs, all the queries
will be rolled backed, and a ``DatabaseException`` will be thrown.
In previous versions, ``DBDebug`` was false only in production environment,
and different database drivers might throw different exception classes.

Disabling Transactions
======================

Expand All @@ -116,8 +97,7 @@ a valid result. To use test mode simply set the first parameter in the
Running Transactions Manually
=============================

If you have ``DBDebug`` false in your **app/Config/Database.php** file
and if you would like to run transactions manually you can do so as follows:
If you would like to run transactions manually you can do so as follows:

.. literalinclude:: transactions/006.php

Expand Down
2 changes: 0 additions & 2 deletions user_guide_src/source/database/transactions/001.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

// When DBDebug in the Database Config is false.

$this->db->transStart();
$this->db->query('AN SQL QUERY...');
$this->db->query('ANOTHER QUERY...');
Expand Down
2 changes: 0 additions & 2 deletions user_guide_src/source/database/transactions/003.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

// DBDebug in the Database Config must be false.

$this->db->transStart();
$this->db->query('AN SQL QUERY...');
$this->db->query('ANOTHER QUERY...');
Expand Down
2 changes: 0 additions & 2 deletions user_guide_src/source/database/transactions/006.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

// DBDebug in the Database Config must be false.

$this->db->transBegin();

$this->db->query('AN SQL QUERY...');
Expand Down
4 changes: 2 additions & 2 deletions user_guide_src/source/database/transactions/008.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

// When DBDebug in the Database Config is true.
// When DBDebug in the Database Config must be true.

use CodeIgniter\Database\Exceptions\DatabaseException;

try {
$this->db->transStart();
$this->db->transException(true)->transStart();
$this->db->query('AN SQL QUERY...');
$this->db->query('ANOTHER QUERY...');
$this->db->query('AND YET ANOTHER QUERY...');
Expand Down

0 comments on commit 2ca5a70

Please sign in to comment.