MonoSqlite

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
Line 6: Line 6:
  
 
* Top Level Types
 
* Top Level Types
* DataSet - an in memory copy of your database
+
** DataSet - an in memory copy of your database
* DataTable - a mapping of a database table
+
** DataTable - a mapping of a database table
* DataRow, DataColumn, etc. - you get the picture
+
** DataRow, DataColumn, etc. - you get the picture
 
* Vendor Specific DB Types
 
* Vendor Specific DB Types
* SqliteConnection - provides connection to an sqlite database
+
** SqliteConnection - provides connection to an sqlite database
* SqliteCommand - an SQL query against the database
+
** SqliteCommand - an SQL query against the database
* SqliteParameter - an SQL parameter for parametrized queries
+
** SqliteParameter - an SQL parameter for parametrized queries
  
 
One of the early confusion points in reading any MicroSoft based documentation is that MS has claimed Sql as their vendor prefix for MS SQL Server.  This can cause quite a bit of confusion if you think of Sql as something generic, and don't realize those are all examples specific to MS SQL Server.
 
One of the early confusion points in reading any MicroSoft based documentation is that MS has claimed Sql as their vendor prefix for MS SQL Server.  This can cause quite a bit of confusion if you think of Sql as something generic, and don't realize those are all examples specific to MS SQL Server.

Revision as of 05:24, 27 August 2007

This is an attempted writeup of the methodology used with Mono / SQLite / ADO.NET in OpenSim. There is a real lack of information out there when trying to do something with these technologies. (this is very ongoing)

Contents

ADO.NET Overview

ADO.NET provides a level of abstraction from embedding SQL statements all through your code (which would be very bad). This is done by creating a top level set of objects that you can use to manipulate loaded data, as well as a way to connect these top level objects to your actual database.

  • Top Level Types
    • DataSet - an in memory copy of your database
    • DataTable - a mapping of a database table
    • DataRow, DataColumn, etc. - you get the picture
  • Vendor Specific DB Types
    • SqliteConnection - provides connection to an sqlite database
    • SqliteCommand - an SQL query against the database
    • SqliteParameter - an SQL parameter for parametrized queries

One of the early confusion points in reading any MicroSoft based documentation is that MS has claimed Sql as their vendor prefix for MS SQL Server. This can cause quite a bit of confusion if you think of Sql as something generic, and don't realize those are all examples specific to MS SQL Server.

Connecting Top Level Types to the Database

This example code will work, but it shouldn't be used, for reasons we'll go into later.

SqliteConnection con = new SqliteConnection("URI=file:opensim.db,version=3");
SqliteCommand fillcmd = new SqliteCommand("select * from prims", con);
SqliteDataAdapter da = new SqliteDataAdapter(fillcmd);
DataSet ds = new DataSet(); 
ds.Fill(da, "prims");

The database connection is vendor specific, obviously, as is the SQL statement (less obvious, but there are vendor differences that need to be handled). DataAdapter is an intermediary which manages pulling things from the database and getting them into the DataSet. Again, you can understand why this would be vendor specific.

The Dataset then uses that DataAdapter to fill itself from the dataconnection using the fillcmd we have specified.

XML for Free

One of the great things about using ADO.NET is that you get an intermediary XML format for free. Every DataSet has the following methods:

* GetXml(), GetXmlSchema()
* WriteXml(), WriteXmlSchema()
* ReadXml(), ReadXmlSchema()


Sqlite Specific Commands

Creating Schema Definitions

Building SqliteCommands

Personal tools
General
About This Wiki