Migrating DLUX, Clustering, Version and XSQL to reST
[docs.git] / docs / getting-started-guide / common-features / xsql.rst
1 Running XSQL Console Commands and Queries
2 =========================================
3
4 XSQL Overview
5 -------------
6
7 XSQL is an XML-based query language that describes simple stored procedures
8 which parse XML data, query or update database tables, and compose XML output.
9 XSQL allows you to query tree models like a sequential database. For example,
10 you could run a query that lists all of the ports configured on a particular
11 module and their attributes.
12
13 The following sections cover the XSQL installation process, supported XSQL
14 commands, and the way to structure queries.
15
16 Installing XSQL
17 ---------------
18
19 To run commands from the XSQL console, you must first install XSQL on your
20 system:
21
22 #. Navigate to the directory in which you unzipped OpenDaylight
23 #. Start Karaf::
24
25       ./bin/karaf
26
27 #. Install XSQL::
28
29       feature:install odl-mdsal-xsql
30
31 XSQL Console Commands
32 ---------------------
33
34 To enter a command in the XSQL console, structure the command as follows::
35
36    odl:xsql _<XSQL command>_
37
38 The following table describes the commands supported in this OpenDaylight
39 release.
40
41 Supported XSQL Console Commands
42
43 +-----------------+-------------------------------------------------------------------------------+
44 | *Command*       | *Description*                                                                 |
45 +=================+===============================================================================+
46 | r               | Repeats the last command you executed.                                        |
47 +-----------------+-------------------------------------------------------------------------------+
48 | list vtables    | Lists the schema node containers that are currently installed. Whenever an    |
49 |                 | OpenDaylight module is installed, its YANG model is placed in the schema      |
50 |                 | context. At that point, the  XSQL receives a notification, confirms that the  |
51 |                 | module's YANG model resides in the schema context and then maps the model to  |
52 |                 | XSQL by setting up the necessary vtables and vfields. This command is useful  |
53 |                 | when you need to determine vtable information for a query.                    |
54 +-----------------+-------------------------------------------------------------------------------+
55 | list vfields    | Lists the vfields present in a specific vtable. This command is useful when   |
56 | *<vtable name>* | you need to determine vfields information for a query.                        |
57 +-----------------+-------------------------------------------------------------------------------+
58 | jdbc            | When the ODL server is behind a firewall, and the JDBC client cannot connect  |
59 | *<ip address>*  | to the JDBC server, run this command to start the client as a server and      |
60 |                 | establish a connection.                                                       |
61 +-----------------+-------------------------------------------------------------------------------+
62 | exit            | Closes the console.                                                           |
63 +-----------------+-------------------------------------------------------------------------------+
64 | tocsv           | Enables or disables the forwarding of query output as a .csv file.            |
65 +-----------------+-------------------------------------------------------------------------------+
66 | filename        | Specifies the .tocsv file to which the query data is exported. If you do not  |
67 | *<filename>*    | specify a value for this option when the toccsv option is enabled, the        |
68 |                 | filename for the query data file is generated automatically.                  |
69 +-----------------+-------------------------------------------------------------------------------+
70
71 XSQL Queries
72 ------------
73
74 You can run a query to extract information that meets the criteria you specify
75 using the information provided by the *list vtables* and *list vfields* 
76 _<vtable name>_ commands.  Any query you run should be structured as follows:
77
78 *select* _<vfields you want to search for, separated by a comma and a space>_
79 *from* _<vtables you want to search in, separated by a comma and a space>_
80 *where* _<criteria>_ *'*_<criteria operator>_*';*
81
82 For example, if you want to search the nodes/node ID field in the
83 nodes/node-connector table and find every instance of the Hardware-Address
84 object that contains _BA_ in its text string, enter the following query::
85
86    select nodes/node.ID from nodes/node-connector where Hardware-Address like '%BA%';
87
88 The following criteria operators are supported:
89
90 Supported XSQL Query Criteria Operators
91
92 +--------------------+----------------------------------------------------------------------+
93 | Criteria Operators | Description                                                          |
94 +====================+======================================================================+
95 | *=*                | Lists results that equal the value you specify.                      |
96 +--------------------+----------------------------------------------------------------------+
97 | *!=*               | Lists results that do not equal the value you specify.               |
98 +--------------------+----------------------------------------------------------------------+
99 | *like*             | Lists results that contain the substring you specify. For            |
100 |                    | example, if you specify *like %BC%*, every string that contains      |
101 |                    | that particular substring is displayed.                              |
102 +--------------------+----------------------------------------------------------------------+
103 | *<*                | Lists results that are less than the value you specify.              |
104 +--------------------+----------------------------------------------------------------------+
105 | *>*                | Lists results that are more than the value you specify.              |
106 +--------------------+----------------------------------------------------------------------+
107 | *and*              | Lists results that match both values you specify.                    |
108 +--------------------+----------------------------------------------------------------------+
109 | *or*               | Lists results that match either of the two values you specify.       |
110 +--------------------+----------------------------------------------------------------------+
111 | *>=*               | Lists results that are more than or equal to the value you specify.  |
112 +--------------------+----------------------------------------------------------------------+
113 | *<=*               | Lists results that are less than or equal to the value you specify.  |
114 +--------------------+----------------------------------------------------------------------+
115 | *is null*          | Lists results for which no value is assigned.                        |
116 +--------------------+----------------------------------------------------------------------+
117 | *not null*         | Lists results for which any value is assigned.                       |
118 +--------------------+----------------------------------------------------------------------+
119 | *skip*             | Use this operator to list matching results from a child node,        |
120 |                    | even if its parent node does not meet the specified criteria.        |
121 |                    | See the following example for more information.                      |
122 +--------------------+----------------------------------------------------------------------+
123
124 Example: Skip Criteria Operator
125 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
126
127 If you are looking at the following structure and want to determine all of the
128 ports that belong to a YY type module:
129
130 * Network Element 1
131
132   * Module 1, Type XX
133
134     * Module 1.1, Type YY
135
136       * Port 1
137       * Port 2
138
139   * Module 2, Type YY
140
141     * Port 1
142     * Port 2
143
144 If you specify *Module.Type='YY'* in your query criteria, the ports associated
145 with module 1.1 will not be returned since its parent module is type XX.
146 Instead, enter *Module.Type='YY' or skip Module!='YY'*. This tells XSQL to
147 disregard any parent module data that does not meet the type YY criteria and
148 collect results for any matching child modules. In this example, you are
149 instructing the query to skip module 1 and collect the relevant data from
150 module 1.1.