2003-01-19 Daniel Morgan <danmorg@sc.rr.com>
[mono.git] / web / sqlite
1 * SQL Lite Data Provider
2
3 <ul>
4         <li>Exists in namespace and assembly Mono.Data.SqliteClient</li>
5         
6         <li>Created by Vladimir Vukicevic</li>
7         
8         <li><a href"http://www.hwaci.com/sw/sqlite/download.html">SQL Lite</a>
9         binaries exist for Linux and Windows.  sqlite.dll on Windows 
10         and sqlite.so on Linux.</li>
11 </ul>
12
13 ** Current Status
14
15 <ul>
16         <li>Able to connect, execute commands, and retrieve data...</li>
17         
18         <li>Works in mPhoto by providing access to a SQL Lite database to store images.</li>
19 </ul>
20
21 ** Action Plan
22
23 <ul>
24         <li>Create a DataAdapter for SQL Lite named SqliteDataAdapter that can be used to 
25         Fill a DataTable in a DataSet</li>
26         
27         <li>Get the method GetSchemaTable() in class SqliteDataReader to return a DataTable
28         that works</li>
29 </ul>
30
31 ** Testing
32
33 <ul>
34         <li>Have a working mcs and mono</li>
35         <li>Make sure Mono.Data.SqliteClient.dll was built and is installed
36         in the same place as the mono class libraries.</li>
37         <li>If you do not have <a href"http://www.hwaci.com/sw/sqlite/download.html">SQL Lite</a>,
38         download it.  There are binaries for Windows and Linux.</li>
39         <li>There is a test named SqliteTest.cs found at mcs/class/Mono.Data.SqliteTest/Test</li>
40         <li>Has a connection string format of "URI=file:some/path".  For example, 
41         the connection string "URI=file:SqliteTest.db" will use the database file 
42         named SqliteTest.db, if it does not exist, the file will be created.</li>
43         <li>C# Example:
44 <pre>
45  using System;
46  using System.Data;
47  using Mono.Data.SqliteClient;
48  
49  public class Test 
50  {
51     public static void Main(string[] args)
52     {
53        string connectionString = "URI=file:SqliteTest.db";
54        IDbConnection dbcon;
55        dbcon = new MySQLConnection(connectionString);
56        IDbCommand dbcmd = dbcon.CreateCommand();
57        // requires a table to be created named employee
58        // with columns firstname and lastname
59        // such as,
60        //        CREATE TABLE employee (
61        //           firstname varchar(32),
62        //           lastname varchar(32));
63        string sql = 
64           "SELECT firstname, lastname " + 
65           "FROM employee";
66        dbcmd.ConnectionString = sql;
67        IDataReader reader = dbcmd.ExecuteReader();
68        while(reader.Read()) {
69             string FirstName = reader[0];
70             string LastName = reader[1];
71             Console.WriteLine("Name: " + 
72                 FirstName + " " + LastName);
73        }
74        // clean up
75        reader.Close();
76        reader = null;
77        dbcmd.Dispose();
78        dbcmd = null;
79        dbcon.Close();
80        dbcon = null;
81     }
82  }
83 </pre>
84         </li>
85         <li>Building C# Example:
86         <ul>
87                 <li>Save the example to a file, such as, TestExample.cs</li>
88                 <li>Build on Linux:
89 <pre>
90         mcs TestExample.cs -r System.Data.dll \
91             -r Mono.Data.SqliteClient.dll
92 </pre>
93                 </li>
94                 <li>Build on Windows via Cygwin:
95 <pre>
96         mono C:/cygwin/home/MyHome/mono/install/bin/mcs.exe \
97              TestExample.cs \
98              -lib:C:/cygwin/home/MyHome/mono/install/lib \
99              -r System.Data.dll \
100              -r Mono.Data.SqliteClient.dll
101 </pre>
102                 </li>
103         </ul>
104         </li>
105         <li>Running the Example:
106 <pre>
107 mono TestExample.exe
108 </pre>
109         </li>
110
111 </ul>
112