(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / Mono.Data.DB2Client / Test / TestDB2Conn / TestDB2Conn.cs
blob73d80310f132bfd5a569bd108a0bb1a5e3ba14bd
1 #region Licence
2 /// DB2DriverCS Test Code - A DB2 driver test for .Net
3 /// Copyright 2003 By Christopher Bockner
4 /// Released under the terms of the MIT/X11 Licence
5 /// Please refer to the Licence.txt file that should be distributed with this package
6 /// This software requires that DB2 client software be installed correctly on the machine
7 /// (or instance) on which the driver is running.
8 ///
9 #endregion
11 using System;
12 using System.Data;
13 using DB2ClientCS;
14 using System.Text;
16 namespace TestDB2Conn {
17 /// <summary>
18 /// Code to test DB2DriverCS.
19 /// </summary>
20 class TestDB2Client
22 static void DoTest(string database, string userid, string password)
24 IDbCommand command = null;
25 string connectionString = String.Format(
26 "DSN={0};UID={1};PWD={2}",
27 database, userid, password);
28 try {
29 Console.WriteLine("Create DB2 client Connection...");
30 DB2ClientConnection DB2Conn = new DB2ClientConnection();
32 Console.WriteLine("connection string: " + connectionString);
34 Console.WriteLine("Set connection string...");
35 DB2Conn.ConnectionString = connectionString;
37 Console.WriteLine("Open a connection...");
38 DB2Conn.Open();
40 string createTestTableSQL =
41 "CREATE TABLE mono_db2_test1 ( " +
42 " testid varchar(2), " +
43 " testdesc varchar(16) " +
44 ")";
45 Console.WriteLine("SQL:\n" + createTestTableSQL);
47 Console.WriteLine("Create a command using sql and connection...");
48 command = new DB2ClientCommand(createTestTableSQL,DB2Conn);
49 Console.WriteLine("Execute Non Query...");
50 command.ExecuteNonQuery();
52 string selectSQL = "select * from employee";
53 Console.WriteLine("SQL:\n" + selectSQL);
54 Console.WriteLine("create command and set connection and connection string...");
55 command = new DB2ClientCommand(selectSQL,DB2Conn);
56 Console.WriteLine("ExecuteReader...");
57 IDataReader dr = command.ExecuteReader();
58 Console.WriteLine("Read row...");
59 dr.Read();
60 Console.WriteLine("Read row...");
61 dr.Read();
62 Console.WriteLine("GetString...");
63 string dt = dr.GetString(1);
64 Console.WriteLine("dt: " + dt);
65 string s = dr.GetString(5);
66 Console.WriteLine("s: " + s);
67 DateTime t = dr.GetDateTime(6);
68 Console.WriteLine("t: " + t);
70 Console.WriteLine("Close connection...");
71 DB2Conn.Close();
73 catch(DB2ClientException e) {
74 System.Console.Write(e.Message);
77 /// <summary>
78 /// The main entry point for the application.
79 /// </summary>
80 [STAThread]
81 static void Main(string[] args)
83 if(args.Length != 3)
84 Console.WriteLine("Usage: mono TestDB2Conn.exe database userid password");
85 else {
86 Console.WriteLine("Test Begin.");
87 // database, userid, password
88 DoTest(args[0], args[1], args[2]);
89 Console.WriteLine("Test End.");