sqlite 3.0 KB

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