|
| 1 | +Querying |
| 2 | +======== |
| 3 | + |
| 4 | +Selecting |
| 5 | +--------- |
| 6 | + |
| 7 | +PHPCRSH currently supports the JCR-SQL2 query language when supported by the |
| 8 | +implementation (currently all implementations support this language). |
| 9 | + |
| 10 | +.. code-block:: bash |
| 11 | +
|
| 12 | + PHPCRSH > SELECT title FROM slinpTest:article |
| 13 | + +--------------------------------------------+-----------------------------+ |
| 14 | + | Path | slinpTest:article.title | |
| 15 | + +--------------------------------------------+-----------------------------+ |
| 16 | + | /slinp/web/root | Slinp Web Content Framework | |
| 17 | + | /slinp/web/root/home | Home | |
| 18 | + | /slinp/web/root/articles/Faster-than-light | Faster than light | |
| 19 | + +--------------------------------------------+-----------------------------+ |
| 20 | + 3 rows in set (0.01 sec) |
| 21 | +
|
| 22 | + PHPCRSH > SELECT title FROM slinpTest:article WHERE title="Home" |
| 23 | + +----------------------+-------------------------+ |
| 24 | + | Path | slinpTest:article.title | |
| 25 | + +----------------------+-------------------------+ |
| 26 | + | /slinp/web/root/home | Home | |
| 27 | + +----------------------+-------------------------+ |
| 28 | + 1 rows in set (0.04 sec) |
| 29 | +
|
| 30 | +The JCR-SQL2 lanugage supports joins, column selection and a range of |
| 31 | +operands (e.g. lowercase, uppercase, length, etc). |
| 32 | + |
| 33 | +For more information on JCR-SQL2 refer to the articles on the |
| 34 | +`official PHPCR website <http://phpcr.github.io/documentation/>`_. |
| 35 | + |
| 36 | +Update and Delete |
| 37 | +----------------- |
| 38 | + |
| 39 | +In addition to standard support for SELECT queries, PHPCRSH additionally |
| 40 | +supports UPDATE and DELETE queries, these query grammers **are not standard** |
| 41 | +and are specific to PHPCRSH. |
| 42 | + |
| 43 | +.. note:: |
| 44 | + |
| 45 | + UPDATE and DELETE operations are *experimental*. You are advised to test |
| 46 | + any updates before hand in a development environment and ensure that you |
| 47 | + have a backup. We can take no responsibility for lost data! |
| 48 | + |
| 49 | +Updating |
| 50 | +-------- |
| 51 | + |
| 52 | +The UPDATE Grammer extends the SELECT grammer: |
| 53 | + |
| 54 | +.. code-block:: bash |
| 55 | +
|
| 56 | + PHPCRSH > UPDATE [slinpTest:article] SET title="Away" WHERE title="Home" |
| 57 | + 1 row(s) affected in 0.01s |
| 58 | +
|
| 59 | + PHPCRSH > UPDATE [slinpTest:article] AS a LEFT JOIN [slinpTest:foobar] AS b ON a.uuid = b.content SET a.title="Away", b.title="Home" WHERE a.title="Home" |
| 60 | + 1 row(s) affected in 0.01s |
| 61 | +
|
| 62 | +Multivalue indexes |
| 63 | +~~~~~~~~~~~~~~~~~~ |
| 64 | + |
| 65 | +You can update (or remove) specific multivalue indexes: |
| 66 | + |
| 67 | +.. code-block:: bash |
| 68 | +
|
| 69 | + PHPCRSH > UPDATE [slinpTest:article] SET title[1] = "Away" WHERE title="Home" |
| 70 | + 1 row(s) affected in 0.01s |
| 71 | +
|
| 72 | +The above query will set the multivalue value at index 1 to "Away" when the |
| 73 | +value "Home" matches *one of* the multivalue property values. |
| 74 | + |
| 75 | +.. code-block:: bash |
| 76 | +
|
| 77 | + PHPCRSH > UPDATE [slinpTest:article] SET title[1] = NULL WHERE title="Home" |
| 78 | + 1 row(s) affected in 0.01s |
| 79 | +
|
| 80 | +Same as above but the value at index 1 will be removed. |
| 81 | + |
| 82 | +.. code-block:: bash |
| 83 | +
|
| 84 | + PHPCRSH > UPDATE [slinpTest:article] SET title[] = "Barfoo" WHERE title="Home" |
| 85 | + 1 row(s) affected in 0.01s |
| 86 | +
|
| 87 | +The above will *add* the value "barfoo" to the multivalue properties (see also :ref:`phpcr_shell_query_function_arrayappend`) |
| 88 | + |
| 89 | +See also: :ref:`phpcr_shell_query_function_arrayremove`, :ref:`phpcr_shell_query_function_arrayreplace`, :ref:`phpcr_shell_query_function_arrayappend`, |
| 90 | + |
| 91 | +Functions |
| 92 | +~~~~~~~~~ |
| 93 | + |
| 94 | +The ``UPDATE`` grammer also allows the use of functions (note that only UPDATE |
| 95 | +supports functions). |
| 96 | + |
| 97 | +.. _phpcr_shell_query_function_arrayremove: |
| 98 | + |
| 99 | +array_remove |
| 100 | +"""""""""""" |
| 101 | + |
| 102 | +Remove the multivalue property value matching the given value. |
| 103 | + |
| 104 | +Usage: |
| 105 | + |
| 106 | +.. code-block:: bash |
| 107 | +
|
| 108 | + PHPCRSH> UPDATE [nt:unstructured] AS a SET a.tags = array_remove(a.tags, 'Planes') WHERE a.tags = 'Planes' |
| 109 | +
|
| 110 | +Arguments: |
| 111 | + |
| 112 | +- **propertyName**: Property name (including selector) of the multivalue |
| 113 | + property |
| 114 | +- **value**: Value to match and remove |
| 115 | + |
| 116 | +.. _phpcr_shell_query_function_arrayreplace: |
| 117 | + |
| 118 | +array_replace |
| 119 | +""""""""""""" |
| 120 | + |
| 121 | +Replace the multivalue property value. |
| 122 | + |
| 123 | +Usage: |
| 124 | + |
| 125 | +.. code-block:: bash |
| 126 | +
|
| 127 | + PHPCRSH> UPDATE [nt:unstructured] SET tags = array_replace(tags, 'Planes', 'Rockets') WHERE tags = 'Planes' |
| 128 | +
|
| 129 | +Arguments: |
| 130 | + |
| 131 | +- **propertyName**: Property name (including selector) of the multivalue |
| 132 | + property |
| 133 | +- **value**: Value to replace |
| 134 | +- **replacement**: Replacement value |
| 135 | + |
| 136 | +.. _phpcr_shell_query_function_arrayappend: |
| 137 | + |
| 138 | +array_append |
| 139 | +"""""""""""" |
| 140 | + |
| 141 | +Append a value to a multivalue property. |
| 142 | + |
| 143 | +Usage: |
| 144 | + |
| 145 | +.. code-block:: bash |
| 146 | +
|
| 147 | + PHPCRSH> UPDATE [nt:unstructured] SET tags - array_append(tags, 'Planes') WHERE tags = 'Planes' |
| 148 | +
|
| 149 | +Arguments: |
| 150 | + |
| 151 | +- **propertyName**: Property name (including selector) of the multivalue |
| 152 | + property |
| 153 | +- **value**: Value to append |
| 154 | + |
| 155 | +Deleting |
| 156 | +-------- |
| 157 | + |
| 158 | +Delete is as you might expect, and is essentially gramatically identical to ``SELECT`` but |
| 159 | +without the column selection: |
| 160 | + |
| 161 | +.. code-block:: bash |
| 162 | +
|
| 163 | + PHPCRSH > DELETE FROM [slinpTest:article] WHERE title="Home" |
| 164 | + 1 row(s) affected in 0.01s |
0 commit comments