2 // SqliteTest.cs - Test for the Sqlite ADO.NET Provider in Mono.Data.SqliteClient
\r
3 // This provider works on Linux and Windows and uses the native
\r
4 // sqlite.dll or sqlite.so library.
\r
6 // Modify or add to this test as needed...
\r
8 // SQL Lite can be downloaded from
\r
9 // http://www.hwaci.com/sw/sqlite/download.html
\r
11 // There are binaries for Windows and Linux.
\r
14 // mcs SqliteTest.cs -r System.Data.dll -r Mono.Data.SqliteClient.dll
\r
17 // Daniel Morgan <danmorg@sc.rr.com>
\r
22 using Mono.Data.SqliteClient;
\r
24 namespace Test.Mono.Data.SqliteClient
\r
29 static void Main(string[] args)
\r
31 Console.WriteLine("If this test works, you should get:");
\r
32 Console.WriteLine("Data 1: 5");
\r
33 Console.WriteLine("Data 2: Mono");
\r
35 Console.WriteLine("create SqliteConnection...");
\r
36 SqliteConnection dbcon = new SqliteConnection();
\r
38 // the connection string is a URL that points
\r
39 // to a file. If the file does not exist, a
\r
42 // "URI=file:some/path"
\r
43 string connectionString =
\r
44 "URI=file:SqliteTest.db";
\r
45 Console.WriteLine("setting ConnectionString using: " +
\r
47 dbcon.ConnectionString = connectionString;
\r
49 Console.WriteLine("open the connection...");
\r
52 Console.WriteLine("create SqliteCommand to CREATE TABLE MONO_TEST");
\r
53 SqliteCommand dbcmd = new SqliteCommand();
\r
54 dbcmd.Connection = dbcon;
\r
56 dbcmd.CommandText =
\r
57 "CREATE TABLE MONO_TEST ( " +
\r
60 Console.WriteLine("execute command...");
\r
61 dbcmd.ExecuteNonQuery();
\r
63 Console.WriteLine("set and execute command to INSERT INTO MONO_TEST");
\r
65 "INSERT INTO MONO_TEST " +
\r
68 dbcmd.ExecuteNonQuery();
\r
70 Console.WriteLine("set command to SELECT FROM MONO_TEST");
\r
72 "SELECT * FROM MONO_TEST";
\r
73 SqliteDataReader reader;
\r
74 Console.WriteLine("execute reader...");
\r
75 reader = dbcmd.ExecuteReader();
\r
77 Console.WriteLine("read and display data...");
\r
78 while(reader.Read()) {
\r
79 Console.WriteLine("Data 1: " + reader[0].ToString());
\r
80 Console.WriteLine("Data 2: " + reader[1].ToString());
\r
83 Console.WriteLine("read and display data using DataAdapter...");
\r
84 SqliteDataAdapter adapter = new SqliteDataAdapter("SELECT * FROM MONO_TEST", connectionString);
\r
85 DataSet dataset = new DataSet();
\r
86 adapter.Fill(dataset);
\r
87 foreach(DataTable myTable in dataset.Tables){
\r
88 foreach(DataRow myRow in myTable.Rows){
\r
89 foreach (DataColumn myColumn in myTable.Columns){
\r
90 Console.WriteLine(myRow[myColumn]);
\r
96 Console.WriteLine("clean up...");
\r
103 Console.WriteLine("Done.");
\r