[f-spot/rubenv-gsoc-2009: 68/86] Be a bit more robust agains bad database values.



commit 10cb85b68cd25b11e85d86e273a3454d16085415
Author: Ruben Vermeersch <ruben savanne be>
Date:   Wed Aug 12 13:37:13 2009 +0200

    Be a bit more robust agains bad database values.
    
    NULL values can happen if you corrupt your database by running old
    versions next to new versions. As happens in my debugging :-).

 src/PhotoStore.cs |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
---
diff --git a/src/PhotoStore.cs b/src/PhotoStore.cs
index 237badf..f426115 100644
--- a/src/PhotoStore.cs
+++ b/src/PhotoStore.cs
@@ -187,8 +187,8 @@ public class PhotoStore : DbStore<Photo> {
 			System.Uri uri = new Uri (new Uri (reader ["base_uri"].ToString ()), reader ["filename"].ToString ());
 			string md5_sum = reader["md5_sum"] != null ? reader ["md5_sum"].ToString () : null;
 			bool is_protected = Convert.ToBoolean (reader["protected"]);
-			PhotoVersionType type = (PhotoVersionType) Enum.ToObject (typeof (PhotoVersionType), reader["type"]);
-			uint parent_version_id = Convert.ToUInt32 (reader ["parent_version_id"]);
+			PhotoVersionType type = (PhotoVersionType) Enum.ToObject (typeof (PhotoVersionType), reader["type"] ?? (uint) PhotoVersionType.Simple);
+			uint parent_version_id = Convert.ToUInt32 (reader ["parent_version_id"] ?? "0");
 			                              
 			if (type == PhotoVersionType.Hidden) {
 				photo.AddHiddenVersion (version_id, uri, md5_sum, name, is_protected, type, parent_version_id);
@@ -234,8 +234,8 @@ public class PhotoStore : DbStore<Photo> {
 				System.Uri uri = new Uri (new Uri (reader ["base_uri"].ToString ()), reader ["filename"].ToString ());
 				string md5_sum = reader["md5_sum"] != null ? reader ["md5_sum"].ToString () : null;
 				bool is_protected = Convert.ToBoolean (reader["protected"]);
-				PhotoVersionType type = (PhotoVersionType) Enum.ToObject (typeof (PhotoVersionType), reader["type"]);
-				uint parent_version_id = Convert.ToUInt32 (reader ["parent_version_id"]);
+				PhotoVersionType type = (PhotoVersionType) Enum.ToObject (typeof (PhotoVersionType), reader["type"] ?? (uint) PhotoVersionType.Simple);
+				uint parent_version_id = Convert.ToUInt32 (reader ["parent_version_id"] ?? "0");
 				
 				if (type == PhotoVersionType.Hidden) {
 					photo.AddHiddenVersion (version_id, uri, md5_sum, name, is_protected, type, parent_version_id);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]