Skip to content

Commit 13590d6

Browse files
authored
Merge pull request #8452 from kenjis/docs-query_builder
docs: improve query_builder
2 parents 94b3701 + ebb950a commit 13590d6

File tree

1 file changed

+43
-22
lines changed

1 file changed

+43
-22
lines changed

user_guide_src/source/database/query_builder.rst

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,9 @@ insertBatch
878878
$builder->insertBatch()
879879
-----------------------
880880

881+
Insert from Data
882+
^^^^^^^^^^^^^^^^
883+
881884
Generates an insert string based on the data you supply, and runs the
882885
query. You can either pass an **array** or an **object** to the
883886
method. Here is an example using an array:
@@ -890,6 +893,9 @@ The first parameter is an associative array of values.
890893

891894
.. warning:: When you use ``RawSql``, you MUST escape the data manually. Failure to do so could result in SQL injections.
892895

896+
Insert from a Query
897+
^^^^^^^^^^^^^^^^^^^
898+
893899
You can also insert from a query:
894900

895901
.. literalinclude:: query_builder/117.php
@@ -954,18 +960,26 @@ $builder->upsertBatch()
954960

955961
.. versionadded:: 4.3.0
956962

963+
Upsert from Data
964+
^^^^^^^^^^^^^^^^
965+
957966
Generates an upsert string based on the data you supply, and runs the
958967
query. You can either pass an **array** or an **object** to the
959968
method. By default a constraint will be defined in order. A primary
960969
key will be selected first and then unique keys. MySQL will use any
961-
constraint by default. Here is an example using an array:
970+
constraint by default.
971+
972+
Here is an example using an array:
962973

963974
.. literalinclude:: query_builder/108.php
964975

965976
The first parameter is an associative array of values.
966977

967978
.. note:: All values are escaped automatically producing safer queries.
968979

980+
Upsert from a Query
981+
^^^^^^^^^^^^^^^^^^^
982+
969983
You can also upsert from a query:
970984

971985
.. literalinclude:: query_builder/115.php
@@ -1096,6 +1110,16 @@ Or as an array:
10961110
You may also use the ``$builder->set()`` method described above when
10971111
performing updates.
10981112

1113+
$builder->getCompiledUpdate()
1114+
-----------------------------
1115+
1116+
This works exactly the same way as ``$builder->getCompiledInsert()`` except
1117+
that it produces an **UPDATE** SQL string instead of an **INSERT** SQL string.
1118+
1119+
For more information view documentation for `$builder->getCompiledInsert()`_.
1120+
1121+
.. note:: This method doesn't work for batched updates.
1122+
10991123
.. _update-batch:
11001124

11011125
UpdateBatch
@@ -1141,16 +1165,6 @@ Since v4.3.0, you can also update from a query with the ``setQueryAsData()`` met
11411165

11421166
.. note:: It is required to alias the columns of the select query to match those of the target table.
11431167

1144-
$builder->getCompiledUpdate()
1145-
-----------------------------
1146-
1147-
This works exactly the same way as ``$builder->getCompiledInsert()`` except
1148-
that it produces an **UPDATE** SQL string instead of an **INSERT** SQL string.
1149-
1150-
For more information view documentation for ``$builder->getCompiledInsert()``.
1151-
1152-
.. note:: This method doesn't work for batched updates.
1153-
11541168
*************
11551169
Deleting Data
11561170
*************
@@ -1174,27 +1188,42 @@ the data to the first parameter of the method:
11741188
If you want to delete all data from a table, you can use the ``truncate()``
11751189
method, or ``emptyTable()``.
11761190

1191+
$builder->getCompiledDelete()
1192+
-----------------------------
1193+
1194+
This works exactly the same way as ``$builder->getCompiledInsert()`` except
1195+
that it produces a **DELETE** SQL string instead of an **INSERT** SQL string.
1196+
1197+
For more information view documentation for `$builder->getCompiledInsert()`_.
1198+
11771199
.. _delete-batch:
11781200

1201+
DeleteBatch
1202+
===========
1203+
11791204
$builder->deleteBatch()
11801205
-----------------------
11811206

11821207
.. versionadded:: 4.3.0
11831208

1209+
Delete from Data
1210+
^^^^^^^^^^^^^^^^
1211+
11841212
Generates a batch **DELETE** statement based on a set of data.
11851213

11861214
.. literalinclude:: query_builder/118.php
11871215

11881216
This method may be especially useful when deleting data in a table with a composite primary key.
11891217

1190-
.. note:: SQLite does not support the use of ``where()``.
1218+
.. note:: SQLite3 does not support the use of ``where()``.
1219+
1220+
Delete from a Query
1221+
^^^^^^^^^^^^^^^^^^^
11911222

11921223
You can also delete from a query:
11931224

11941225
.. literalinclude:: query_builder/119.php
11951226

1196-
.. note:: ``$deleteBatch()`` can be used since v4.3.0.
1197-
11981227
$builder->emptyTable()
11991228
----------------------
12001229

@@ -1213,14 +1242,6 @@ Generates a **TRUNCATE** SQL string and runs the query.
12131242
.. note:: If the TRUNCATE command isn't available, ``truncate()`` will
12141243
execute as "DELETE FROM table".
12151244

1216-
$builder->getCompiledDelete()
1217-
-----------------------------
1218-
1219-
This works exactly the same way as ``$builder->getCompiledInsert()`` except
1220-
that it produces a **DELETE** SQL string instead of an **INSERT** SQL string.
1221-
1222-
For more information view documentation for ``$builder->getCompiledInsert()``.
1223-
12241245
**********************
12251246
Conditional Statements
12261247
**********************

0 commit comments

Comments
 (0)