2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / tools / sqlsharp / README
1 Mono SQL Query - Command Line Interface
2 =======================================
3
4 Running SQL Query on Mono:
5         mono sqlsharp.exe
6
7 Use this tool to test connection strings and enter SQL queries 
8 to different ADO.NET providers in Mono.
9
10 Basically, there are five commands a user should know:
11         \provider, \connectionstring, \open, \quit, and \help
12         
13 To connect to a database, you need to do the following:
14 1. set your data provider via \provider
15         Example:
16                 SQL# \provider mysql
17
18 2. set your connection string via \connectionstring
19         Example:
20                 SQL# \connectionstring Server=localhost;Database=test;User ID=someuser;Password=somepass
21                 
22 3. open a connection to the database via \open
23         Example:
24                 SQL# \open
25
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.
28
29 CONNECTION AND PROVIDER COMMANDS
30 ================================
31
32 \ConnectionString to set the ConnectionString
33         
34         Example connection strings for various providers:
35         
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
38                 
39         PostgreSQL via Npgsql provider:
40                 SQL# \ConnectionString Server=localhost;Database=test;User ID=postgres;Password=fun2db
41                 
42         MySQL via ByteFX.Data.MySqlClient provider:
43                 SQL# \ConnectionString Server=localhost;Database=test;User ID=mysql;Password=
44                 
45         ODBC via System.Data.Odbc provider using a DSN named "MSSQLDSN" I set up 
46         in the Windows control panel's ODBC Data Sources which connects 
47         to Microsoft SQL Server 2000:
48                 SQL# \ConnectionString DSN=MSSQLDSN;UID=danmorg;PWD=freetds
49
50         SQL Lite via Mono.Data.SqliteClient provider which connects to the
51         database file SqliteTest.db; if not found, the file is created:
52                 SQL# \ConnectionString URI=file:SqliteTest.db
53                 
54         OLE DB via System.Data.OleDb provider which connects to a PostgreSQL database:
55                 SQL# \ConnectionString Provider=PostgreSQL;Addr=127.0.0.1;Database=rodrigo
56                 
57         Oracle via System.Data.OracleClient
58                 SQL# \ConnectionString Data Source=testdb;User ID=scott;Password=tiger
59
60     FirebirdSql via FirebirdSql.Data.Firebird (not included with Mono)
61                 SQL# \ConnectionString Database=C:\FIREBIRD\EXAMPLES\EMPLOYEE.FDB;User=SYSDBA;Password=masterkey;Dialect=3;Server=localhost
62         
63
64 \Provider to set the Provider:
65
66     Provider    Name          Namespace                  Assembly
67     =========== ============= ========================== ==========================
68         OleDb       OLE DB        System.Data.OleDb          System.Data  
69         SqlClient   MS SQL 7/2000 System.Data.SqlClient      System.Data
70         Odbc        ODBC          System.Data.Odbc           System.Data
71         Sqlite      SQL Lite      Mono.Data.SqliteClient     Mono.Data.SqliteClient
72         Sybase      Sybase        Mono.Data.SybaseClient     Mono.Data.SybaseClient
73         Tds         TDS Generic   Mono.Data.TdsClient        Mono.Data.TdsClient
74         Oracle      Oracle 8i     System.Data.OracleClient   System.Data.OracleClient
75         PostgreSql  NET Postgres  Npgsql                     Npgsql
76         MySql       ByteFX MySQL  ByteFX.Data.MySqlClient    ByteFX.Data
77         Firebird    Firebird      FirebirdSql.Data.Firebird  FirebirdSql.Data.Firebird
78         
79         Example: to set the provider for MySQL:
80                 SQL# \provider mysql
81                 
82         Note: if you need to load an external provider in SQL#, 
83               see the SQL# command \loadextprovider 
84
85 \loadextprovider ASSEMBLY CLASS to load an external provider
86                                 use the complete name of its assembly and
87                                 its Connection class.
88
89         Example: to load the MySQL provider Mono.Data.MySql
90                 SQL# \loadextprovider Mono.Data.MySql Mono.Data.MySql.MySqlConnection
91         
92 \Open to open the connection
93
94         Example:
95                 SQL# \open
96
97 \Close to close the connection
98
99         Example:
100                 SQL# \close
101
102 \defaults to show default variables, such as, Provider and ConnectionString.
103
104         Example:
105                 SQL# \defaults
106
107 \Q to quit
108         Example:
109                 SQL# \q
110
111 SQL EXECUTION COMMANDS
112 ======================
113                 
114 \e to execute SQL query (SELECT)
115
116         Example: to execute a query
117         
118                 SQL# SELECT * FROM EMPLOYEE
119                 SQL# \e
120                 
121         Note: to get \e to automatically work after entering a query, put a
122               semicolon ; at the end of the query.
123               
124         Example: to enter and exectue query at the same time
125         
126                 SQL# SELECT * FROM EMPLOYEE;
127                 
128 \exenonquery to execute an SQL non query (not a SELECT)
129
130         Example: to insert a row into a table:
131         
132                 SQL# INSERT INTO SOMETABLE (COL1, COL2) VALUES('ABC','DEF')
133                 SQL# \exenonquery
134                 
135         Note: this can be used for those providers that are new and do not have
136               the ability to execute queries yet.      
137
138 \exescalar to execute SQL to get a single row and single column.
139
140         Example: to execute a Maxium aggregate
141                 SQL# SELECT MAX(grade) FROM class
142                 SQL# \exescalar 
143
144 \exexml FILENAME to execute SQL and save output to XML file
145
146         Example: 
147                 SQL# SELECT fname, lname, hire_date FROM employee
148                 SQL# \exexml employee.xml
149                 
150         Note: this depends on DataAdapter, DataTable, and DataSet
151               to be working properly
152               
153 FILE COMMANDS
154 =============              
155               
156 \f FILENAME to read a batch of SQL# commands from file
157
158         Example:
159                 SQL# \f batch.sql#
160                 
161         Note: the SQL# commands are interpreted as they are read.  If there is
162               any SQL statements, they are executed.
163
164 \o FILENAME to write result of commands executed to file.
165
166         Example:
167                 SQL# \o result.txt
168
169 \load FILENAME to load from file SQL commands into SQL buffer.
170
171         Example:
172                 SQL# \load commands.sql
173
174 \save FILENAME to save SQL commands from SQL buffer to file.
175
176         Example:
177                 SQL# \save commands.sql
178
179 GENERAL PURPOSE COMMANDS
180 ========================
181
182 \h to show help (all commands).
183
184         Example:
185                 SQL# \h
186
187 \s {TRUE, FALSE} to silent messages.
188
189         Example 1:
190                 SQL# \s true
191                 
192         Example 2:
193                 SQL# \s false
194         
195 \r to reset or clear the query buffer.
196
197         Example:
198                 SQL# \r
199
200 \print - show what's in the SQL buffer now.
201
202         Example:
203                 SQL# \print
204
205 VARIABLES WHICH CAN BE USED AS PARAMETERS
206 =========================================
207
208 \set NAME VALUE to set an internal variable.
209
210         Example:
211                 SQL# \set sFirstName John
212
213 \unset NAME to remove an internal variable.
214
215         Example:
216                 SQL# \unset sFirstName
217
218 \variable NAME to display the value of an internal variable.
219
220         Example:
221                 SQL# \variable sFirstName
222
223 PROVIDER SUPPORT OPTIONS
224 ========================
225
226 \UseParameters (TRUE,FALSE) to use parameters when executing SQL which
227                             use the variables that were set.  
228                             
229                             If this option is true, the SQL
230                             contains parameters, and for each parameter
231                             which does not have a SQL# variable set, the
232                             user will be prompted to enter the value
233                             for that parameter.
234
235         Example:
236                 SQL# \useparameter true
237                 
238         Default: false
239
240 \UseSimpleReader (TRUE,FALSE) to use simple reader when displaying results.
241
242         Example:
243                 SQL# \usesimplereader true
244                 
245         Default: false.  Mostly, this is dependent on the provider.  If the provider
246                          does not have enough of IDataReader implemented to have
247                          the normal reader working, then the simple reader can be used.
248                          
249