Skip to content

Commit 0e0583a

Browse files
committed
Merge pull request #17 from phpcr/querying
Added dedicated querying chapter
2 parents f2c64a1 + 3008cce commit 0e0583a

File tree

3 files changed

+178
-39
lines changed

3 files changed

+178
-39
lines changed

phpcr-shell/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ PHPCR-Shell
77
installation
88
connecting
99
interacting
10+
querying
1011
configuration
1112
reference

phpcr-shell/interacting.rst

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -143,42 +143,3 @@ of :ref:`phpcr_shell_command_nodecopy` which is a workspace command).
143143
To persist changes to the repository you must call :ref:`phpcr_shell_command_sessionsave` (or ``save``).
144144

145145
You can also refresh (or reset) the session by calling :ref:`phpcr_shell_command_sessionrefresh` (or ``refresh``).
146-
147-
Queries
148-
-------
149-
150-
PHPCRSH supports the JCR-SQL2 query language:
151-
152-
.. code-block:: bash
153-
154-
PHPCRSH > SELECT title FROM slinpTest:article
155-
+--------------------------------------------+-----------------------------+
156-
| Path | slinpTest:article.title |
157-
+--------------------------------------------+-----------------------------+
158-
| /slinp/web/root | Slinp Web Content Framework |
159-
| /slinp/web/root/home | Home |
160-
| /slinp/web/root/articles/Faster-than-light | Faster than light |
161-
+--------------------------------------------+-----------------------------+
162-
3 rows in set (0.01 sec)
163-
PHPCRSH > SELECT title FROM slinpTest:article WHERE title="Home"
164-
+----------------------+-------------------------+
165-
| Path | slinpTest:article.title |
166-
+----------------------+-------------------------+
167-
| /slinp/web/root/home | Home |
168-
+----------------------+-------------------------+
169-
1 rows in set (0.04 sec)
170-
171-
For more information on JCR-SQL2 refer to the articles on the
172-
`official PHPCR website <http://phpcr.github.io/documentation/>`_.
173-
174-
In addition to SELECT PHPCR Shell supports non-standard UPDATE and DELETE queries:
175-
176-
.. code-block:: bash
177-
178-
PHPCRSH > DELETE FROM [slinpTest:article] WHERE title="Home"
179-
1 row(s) affected in 0.01s
180-
181-
.. code-block:: bash
182-
183-
PHPCRSH > UPDATE [slinpTest:article] SET title="Away" WHERE title="Home"
184-
1 row(s) affected in 0.01s

phpcr-shell/querying.rst

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
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

Comments
 (0)