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