Commit 70a9c31b authored by Marc Gravell's avatar Marc Gravell
parents 01157915 aec9a9d2
...@@ -3231,8 +3231,9 @@ protected void AddParameters(IDbCommand command, SqlMapper.Identity identity) ...@@ -3231,8 +3231,9 @@ protected void AddParameters(IDbCommand command, SqlMapper.Identity identity)
var dbType = param.DbType; var dbType = param.DbType;
var val = param.Value; var val = param.Value;
string name = Clean(param.Name); string name = Clean(param.Name);
var isCustomQueryParameter = typeof(SqlMapper.ICustomQueryParameter).IsAssignableFrom(val.GetType());
if (dbType == null && val != null) dbType = SqlMapper.LookupDbType(val.GetType(), name); if (dbType == null && val != null && !isCustomQueryParameter) dbType = SqlMapper.LookupDbType(val.GetType(), name);
if (dbType == DynamicParameters.EnumerableMultiParameter) if (dbType == DynamicParameters.EnumerableMultiParameter)
{ {
...@@ -3240,6 +3241,10 @@ protected void AddParameters(IDbCommand command, SqlMapper.Identity identity) ...@@ -3240,6 +3241,10 @@ protected void AddParameters(IDbCommand command, SqlMapper.Identity identity)
SqlMapper.PackListParameters(command, name, val); SqlMapper.PackListParameters(command, name, val);
#pragma warning restore 612, 618 #pragma warning restore 612, 618
} }
else if (isCustomQueryParameter)
{
((SqlMapper.ICustomQueryParameter)val).AddParameter(command, name);
}
else else
{ {
...@@ -3729,4 +3734,4 @@ public partial class FeatureSupport ...@@ -3729,4 +3734,4 @@ public partial class FeatureSupport
#endif #endif
} }
\ No newline at end of file
...@@ -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