Skip to content

Commit

Permalink
Merge pull request #651 from pdesterlich/master
Browse files Browse the repository at this point in the history
added firebird support
  • Loading branch information
NickCraver authored Jan 28, 2017
2 parents fe5c270 + 16d8691 commit 01acca6
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Dapper.Contrib/SqlMapperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ private static readonly Dictionary<string, ISqlAdapter> AdapterDictionary
{"npgsqlconnection", new PostgresAdapter()},
{"sqliteconnection", new SQLiteAdapter()},
{"mysqlconnection", new MySqlAdapter()},
{"fbconnection", new FbAdapter() }
};

private static List<PropertyInfo> ComputedPropertiesCache(Type type)
Expand Down Expand Up @@ -864,3 +865,35 @@ public void AppendColumnNameEqualsValue(StringBuilder sb, string columnName)
sb.AppendFormat("\"{0}\" = @{1}", columnName, columnName);
}
}

public partial class FbAdapter : ISqlAdapter
{
public int Insert(IDbConnection connection, IDbTransaction transaction, int? commandTimeout, string tableName, string columnList, string parameterList, IEnumerable<PropertyInfo> keyProperties, object entityToInsert)
{
var cmd = $"insert into {tableName} ({columnList}) values ({parameterList})";
connection.Execute(cmd, entityToInsert, transaction, commandTimeout);

var propertyInfos = keyProperties as PropertyInfo[] ?? keyProperties.ToArray();
var keyName = propertyInfos.First().Name;
var r = connection.Query($"SELECT FIRST 1 {keyName} ID FROM {tableName} ORDER BY {keyName} DESC", transaction: transaction, commandTimeout: commandTimeout);

var id = r.First().ID;
if (id == null) return 0;
if (!propertyInfos.Any()) return Convert.ToInt32(id);

var idp = propertyInfos.First();
idp.SetValue(entityToInsert, Convert.ChangeType(id, idp.PropertyType), null);

return Convert.ToInt32(id);
}

public void AppendColumnName(StringBuilder sb, string columnName)
{
sb.AppendFormat("{0}", columnName);
}

public void AppendColumnNameEqualsValue(StringBuilder sb, string columnName)
{
sb.AppendFormat("{0} = @{1}", columnName, columnName);
}
}

0 comments on commit 01acca6

Please sign in to comment.