|
| 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 | +Functions |
| 63 | +~~~~~~~~~ |
| 64 | + |
| 65 | +The ``UPDATE`` grammer also allows the use of functions (note that only UPDATE |
| 66 | +supports functions). |
| 67 | + |
| 68 | +.. _phpcr_shell_query_function_arrayremove: |
| 69 | + |
| 70 | +array_remove |
| 71 | +"""""""""""" |
| 72 | + |
| 73 | +Remove the multivalue property value matching the given value. |
| 74 | + |
| 75 | +Usage: |
| 76 | + |
| 77 | +.. code-block:: bash |
| 78 | +
|
| 79 | + PHPCRSH> UPDATE [nt:unstructured] AS a SET a.tags = array_remove(a.tags, 'Planes') WHERE a.tags = 'Planes' |
| 80 | +
|
| 81 | +Arguments: |
| 82 | + |
| 83 | +- **propertyName**: Property name (including selector) of the multivalue |
| 84 | + property |
| 85 | +- **value**: Value to match and remove |
| 86 | + |
| 87 | +.. _phpcr_shell_query_function_array: |
| 88 | + |
| 89 | +array |
| 90 | +""""" |
| 91 | + |
| 92 | +Provides an array value, analagous to the ``array`` keyword in PHP: |
| 93 | + |
| 94 | +.. code-block:: bash |
| 95 | +
|
| 96 | + PHPCRSH> UPDATE [nt:unstructured] SET tags = array('One', 'Two', 'Three') |
| 97 | +
|
| 98 | +Arguments: |
| 99 | + |
| 100 | +- List of values |
| 101 | + |
| 102 | +.. _phpcr_shell_query_function_arrayreplace: |
| 103 | + |
| 104 | +array_replace |
| 105 | +""""""""""""" |
| 106 | + |
| 107 | +Replace a given multivalue property value, or remove it by setting it to |
| 108 | +``NULL``. |
| 109 | + |
| 110 | +Replace a value: |
| 111 | + |
| 112 | +.. code-block:: bash |
| 113 | +
|
| 114 | + PHPCRSH> UPDATE [nt:unstructured] SET tags = array_replace(tags, 'Planes', 'Rockets') |
| 115 | +
|
| 116 | +Remove matching values: |
| 117 | + |
| 118 | +.. code-block:: bash |
| 119 | +
|
| 120 | + PHPCRSH> UPDATE [nt:unstructured] SET tags = array_replace(tags, 'Planes', NULL) |
| 121 | +
|
| 122 | +Arguments: |
| 123 | + |
| 124 | +- **propertyName**: Property name (including selector) of the multivalue |
| 125 | + property |
| 126 | +- **value**: Value to replace, use ``NULL`` to remove a value |
| 127 | +- **replacement**: Replacement value |
| 128 | + |
| 129 | +.. _phpcr_shell_query_function_arrayreplaceat: |
| 130 | + |
| 131 | +array_replace_at |
| 132 | +"""""""""""""""" |
| 133 | + |
| 134 | +Replace a given multivalue property value at the specified index. |
| 135 | + |
| 136 | +Usage: |
| 137 | + |
| 138 | +.. code-block:: bash |
| 139 | +
|
| 140 | + PHPCRSH> UPDATE [nt:unstructured] SET tags = array_replace_at(tags, 0, 'Rockets') WHERE tags = 'Planes' |
| 141 | +
|
| 142 | +Arguments: |
| 143 | + |
| 144 | +- **propertyName**: Property name (including selector) of the multivalue |
| 145 | + property |
| 146 | +- **index**: Index at which the new value should be set |
| 147 | +- **value**: Value to set |
| 148 | + |
| 149 | +.. _phpcr_shell_query_function_arrayappend: |
| 150 | + |
| 151 | +array_append |
| 152 | +"""""""""""" |
| 153 | + |
| 154 | +Append a value to a multivalue property. |
| 155 | + |
| 156 | +Usage: |
| 157 | + |
| 158 | +.. code-block:: bash |
| 159 | +
|
| 160 | + PHPCRSH> UPDATE [nt:unstructured] SET tags - array_append(tags, 'Planes') WHERE tags = 'Planes' |
| 161 | +
|
| 162 | +Arguments: |
| 163 | + |
| 164 | +- **propertyName**: Property name (including selector) of the multivalue |
| 165 | + property |
| 166 | +- **value**: Value to append |
| 167 | + |
| 168 | +Deleting |
| 169 | +-------- |
| 170 | + |
| 171 | +Delete is as you might expect, and is essentially gramatically identical to ``SELECT`` but |
| 172 | +without the column selection: |
| 173 | + |
| 174 | +.. code-block:: bash |
| 175 | +
|
| 176 | + PHPCRSH > DELETE FROM [slinpTest:article] WHERE title="Home" |
| 177 | + 1 row(s) affected in 0.01s |
0 commit comments