Skip to content

Commit b7a7f9a

Browse files
committed
Added dedicated querying chapter
1 parent f2c64a1 commit b7a7f9a

File tree

3 files changed

+165
-39
lines changed

3 files changed

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

Comments
 (0)