This is a very simple C# wrapper for SQLite 3. Only the essential API functions are supported (i.e. creating statements, binding parameters, executing statements).
Here's an example:
// Open the database
SQLite.DB db = new SQLite.DB("database.sqlite");
// Create the statement
SQLite.DB.Statement stmt = db.CreateStatement("SELECT * FROM dummy_table WHERE id = ?");
// Bind the value 4 to the first parameter
stmt.BindInt(1, 4);
// Execute the statement and receive an array of columns.
// You can execute a statement multiple times, and bind
// different values on the same parameter
SQLite.Column[] result = stmt.Exec();
if(result != null) {
// If it's null, the query didn't return anything
// Otherwise, there is at least one row
for (int i = 0; i < result.Length; ++i)
{
// Column name
string name = result[i].name;
// Column type
SQLite.Column.Type type = result[i].type;
// Column values. Make sure to cast those to the correct type based on the column type:
// INTEGER -> long
// FLOAT -> double
// TEXT -> string
// BLOB -> byte[]
// NULL -> 'values' is empty in this case, so no cast needed here
List<object> values = result[i].values;
// Every column will have the same number of values,
// which is also the number of rows.
}
}
This wrapper was created by UnexomWid. It is licensed under the MIT license.