diff --git a/.whitesource b/.whitesource new file mode 100644 index 000000000..9b3d393d5 --- /dev/null +++ b/.whitesource @@ -0,0 +1,8 @@ +########################################################## +#### WhiteSource "Bolt for Github" configuration file #### +########################################################## + +# Configuration # +#---------------# +ws.repo.scan=true +vulnerable.check.run.conclusion.level=failure diff --git a/src/SQLite.Net/SQLiteConnection.cs b/src/SQLite.Net/SQLiteConnection.cs index bb59b273e..960af80e1 100644 --- a/src/SQLite.Net/SQLiteConnection.cs +++ b/src/SQLite.Net/SQLiteConnection.cs @@ -1477,9 +1477,33 @@ public int Insert(object obj, string extra, Type objType) } } + bool usePkValue = false; + if (map.PK != null && map.PK.IsAutoInc) + { + var prop = objType.GetRuntimeProperty(map.PK.PropertyName); + if (prop != null) + { + var val = prop.GetValue(obj); + if (val != null && val.ToString() != "0") + { + usePkValue = true; + } + } + } + var replacing = string.Compare(extra, "OR REPLACE", StringComparison.OrdinalIgnoreCase) == 0; - var cols = replacing ? map.Columns : map.InsertColumns; + TableMapping.Column[] cols; + + if (usePkValue) + { + cols = replacing ? map.Columns : map.InsertColumnsWithPk; + } + else + { + cols = replacing ? map.Columns : map.InsertColumns; + } + var vals = new object[cols.Length]; for (var i = 0; i < vals.Length; i++) { diff --git a/src/SQLite.Net/TableMapping.cs b/src/SQLite.Net/TableMapping.cs index c14a5081b..46a14b0b4 100644 --- a/src/SQLite.Net/TableMapping.cs +++ b/src/SQLite.Net/TableMapping.cs @@ -105,6 +105,13 @@ public Column[] InsertColumns { get { return _insertColumns ?? (_insertColumns = Columns.Where(c => !c.IsAutoInc).ToArray()); } } + + [PublicAPI] + public Column[] InsertColumnsWithPk + { + get { return _insertColumns ?? (_insertColumns = Columns.ToArray()); } + } + [PublicAPI] public void SetAutoIncPK(object obj, long id)