Commit aec9a9d2 authored by Marc Gravell's avatar Marc Gravell

Merge pull request #109 from majorsilence/sqlite-support

Add SQLiteAdapter
parents f8abab60 48c111ac
...@@ -29,7 +29,8 @@ public interface IProxy ...@@ -29,7 +29,8 @@ public interface IProxy
private static readonly Dictionary<string, ISqlAdapter> AdapterDictionary = new Dictionary<string, ISqlAdapter>() { private static readonly Dictionary<string, ISqlAdapter> AdapterDictionary = new Dictionary<string, ISqlAdapter>() {
{"sqlconnection", new SqlServerAdapter()}, {"sqlconnection", new SqlServerAdapter()},
{"npgsqlconnection", new PostgresAdapter()} {"npgsqlconnection", new PostgresAdapter()},
{"sqliteconnection", new SQLiteAdapter()}
}; };
private static IEnumerable<PropertyInfo> ComputedPropertiesCache(Type type) private static IEnumerable<PropertyInfo> ComputedPropertiesCache(Type type)
{ {
...@@ -551,4 +552,23 @@ public int Insert(IDbConnection connection, IDbTransaction transaction, int? com ...@@ -551,4 +552,23 @@ public int Insert(IDbConnection connection, IDbTransaction transaction, int? com
} }
return id; return id;
} }
} }
\ No newline at end of file
public class SQLiteAdapter : ISqlAdapter
{
public int Insert(IDbConnection connection, IDbTransaction transaction, int? commandTimeout, String tableName, string columnList, string parameterList, IEnumerable<PropertyInfo> keyProperties, object entityToInsert)
{
string cmd = String.Format("insert into {0} ({1}) values ({2})", tableName, columnList, parameterList);
connection.Execute(cmd, entityToInsert, transaction: transaction, commandTimeout: commandTimeout);
var r = connection.Query("select last_insert_rowid() id", transaction: transaction, commandTimeout: commandTimeout);
int id = (int)r.First().id;
if (keyProperties.Any())
keyProperties.First().SetValue(entityToInsert, id, null);
return id;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment