From fa08bb2b0a353f45cd164b3d3ba7ac3678679953 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 24 Jan 2024 13:07:42 +0900 Subject: [PATCH 1/4] docs: add "Notes on Data Types" --- user_guide_src/source/dbmgmt/forge.rst | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/user_guide_src/source/dbmgmt/forge.rst b/user_guide_src/source/dbmgmt/forge.rst index c14664b1ad7c..90bda20dfdba 100644 --- a/user_guide_src/source/dbmgmt/forge.rst +++ b/user_guide_src/source/dbmgmt/forge.rst @@ -120,6 +120,40 @@ After the fields have been defined, they can be added using ``$forge->addField($fields)`` followed by a call to the ``createTable()`` method. +Notes on Data Types +------------------- + +Floating-Point Types +^^^^^^^^^^^^^^^^^^^^ + +Floating-Point types such as ``FLOAT`` and ``DOUBLE`` represent approximate values. +Therefore, they should not be used when exact values are needed. + +:: + + mysql> CREATE TABLE t (f FLOAT, d DOUBLE); + mysql> INSERT INTO t VALUES(99.9, 99.9); + + mysql> SELECT * FROM t WHERE f=99.9; + Empty set (0.00 sec) + + mysql> SELECT * FROM t WHERE f > 99.89 AND f < 99.91; + +------+------+ + | f | d | + +------+------+ + | 99.9 | 99.9 | + +------+------+ + 1 row in set (0.01 sec) + +When it is important to preserve exact precision, for example with monetary data, +``DECIMAL`` or ``NUMERIC`` should be used. + +TEXT +^^^^ + +``TEXT`` should not be used on SQLSRV. It is deprecated. +See `ntext, text, and image (Transact-SQL) - SQL Server | Microsoft Learn `_. + $forge->addField() ------------------ From a5062173ef2a39dc02dad67dc3ede165149ac473 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 24 Jan 2024 13:09:14 +0900 Subject: [PATCH 2/4] docs: improve readability --- user_guide_src/source/dbmgmt/forge.rst | 29 +++++++++++----------- user_guide_src/source/dbmgmt/forge/007.php | 1 + 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/user_guide_src/source/dbmgmt/forge.rst b/user_guide_src/source/dbmgmt/forge.rst index 90bda20dfdba..5be595d48371 100644 --- a/user_guide_src/source/dbmgmt/forge.rst +++ b/user_guide_src/source/dbmgmt/forge.rst @@ -96,29 +96,33 @@ mechanism for this. Adding Fields ============= +$forge->addField() +------------------ + Fields are normally created via an associative array. Within the array, you must -include a ``type`` key that relates to the datatype of the field. For -example, INT, VARCHAR, TEXT, etc. Many datatypes (for example VARCHAR) -also require a ``constraint`` key. +include a ``type`` key that relates to the datatype of the field. + +For example, ``INT``, ``VARCHAR``, ``TEXT``, etc. +Many datatypes (for example ``VARCHAR``) also require a ``constraint`` key. .. literalinclude:: forge/006.php Additionally, the following key/values can be used: -- ``unsigned``/true : to generate "UNSIGNED" in the field definition. -- ``default``/value : to generate a default value in the field definition. -- ``null``/true : to generate "null" in the field definition. Without this, - the field will default to "NOT null". +- ``unsigned``/true : to generate ``UNSIGNED`` in the field definition. +- ``default``/value : to generate ``DEFAULT`` constraint in the field definition. +- ``null``/true : to generate ``NULL`` in the field definition. Without this, + the field will default to ``NOT NULL``. - ``auto_increment``/true : generates an auto_increment flag on the field. Note that the field type must be a type that supports this, - such as integer. + such as ``INTEGER``. - ``unique``/true : to generate a unique key for the field definition. .. literalinclude:: forge/007.php After the fields have been defined, they can be added using ``$forge->addField($fields)`` followed by a call to the -``createTable()`` method. +:ref:`createTable() ` method. Notes on Data Types ------------------- @@ -154,11 +158,6 @@ TEXT ``TEXT`` should not be used on SQLSRV. It is deprecated. See `ntext, text, and image (Transact-SQL) - SQL Server | Microsoft Learn `_. -$forge->addField() ------------------- - -The ``addField()`` method will accept the above array. - .. _forge-addfield-default-value-rawsql: Raw Sql Strings as Default Values @@ -243,6 +242,8 @@ You can specify the desired action for the "on update" and "on delete" propertie .. note:: SQLite3 does not support the naming of foreign keys. CodeIgniter will refer to them by ``prefix_table_column_foreign``. +.. _creating-a-table: + Creating a Table ================ diff --git a/user_guide_src/source/dbmgmt/forge/007.php b/user_guide_src/source/dbmgmt/forge/007.php index 182ea8347633..1cfa77487d2b 100644 --- a/user_guide_src/source/dbmgmt/forge/007.php +++ b/user_guide_src/source/dbmgmt/forge/007.php @@ -27,3 +27,4 @@ 'default' => 'pending', ], ]; +$forge->addField($fields); From 415012c37a50df8e2f73158c12b39e044ee0b123 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 24 Jan 2024 13:09:32 +0900 Subject: [PATCH 3/4] docs: align comments --- user_guide_src/source/dbmgmt/forge/025.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/dbmgmt/forge/025.php b/user_guide_src/source/dbmgmt/forge/025.php index 7e1aa8ebd320..848625a9b0d6 100644 --- a/user_guide_src/source/dbmgmt/forge/025.php +++ b/user_guide_src/source/dbmgmt/forge/025.php @@ -1,4 +1,4 @@ dropColumn('table_name', 'column_1,column_2'); // by proving comma separated column names +$forge->dropColumn('table_name', 'column_1,column_2'); // by proving comma separated column names $forge->dropColumn('table_name', ['column_1', 'column_2']); // by proving array of column names From 9bda43adcb4852ae973e1c52f0468de1c23fd420 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 24 Jan 2024 13:09:46 +0900 Subject: [PATCH 4/4] docs: replace MySqli with MySQLi --- user_guide_src/source/dbmgmt/forge/028.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/dbmgmt/forge/028.php b/user_guide_src/source/dbmgmt/forge/028.php index 776c587b896c..b0a92357d088 100644 --- a/user_guide_src/source/dbmgmt/forge/028.php +++ b/user_guide_src/source/dbmgmt/forge/028.php @@ -1,5 +1,5 @@ dropPrimaryKey('tablename');