Merge "Fixing PacketCable user guide formatting" into stable/lithium
[docs.git] / manuals / getting-started-guide / src / main / asciidoc / ch-xsql-commands.adoc
1 == Running XSQL Console Commands and Queries
2
3 //* <<XSQL Overview>>
4 //* <<Installing XSQL>>
5 //* <<XSQL Console Commands>>
6 //* <<XSQL Queries>>
7 //** <<Example: skip Criteria Operator>>
8 :toc:
9
10 === XSQL Overview
11
12 XSQL is an XML-based query language that describes simple stored procedures which parse XML data, query or update database tables, and compose XML output. It allows you to query tree models as if they were a sequential database. For example, you could run a query that lists all of the ports configured on a particular module and their attributes.
13
14 The following sections will cover the XSQL installation process, supported XSQL commands, and the proper way to structure queries.
15
16 === Installing XSQL
17
18 Before you can run commands from the XSQL console, you must first install XSQL onto your system:
19
20 '''
21
22 . Navigate to the directory in which you unzipped the OpenDaylight source files.
23 . Start Karaf: *./karaf*
24 . Install XSQL: *feature:install odl-mdsal-xsql*
25
26 '''
27
28 === XSQL Console Commands
29
30 When entering a command in the XSQL console, structure it as follows: *odl:xsql* _<XSQL command>_
31
32 The following table describes the commands supported in this OpenDaylight release.
33
34 .Supported XSQL Console Commands
35 [cols="2",options="headers"]
36 |==============================================
37 | *Command* | *Description*
38 | *r*
39 | Repeats the last command you executed.
40 | *list vtables*
41 | Lists the schema node containers that are currently installed. Whenever an OpenDaylight module is installed, its YANG model is placed in the Schema Context. At that point, the XSQL receives a notification, confirms that the module&#8217;s YANG model resides in the Schema Context, and then maps the model to XSQL by setting up the necessary vtables and vfields. This command is useful when you need to determine vtable information for a query.
42 | *list vfields* _<vtable name>_
43 | Lists the vfields present in a specific vtable. This command is useful when you need to determine vfields information for a query.
44 | *jdbc* _<ip address>_
45 | When the ODL server is behind a firewall, and the JDBC client cannot connect to the JDBC server, run this command to start the client as if it was a server and establish a connection.
46 | *exit*
47 | Closes the console.
48 | *tocsv*
49 | Enables/disables the forwarding of query output as a .csv file.
50 | *filename* _<filename>_
51 | Specifies the .tocsv file to which query data is exported. If you do not specify a value for this option when the toccsv option is enabled, the filename for the query data file is generated automatically.
52 |==============================================
53
54 === XSQL Queries
55
56 Using the information provided by the *list vtables* and *list vfields* _<vtable name>_ commands, you can run a query to extract information that meets the criteria you specify. Any query you run should be structured as follows:
57
58 *select* _<vfields you want to search for, separated by a comma and a space>_ *from* _<vtables you want to search in, separated by a comma and a space>_ *where* _<criteria>_ **&#8217;**_<criteria operator>_**&#8217;****;**
59
60 For example, say you want to search the nodes/node.ID field in the nodes/node-connector table and find every instance of the Hardware-Address object that contains _BA_ in its text string. To do so, you would enter the following query:
61 *Select nodes/node.ID from nodes/node-connector where Hardware-Address like &#8217;%BA%&#8217;;*
62
63 The following criteria operators are supported:
64
65 .Supported XSQL Query Criteria Operators
66 [cols="2",options="headers"]
67 |==============================================
68 | *Criteria Operators* | *Description*
69 | *=* | Lists results that equal the value you specify.
70 | *!=* | Lists results that do not equal the value you specify.
71 | *like* | Lists results that contain the substring you specify. For example, if you specify *like %BC%*, every string that contains that particular substring is displayed.
72 | *<* | Lists results that are less than the value you specify.
73 | *>* | Lists results that are more than the value you specify.
74 | *and* | Lists results that match both values you specify.
75 | *or* | Lists results that match either of the two values you specify.
76 | *>=* | Lists results that are more than or equal to the value you specify.
77 | *<=* | Lists results that are less than or equal to the value you specify.
78 | *is null* | Lists results for which no value is assigned.
79 | *not null* | Lists results for which any value is assigned.
80 | *skip* | Use this operator to list matching results from a child node, even if its parent node does not meet the specified criteria. See the following example for more information.
81 |==============================================
82
83 ==== Example: skip Criteria Operator
84
85 Say you are looking at the following structure and want to determine all of the ports that belong to a YY type module:
86
87 * Network Element 1
88 ** Module 1, Type XX
89 *** Module 1.1, Type YY
90 **** Port 1
91 **** Port 2
92 ** Module 2, Type YY
93 *** Port 1
94 *** Port 2
95
96 If you specify *Module.Type=&#8217;YY&#8217;* in your query criteria, the ports associated with module 1.1 will not be returned since its parent module is type XX. Instead, enter *Module.Type=&#8217;YY&#8217; or skip Module!=&#8217;YY&#8217;*. This tells XSQL to disregard any parent module data that does not meet the type YY criteria and collect results for any matching child modules. In this example, you are instructing the query to skip module 1 and collect the relevant data from module 1.1.
97