2 using System.Data.OleDb;
4 namespace System.Data.OleDb.Test
8 private OleDbConnection m_cnc;
14 m_cnc = new OleDbConnection ("Provider=PostgreSQL;Addr=127.0.0.1;Database=rodrigo");
17 Console.WriteLine ("Connected to:");
18 Console.WriteLine (" Data Source: " + m_cnc.DataSource);
19 Console.WriteLine (" Database: " + m_cnc.Database);
20 Console.WriteLine (" Connection string: " + m_cnc.ConnectionString);
21 Console.WriteLine (" Provider: " + m_cnc.Provider);
22 Console.WriteLine (" Server version:" + m_cnc.ServerVersion);
24 /* create temporary table */
25 Console.WriteLine ("Creating temporary table...");
26 cmd = new OleDbCommand ("CREATE TABLE mono_test_table ( " +
27 " name varchar(25), email varchar(50), date_entered timestamp)",
29 cmd.ExecuteNonQuery ();
30 InsertRow ("Mike Smith", "mike@smiths.com");
31 InsertRow ("Julie Andrews", "julie@hollywood.com");
32 InsertRow ("Michael Jordan", "michael@bulls.com");
35 void InsertRow (string name, string email)
39 cmd = new OleDbCommand ("INSERT INTO mono_test_table (name, email, date_entered) VALUES ('" +
40 name + "', '" + email +"', date 'now')", m_cnc);
41 Console.WriteLine ("Executing command '" + cmd.CommandText + "'");
42 cmd.ExecuteNonQuery ();
46 void DisplayRow (OleDbDataReader reader)
48 for (int i = 0; i < reader.FieldCount; i++) {
49 Console.WriteLine (" " + reader.GetDataTypeName (i) + ": " +
50 reader.GetValue (i).ToString ());
54 void TestDataReader ()
57 string sql = "SELECT * FROM mono_test_table";
59 Console.WriteLine ("Executing SELECT command...");
60 OleDbCommand cmd = new OleDbCommand (sql, m_cnc);
61 OleDbDataReader reader = cmd.ExecuteReader ();
63 Console.WriteLine (" Recordset description:");
64 for (i = 0; i < reader.FieldCount; i++) {
65 Console.WriteLine (" Field " + i + ": " +
66 reader.GetName (i) + " (" +
67 reader.GetDataTypeName (i) + ")");
70 Console.WriteLine ("Reading data...");
72 while (reader.Read ()) {
73 Console.WriteLine ("Row " + i + ":");
81 void TestTransaction ()
83 Console.WriteLine ("Starting transaction...");
84 OleDbTransaction xaction = m_cnc.BeginTransaction ();
86 Console.WriteLine ("Aborting transaction...");
92 OleDbCommand cmd = new OleDbCommand ("DROP TABLE mono_test_table", m_cnc);
93 cmd.ExecuteNonQuery ();
97 static void Main (string[] args)
100 TestOleDb test = new TestOleDb ();
101 test.TestDataReader ();
102 test.TestTransaction ();
104 } catch (Exception e) {
105 Console.WriteLine ("An error has occured: {0}", e.ToString ());