[hyena] Allow force insert in SqliteModelProvider.Save ().
- From: Gabriel Burt <gburt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [hyena] Allow force insert in SqliteModelProvider.Save ().
- Date: Wed, 26 May 2010 02:36:42 +0000 (UTC)
commit 29046b8e5360514f59cb3425eee25c22558fe941
Author: Ruben Vermeersch <ruben savanne be>
Date: Fri Mar 26 01:38:27 2010 +0100
Allow force insert in SqliteModelProvider.Save ().
Adds a Save () overload to SqliteModelProvider which takes a second boolean
parameter to cause a forced insert.
This is needed for cases where you want to preinitialize the primary key to a
certain value. Simply calling Save () would cause the model provider to think
that this is an existing object, causing an update to happen. Result: object
not saved.
Example use case:
private class CacheParameters
{
[DatabaseColumn(Constraints = DatabaseColumnConstraints.PrimaryKey)]
public int CacheId { get; set; }
[DatabaseColumn]
public string Parameters { get; set; }
}
In this class, the CacheId parameter is set to match the id of objects in
another table. Without the overload, there is no way to save it.
https://bugzilla.gnome.org/show_bug.cgi?id=613981
.../Hyena.Data.Sqlite/SqliteModelProvider.cs | 10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/SqliteModelProvider.cs b/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/SqliteModelProvider.cs
index affa723..048ab8e 100644
--- a/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/SqliteModelProvider.cs
+++ b/src/Hyena.Data.Sqlite/Hyena.Data.Sqlite/SqliteModelProvider.cs
@@ -288,10 +288,10 @@ namespace Hyena.Data.Sqlite
));
}
- public virtual void Save (T target)
+ public virtual void Save (T target, bool force_insert)
{
try {
- if (Convert.ToInt32 (key.GetRawValue (target)) > 0) {
+ if (Convert.ToInt32 (key.GetRawValue (target)) > 0 && !force_insert) {
Update (target);
} else {
key.SetValue (target, Insert (target));
@@ -301,6 +301,12 @@ namespace Hyena.Data.Sqlite
Hyena.Log.DebugFormat ("type of key value: {0}", key.GetRawValue (target).GetType ());
throw;
}
+
+ }
+
+ public virtual void Save (T target)
+ {
+ Save (target, false);
}
protected virtual object [] GetInsertParams (T target)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]