1 Mono SQL Query - Command Line Interface
2 =======================================
4 Running SQL Query on Mono:
7 Use this tool to test connection strings and enter SQL queries
8 to different ADO.NET providers in Mono.
10 Basically, there are five commands a user should know:
11 \provider, \connectionstring, \open, \quit, and \help
13 To connect to a database, you need to do the following:
14 1. set your data provider via \provider
18 2. set your connection string via \connectionstring
20 SQL# \connectionstring Server=localhost;Database=test;User ID=someuser;Password=somepass
22 3. open a connection to the database via \open
26 Here are the SQL# Commands taken from the help command: \h
27 SQL# Commands are case insensitive, so \Q and \q work the same.
29 CONNECTION AND PROVIDER COMMANDS
30 ================================
32 \ConnectionString to set the ConnectionString
34 Example connection strings for various providers:
36 Microsoft SQL Server via System.Data.SqlClient or Mono.Data.TdsClient provider:
37 SQL# \ConnectionString Server=DANPC;Database=pubs;User ID=danmorg;Password=freetds
39 PostgreSQL via Npgsql provider:
40 SQL# \ConnectionString Server=localhost;Database=test;User ID=postgres;Password=fun2db
42 MySQL via ByteFX.Data.MySqlClient provider:
43 SQL# \ConnectionString Server=localhost;Database=test;User ID=mysql;Password=
45 MySQL via MySql.Data provider:
46 SQL# \ConnectionString Server=localhost;Database=test;User ID=mysql;Password=mypass;Pooling=false
48 ODBC via System.Data.Odbc provider using a DSN named "MSSQLDSN" I set up
49 in the Windows control panel's ODBC Data Sources which connects
50 to Microsoft SQL Server 2000:
51 SQL# \ConnectionString DSN=MSSQLDSN;UID=danmorg;PWD=freetds
53 SQL Lite via Mono.Data.SqliteClient provider which connects to the
54 database file SqliteTest.db; if not found, the file is created:
55 SQL# \ConnectionString URI=file:SqliteTest.db
57 OLE DB via System.Data.OleDb provider which connects to a PostgreSQL database:
58 SQL# \ConnectionString Provider=PostgreSQL;Addr=127.0.0.1;Database=rodrigo
60 Oracle via System.Data.OracleClient
61 SQL# \ConnectionString Data Source=testdb;User ID=scott;Password=tiger
63 FirebirdSql via FirebirdSql.Data.Firebird (not included with Mono)
64 SQL# \ConnectionString Database=C:\FIREBIRD\EXAMPLES\EMPLOYEE.FDB;User=SYSDBA;Password=masterkey;Dialect=3;Server=localhost
67 \Provider to set the Provider:
69 Provider Name Namespace Assembly
70 =========== ============= ========================== ==========================
71 OleDb OLE DB System.Data.OleDb System.Data
72 SqlClient MS SQL 7/2000 System.Data.SqlClient System.Data
73 Odbc ODBC System.Data.Odbc System.Data
74 Sqlite SQL Lite Mono.Data.SqliteClient Mono.Data.SqliteClient
75 Sybase Sybase Mono.Data.SybaseClient Mono.Data.SybaseClient
76 Tds TDS Generic Mono.Data.TdsClient Mono.Data.TdsClient
77 Oracle Oracle 8i System.Data.OracleClient System.Data.OracleClient
78 PostgreSql NET Postgres Npgsql Npgsql
79 ByteFX ByteFX MySQL ByteFX.Data.MySqlClient ByteFX.Data
80 Firebird Firebird FirebirdSql.Data.Firebird FirebirdSql.Data.Firebird
81 MySql MySQL AB MySql.Data.MySqlClient MySql.Data
83 Example: to set the provider for MySQL:
86 Note: if you need to load an external provider in SQL#,
87 see the SQL# command \loadextprovider
89 \loadextprovider ASSEMBLY CLASS to load an external provider
90 use the complete name of its assembly and
91 its Connection class. No spaces in the assembly name.
93 Example: to load the MySQL provider MySql.Data.dll from the GAC:
94 SQL# \loadextprovider MySql.Data,Version=1.0.7.30073,Culture=neutral,PublicKeyToken=8e323390df8d9ed4 MySql.Data.MySqlCliet.MySqlConnection
96 \Open to open the connection
101 \Close to close the connection
106 \defaults to show default variables, such as, Provider and ConnectionString.
115 SQL EXECUTION COMMANDS
116 ======================
118 \e to execute SQL query (SELECT)
120 Example: to execute a query
122 SQL# SELECT * FROM EMPLOYEE
125 Note: to get \e to automatically work after entering a query, put a
126 semicolon ; at the end of the query.
128 Example: to enter and exectue query at the same time
130 SQL# SELECT * FROM EMPLOYEE;
132 \exenonquery to execute an SQL non query (not a SELECT)
134 Example: to insert a row into a table:
136 SQL# INSERT INTO SOMETABLE (COL1, COL2) VALUES('ABC','DEF')
139 Note: this can be used for those providers that are new and do not have
140 the ability to execute queries yet.
142 \exescalar to execute SQL to get a single row and single column.
144 Example: to execute a Maxium aggregate
145 SQL# SELECT MAX(grade) FROM class
148 \exexml FILENAME to execute SQL and save output to XML file
151 SQL# SELECT fname, lname, hire_date FROM employee
152 SQL# \exexml employee.xml
154 Note: this depends on DataAdapter, DataTable, and DataSet
155 to be working properly
160 \f FILENAME to read a batch of SQL# commands from file
165 Note: the SQL# commands are interpreted as they are read. If there is
166 any SQL statements, they are executed.
168 \o FILENAME to write result of commands executed to file.
173 \load FILENAME to load from file SQL commands into SQL buffer.
176 SQL# \load commands.sql
178 \save FILENAME to save SQL commands from SQL buffer to file.
181 SQL# \save commands.sql
183 GENERAL PURPOSE COMMANDS
184 ========================
186 \h to show help (all commands).
191 \s {TRUE, FALSE} to silent messages.
199 \r to reset or clear the query buffer.
204 \print - show what's in the SQL buffer now.
209 VARIABLES WHICH CAN BE USED AS PARAMETERS
210 =========================================
212 \set NAME VALUE to set an internal variable.
215 SQL# \set sFirstName John
217 \unset NAME to remove an internal variable.
220 SQL# \unset sFirstName
222 \variable NAME to display the value of an internal variable.
225 SQL# \variable sFirstName
227 PROVIDER SUPPORT OPTIONS
228 ========================
230 \UseParameters (TRUE,FALSE) to use parameters when executing SQL which
231 use the variables that were set.
233 If this option is true, the SQL
234 contains parameters, and for each parameter
235 which does not have a SQL# variable set, the
236 user will be prompted to enter the value
240 SQL# \useparameter true
244 \UseSimpleReader (TRUE,FALSE) to use simple reader when displaying results.
247 SQL# \usesimplereader true
249 Default: false. Mostly, this is dependent on the provider. If the provider
250 does not have enough of IDataReader implemented to have
251 the normal reader working, then the simple reader can be used.