banshee r3442 - in trunk/banshee: . src/Libraries/Hyena/Hyena.Data.Sqlite
- From: gburt svn gnome org
- To: svn-commits-list gnome org
- Subject: banshee r3442 - in trunk/banshee: . src/Libraries/Hyena/Hyena.Data.Sqlite
- Date: Thu, 13 Mar 2008 16:10:32 +0000 (GMT)
Author: gburt
Date: Thu Mar 13 16:10:32 2008
New Revision: 3442
URL: http://svn.gnome.org/viewvc/banshee?rev=3442&view=rev
Log:
2008-03-13 Gabriel Burt <gabriel burt gmail com>
* src/Libraries/Hyena/Hyena.Data.Sqlite/DatabaseColumn.cs:
* src/Libraries/Hyena/Hyena.Data.Sqlite/HyenaSqliteCommand.cs:
* src/Libraries/Hyena/Hyena.Data.Sqlite/HyenaSqliteConnection.cs:
* src/Libraries/Hyena/Hyena.Data.Sqlite/SqliteUtils.cs: Patch from Scott
Peterson fixing up some DateTime/SQL related issues.
Modified:
trunk/banshee/ChangeLog
trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/DatabaseColumn.cs
trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/HyenaSqliteCommand.cs
trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/HyenaSqliteConnection.cs
trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/SqliteUtils.cs
Modified: trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/DatabaseColumn.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/DatabaseColumn.cs (original)
+++ trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/DatabaseColumn.cs Thu Mar 13 16:10:32 2008
@@ -84,26 +84,8 @@
public void SetValue (object target, IDataReader reader, int column)
{
// FIXME should we insist on nullable types?
- object result;
- if (type == typeof (string)) {
- result = !reader.IsDBNull (column)
- ? String.Intern (reader.GetString (column))
- : null;
- } else if (type == typeof (int)) {
- result = !reader.IsDBNull (column)
- ? reader.GetInt32 (column)
- : 0;
- } else if (type == typeof (int)) {
- result = !reader.IsDBNull (column)
- ? Convert.ToInt64 (reader.GetValue (column))
- : Int64.MinValue;
- } else {
- result = !reader.IsDBNull (column)
- ? Convert.ToInt64 (reader.GetValue (column))
- : 0;
- }
- result = SqliteUtils.FromDbFormat (type, result);
- SetValue (target, result);
+ object value = reader.IsDBNull (column) ? null : reader.GetValue (column);
+ SetValue (target, SqliteUtils.FromDbFormat(type, value));
}
public void SetValue (object target, object value)
Modified: trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/HyenaSqliteCommand.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/HyenaSqliteCommand.cs (original)
+++ trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/HyenaSqliteCommand.cs Thu Mar 13 16:10:32 2008
@@ -107,7 +107,7 @@
break;
}
} catch (Exception e) {
- Log.DebugFormat (String.Format ("Exception executing command: {0}", Text), e.ToString ());
+ Log.DebugFormat (String.Format ("Exception executing command: {0}", sql_command.CommandText), e.ToString ());
execution_exception = e;
}
@@ -150,12 +150,7 @@
if (param_values[i] is string) {
param_values[i] = String.Format ("'{0}'", (param_values[i] as string).Replace ("'", "''"));
} else if (param_values[i] is DateTime) {
- DateTime dt = (DateTime) param_values[i];
- if (dt == DateTime.MinValue) {
- param_values[i] = "NULL";
- } else {
- DateTimeUtil.FromDateTime ((DateTime) param_values[i]);
- }
+ param_values[i] = DateTimeUtil.FromDateTime ((DateTime) param_values[i]);
} else if (param_values[i] == null) {
param_values[i] = "NULL";
}
Modified: trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/HyenaSqliteConnection.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/HyenaSqliteConnection.cs (original)
+++ trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/HyenaSqliteConnection.cs Thu Mar 13 16:10:32 2008
@@ -109,9 +109,7 @@
result = command.WaitForResult (this);
}
- return result == null
- ? default (T)
- : (T) SqliteUtils.FromDbFormat (typeof (T), Convert.ChangeType (result, typeof (T)));
+ return (T)SqliteUtils.FromDbFormat (typeof (T), result);
}
public T Query<T> (HyenaSqliteCommand command, params object [] param_values)
Modified: trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/SqliteUtils.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/SqliteUtils.cs (original)
+++ trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/SqliteUtils.cs Thu Mar 13 16:10:32 2008
@@ -27,6 +27,7 @@
//
using System;
+using System.Reflection;
using System.Text;
namespace Hyena.Data.Sqlite
@@ -49,13 +50,13 @@
public static object ToDbFormat (Type type, object value)
{
if (type == typeof (DateTime)) {
- if (DateTime.MinValue.Equals (value)) {
- value = "NULL";
- } else {
- value = DateTimeUtil.FromDateTime ((DateTime)value);
- }
+ return DateTime.MinValue.Equals ((DateTime)value)
+ ? (object)null
+ : DateTimeUtil.FromDateTime ((DateTime)value);
} else if (type == typeof (TimeSpan)) {
- value = ((TimeSpan)value).TotalMilliseconds;
+ return TimeSpan.MinValue.Equals ((TimeSpan)value)
+ ? (object)null
+ : ((TimeSpan)value).TotalMilliseconds;
}
return value;
}
@@ -63,11 +64,22 @@
public static object FromDbFormat (Type type, object value)
{
if (type == typeof (DateTime)) {
- value = Int64.MinValue.Equals (value) ? DateTime.MinValue : DateTimeUtil.ToDateTime ((long) value);
+ return value == null
+ ? DateTime.MinValue
+ : DateTimeUtil.ToDateTime (Convert.ToInt64 (value));
} else if (type == typeof (TimeSpan)) {
- value = TimeSpan.FromMilliseconds ((long)value);
+ return value == null
+ ? TimeSpan.MinValue
+ : TimeSpan.FromMilliseconds (Convert.ToInt64 (value));
+ } else if (value == null) {
+ if (type.IsValueType) {
+ return Activator.CreateInstance (type);
+ } else {
+ return null;
+ }
+ } else {
+ return Convert.ChangeType (value, type);
}
- return value;
}
public static string BuildColumnSchema (string type,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]