2 // MySqlTestBed.cs : This is base class which manages the connections to
3 // mysql database. This serves as a base class for all
4 // mysql database dependant tests.
7 // * create a test database in mysql server.
8 // * create an DNS entry.
9 // * update the MySqlTestBed.config with the DNS names and
10 // username, password for connection in the configuration key
12 // * compile using following command
13 // mcs /r:System.Data.dll,NUnit.Framework.dll /t:library /debug
14 // /out:MySqlTestBed.dll MySqlTestBed.cs System.Data.Odbc/*.cs
16 // mono /usr/local/bin/nunit-console.exe MySqlTestBed.dll
19 // Sureshkumar T (TSureshkumar@novell.com)
21 // Copyright (c) 2004 Novell Inc., and the individuals listed
22 // on the ChangeLog entries.
24 // Permission is hereby granted, free of charge, to any person obtaining
25 // a copy of this software and associated documentation files (the
26 // "Software"), to deal in the Software without restriction, including
27 // without limitation the rights to use, copy, modify, merge, publish,
28 // distribute, sublicense, and/or sell copies of the Software, and to
29 // permit persons to whom the Software is furnished to do so, subject to
30 // the following conditions:
32 // The above copyright notice and this permission notice shall be
33 // included in all copies or substantial portions of the Software.
35 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
36 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
37 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
38 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
39 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
40 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
41 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
46 using System.Data.Odbc;
47 using System.Collections.Specialized;
49 namespace MonoTests.System.Data
51 public class MySqlOdbcBaseClient
53 #region protected members
54 protected string connectionString = null;
55 protected OdbcConnection conn = null;
56 protected bool isConnAlive = false;
59 public MySqlOdbcBaseClient ()
61 //Connection String with DSN.
62 NameValueCollection appSettings = System.Configuration.ConfigurationSettings.AppSettings ;
63 connectionString = appSettings ["MySql-DSN"];
64 conn = new OdbcConnection (connectionString);
67 protected void OpenConnection ()
69 conn.ConnectionString = connectionString;
71 // run tests only if the connection is open,
72 // otherwise make it fail, to setup with correct
74 if (conn != null && conn.State != ConnectionState.Closed)
78 protected void CloseConnection ()
80 if (conn != null && conn.State != ConnectionState.Closed) {
86 protected void CreateTestSetup ()
90 // Create test database & tables
91 // mysql odbc does not supports batch sql statements
92 string createQuery = "DROP TABLE IF EXISTS test;" ;
93 ExecuteQuery (createQuery);
94 createQuery = "CREATE TABLE test (" +
95 "pk_tint TINYINT NOT NULL PRIMARY KEY," +
96 "col_char CHAR(20)," +
98 "col_blob TINYBLOB," +
99 "col_datetime DATETIME," +
103 ExecuteQuery (createQuery);
104 createQuery = "INSERT INTO test VALUES (1, 'mono test" +
105 "#1', 255, 127123645917568585638457243856234985, '2004-08-22', '2004-08-22', '12:00:00' );" ;
106 ExecuteQuery (createQuery);
107 createQuery = "INSERT INTO test VALUES (2, 'mono test" +
108 "#2', 256, NULL, NULL, NULL, NULL );";
109 ExecuteQuery (createQuery);
110 createQuery = "INSERT INTO test VALUES (3, 'mono test" +
111 "#3', 257 , 127123645917568585638457243856234985, '2004-08-22', '2004-08-22', '12:00:00');" ;
112 ExecuteQuery (createQuery);
113 createQuery = "INSERT INTO test VALUES (4, 'mono test" +
114 "#4', 258 , 127123645917568585638457243856234985, '2004-08-22', '2004-08-22', '12:00:00');" ;
115 ExecuteQuery (createQuery);
116 createQuery = "INSERT INTO test VALUES (5, 'mono test" +
117 "#5', 259, 127123645917568585638457243856234985, '2004-08-22', '2004-08-22', '12:00:00' );" ;
118 ExecuteQuery (createQuery);
121 private void ExecuteQuery (string query)
123 OdbcCommand cmd = new OdbcCommand ();
124 cmd.Connection = conn;
125 cmd.CommandText = query;
127 int recordsAff = cmd.ExecuteNonQuery ();
128 } catch (Exception e) {
132 protected void CleanTestSetup ()
136 // delete test database
137 string dropQuery = "DROP table IF EXISTS test";
138 //ExecuteQuery(dropQuery);