Change references to ByteFX.Data.MySQLClient to the
[mono.git] / web / mysql
1 * MySQL Data Provider
2
3  <p>There are two ADO.NET providers in Mono 
4  for a <a href="http://www.mysql.com/">MySQL</a> database:
5
6 <ul>
7         <li><a href="http://sourceforge.net/projects/mysqlnet/">ByteFX.Data.MySQLClient</a>
8                 <ul>
9                         <li>Written in 100% C#</li>
10                         <li>Does not require a client library</li>
11                         <li>Works on Mono and Microsoft .NET</li>
12                         <li>Requires at least Mono 0.18 and MySQLNet 0.65 for it to work on Mono</li>
13                         <li>Works in the SQL# command-line and GTK# GUI version</li>
14                 </ul>
15         </li>
16
17         <li>Mono.Data.MySql (deprecated)
18                 <ul>
19                         <li>Deprecated in favor of ByteFX.Data.MySQLClient
20                 
21                         <li>Written in C# and uses
22                                 the MySQL C Client Library</li>
23
24                         <li>Exists in namespace Mono.Data.MySql and assembly Mono.Data.MySql</li>
25         
26                         <li>Works on Windows and Linux via the MySQL client shared library
27                                 (libmySQL.dll on Windows and libmysqlclient.so on Linux).</li>
28             
29                         <li>Started by Daniel Morgan using 
30                                 <a href="http://www.cybercom.net/~zbrad/DotNet/MySql/">C# Bindings to MySQL</a> from <a href="mailto:zbrad@cybercom.net">Brad Merill</a></li>
31                 </ul>
32         </li>
33         
34         <li>Bugs with Mono or the data provider should be reported 
35         in Mono's Bugzilla <a href="http://bugzilla.ximian.com/">here</a>.  If you
36         do not have Bugzilla user account, it is free 
37         and easy to 
38         create one <a href="http://bugzilla.ximian.com/createaccount.cgi">here</a>.</li>
39         
40 </ul>
41
42  <p><a href="http://www.mysql.com/articles/dotnet/">Exploring MySQL 
43  in the Microsoft .NET Environment</a> is an article
44  by Mr. Venu who is a MySQL AB developer.</li>
45
46  <p>Testing for Mono's Mono.Data.MySql and ByteFX's ByteFX.Data.MySqlClient is below.
47     
48 ** Current Status
49
50  Current Status of the MySQL providers:
51
52 <ul>
53
54         <li>ByteFX.Data.MySqlClient
55                 <ul>
56                         <li>Build and Runs on Microsoft .NET and Mono</li>
57                         <li>Works with SQL# (command-line and GTK# GUI versions)</li>\r
58                         <li>MySQLCommandBuilder now implemented</li>\r
59                         <li>Transaction support now implemented (not all table types support this)</li>\r
60                         <li>GetSchemaTable fixed to not use xsd (for Mono)</li>\r
61                         <li>Driver is now Mono-compatible</li>\r
62                         <li>TIME data type now supported</li>\r
63                         <li>More work to improve Timestamp data type handling</li>\r
64                         <li>Changed signatures of all classes to match corresponding SqlClient classes</li>\r
65                         <li>Protocol compression  using <a href="http://www.icsharpcode.net/OpenSource/SharpZipLib/default.asp">SharpZipLib</a></li>\r
66                         <li>Named pipes on Windows now working properly</li>\r
67                         <li>Work done to improve Timestamp data type handling</li>\r
68                         <li>Implemented IEnumerable on DataReader so DataGrid would work</li>\r
69                         <li>Speed increased dramatically by removing bugging network sync code</li>\r
70                         <li>Driver no longer buffers rows of data (more ADO.Net compliant)</li>\r
71                         <li>Conversion bugs related to TIMESTAMP and DATETIME fields fixed</li>\r
72                         
73                 </ul>
74         </li>
75         
76         <li>Mono.Data.MySql (deprecated)
77                 <ul>
78                         <li>Currently, only works with version 3.23.x of MySQL</li>
79                 
80                         <li>can connect</li>
81         
82                         <li>can execute non-queries via ExecuteNonQuery()</li>
83         
84                         <li>can execute aggregates via ExecuteScalar() and retrieve the
85                                 single row/single column result</li>
86         
87                         <li>can execute queries and retrieve results using a data reader.</li>
88         
89                         <li>a schema DataTable has been partially 
90                                 implemented which is returned from GetSchemaTable() in MySqlDataReader.</li>
91         
92                         <li>a DataTable in a DataSet can be filled via a MySqlDataAdapter</li>
93                 
94                         <li>The shared client libraries 
95                                 between windows version and linux are different: windows has libmySQL.dll 
96                                 while linux has libmysqlclient.so.  This is handled by the 
97                                 file etc/mono/config which is mapped by the mono runtime in knowing
98                                 which native shared library to load.  In cvs, this file is mono/config.in and
99                                 can be modified with a text editor.</li>
100         
101                         <li>Works in the SQL# command-line and GTK# GUI version</li>
102                 </ul>
103         </li>
104         
105 </ul>
106
107 ** Action plan
108
109  The current plan for the MySQL data providers:
110  
111  <ul>
112         <li>ByteFX.Data.MySqlClient
113                 <ul>
114                         <li>Testing and fixes</li>
115                         <li>Implement missing features</li>
116                         <li>Only fixes for bugs to build and run MySQLClient on Mono
117                         will be accepted in mono-cvs.  Most bugs and any new features will
118                         go into sourceforge cvs.  Anytime there is a release of MySQLClient,
119                         the source code will be copied from sourceforge cvs to mono-cvs</li>
120                         <li>Releases of MySQLClient are determined by Reggie Burnett and releases
121                         of Mono are determined by Miguel de Icaza</li>
122                         <li>Implement any missing features or fix any bugs in Mono to get new
123                         features all of MySQLClient to work on Mono</li>
124                 </ul>
125         </li>
126         <li>Mono.Data.MySql (deprecated)
127                 <ul>
128                         <li>Testing and bug fixes</li>
129                         <li>Mono.Data.MySql is deprecated and therefore maybe removed
130                         at a later date.  It will stay in Mono for now because other
131                         programs maybe using it now.</li>
132                 </ul>
133         </li>
134 </ul>
135
136 ** Testing for MySQLNet provider (ByteFX.Data.MySQLClient)
137
138 <ul>
139         <li>Have access to a MySQL database or download it from
140                 <ul>
141                         <li><a href="http://www.mysql.com/downloads/index.html">MySQL AB</a></li>
142                 </ul>
143         </li>
144         
145         <li>MySQLNet can be gotten from <a href="http://sourceforge.net/projects/mysqlnet/">here</a> and the 
146         binary assembly ByteFX.Data.dll needs to be     installed 
147         in the same place as the mono class libraries.</li>
148         
149         <li>MySQLNet requires <a href="http://www.icsharpcode.net/OpenSource/SharpZipLib/default.asp">SharpZipLib</a> which is 
150         a Zip Library written in 100% C#.  This is used for compression/decompression of data
151         sent/received over the network.  The SharpZipLib binary assembly SharpZipLib.dll should 
152         be installed in the same place as the mono class libraries.</li>
153         
154         <li>Has a ConnectionString format: 
155 <pre>
156 "Server=hostname;" +
157 "Database=database;" +
158 "User ID=username;" +
159 "Password=password"
160 </pre>
161         </li>
162         <li>C# Example:
163 <pre>
164  using System;
165  using System.Data;
166  using ByteFX.Data.MySqlClient;
167  
168  public class Test 
169  {
170     public static void Main(string[] args)
171     {
172        string connectionString = 
173           "Server=localhost;" +
174           "Database=test;" +
175           "User ID=myuserid;" +
176           "Password=mypassword;";
177        IDbConnection dbcon;
178        dbcon = new MySQLConnection(connectionString);
179        dbcon.Open();
180        IDbCommand dbcmd = dbcon.CreateCommand();
181        // requires a table to be created named employee
182        // with columns firstname and lastname
183        // such as,
184        //        CREATE TABLE employee (
185        //           firstname varchar(32),
186        //           lastname varchar(32));
187        string sql = 
188            "SELECT firstname, lastname " +
189            "FROM employee";
190        dbcmd.CommandText = sql;
191        IDataReader reader = dbcmd.ExecuteReader();
192        while(reader.Read()) {
193             string FirstName = (string) reader["firstname"];
194             string LastName = (string) reader["lastname"];
195             Console.WriteLine("Name: " + 
196                   FirstName + " " + LastName);
197        }
198        // clean up
199        reader.Close();
200        reader = null;
201        dbcmd.Dispose();
202        dbcmd = null;
203        dbcon.Close();
204        dbcon = null;
205     }
206  }
207 </pre>
208         </li>
209         <li>Building C# Example:
210         <ul>
211                 <li>Save the example to a file, such as, TestExample.cs</li>
212                 <li>Build on Linux:
213 <pre>
214         mcs TestExample.cs -r System.Data.dll \
215             -r ByteFX.Data.dll
216 </pre>
217                 </li>
218                 <li>Build on Windows via Cygwin:
219 <pre>
220         mono C:/cygwin/home/MyHome/mono/install/bin/mcs.exe \
221              TestExample.cs \
222              -lib:C:/cygwin/home/MyHome/mono/install/lib \
223              -r System.Data.dll -r ByteFX.Data.dll
224 </pre>
225                 </li>
226         </ul>
227         </li>
228         <li>Running the Example:
229 <pre>
230 mono TestExample.exe
231 </pre>
232         </li>
233
234 </ul>
235
236 ** Testing for Mono's MySQL provider (Mono.Data.MySql)
237
238 <ul>
239         <li>Have access to a MySQL database or download it from
240                 <ul>
241                         <li><a href="http://www.mysql.com/downloads/index.html">MySQL AB</a></li>
242                 </ul>
243         </li>
244         
245         <li>Take a look at MySqlTest.cs in mcs/class/Mono.Data.MySql/Test</li>
246         <li>On Linux, you may need to make a symbolic link from libmySQL.dll to libmysqlclient.dll</li>
247         
248         <li>Has a ConnectionString format: 
249 <pre>
250  "Server=hostname;Database=database;User ID=username;Password=password"
251          (or)
252  "Host=hostname;Dbname=database;User=username;Passwd=password"
253 </pre>
254
255         <li>C# Example:
256 <pre>
257  using System;
258  using System.Data;
259  using Mono.Data.MySql;
260  
261  public class Test 
262  {
263     public static void Main(string[] args)
264     {
265        string connectionString = 
266           "Server=localhost;" +
267           "Database=test;" +
268           "User ID=myuserid;" +
269           "Password=mypassword;";
270        IDbConnection dbcon;
271        dbcon = new MySqlConnection(connectionString);
272        dbcon.Open();
273        IDbCommand dbcmd = dbcon.CreateCommand();
274        // requires a table to be created named employee
275        // with columns firstname and lastname
276        // such as,
277        //        CREATE TABLE employee (
278        //           firstname varchar(32),
279        //           lastname varchar(32));
280        string sql = 
281             "SELECT firstname, lastname " + 
282             "FROM employee";
283        dbcmd.CommandText = sql;
284        IDataReader reader = dbcmd.ExecuteReader();
285        while(reader.Read()) {
286             string FirstName = reader["firstname"];
287             string LastName = reader["lastname"];
288             Console.WriteLine("Name: " + 
289                  FirstName + " " + LastName);
290        }
291        // clean up
292        reader.Close();
293        reader = null;
294        dbcmd.Dispose();
295        dbcmd = null;
296        dbcon.Close();
297        dbcon = null;
298     }
299  }
300 </pre>
301         </li>
302         <li>Building C# Example:
303         <ul>
304                 <li>Save the example to a file, such as, TestExample.cs</li>
305                 <li>Build on Linux:
306 <pre>
307         mcs TestExample.cs \
308             -r System.Data.dll \
309             -r Mono.Data.MySql.dll
310 </pre>
311                 </li>
312                 <li>Build on Windows via Cygwin:
313 <pre>
314         mono C:/cygwin/home/MyHome/mono/install/bin/mcs.exe \
315              TestExample.cs \
316              -lib:C:/cygwin/home/MyHome/mono/install/lib \
317              -r System.Data.dll \
318              -r Mono.Data.MySql.dll
319 </pre>
320                 </li>
321         </ul>
322         </li>
323         <li>Running the Example:
324 <pre>
325 mono TestExample.exe
326 </pre>
327         </li>
328
329 </ul>