Skip to content

Commit

Permalink
Remove old Expression/Reflection dependency injection cruft and just …
Browse files Browse the repository at this point in the history
…use conditional compilation.

Update with the latest libs.
  • Loading branch information
mythz committed Nov 11, 2011
1 parent 6423995 commit 450a746
Show file tree
Hide file tree
Showing 33 changed files with 433 additions and 596 deletions.
Binary file modified NuGet/ServiceStack.OrmLite.SqlServer/lib/ServiceStack.Common.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified NuGet/ServiceStack.OrmLite.Sqlite32/lib/ServiceStack.Common.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package>
<metadata>
<id>ServiceStack.OrmLite.Sqlite32</id>
<version>2.09</version>
<version>3.03</version>
<authors>Demis Bellot</authors>
<owners>Demis Bellot</owners>
<description>ServiceStack.NET OrmLite - Light, simple and fast convention-based POCO ORM</description>
Expand Down
Binary file modified NuGet/ServiceStack.OrmLite.Sqlite64/lib/ServiceStack.Common.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package>
<metadata>
<id>ServiceStack.OrmLite.Sqlite64</id>
<version>2.09</version>
<version>3.03</version>
<authors>Demis Bellot</authors>
<owners>Demis Bellot</owners>
<description>ServiceStack.NET OrmLite - Light, simple and fast convention-based POCO ORM</description>
Expand Down
Binary file modified lib/ServiceStack.Common.dll
Binary file not shown.
Binary file modified lib/ServiceStack.Common.pdb
Binary file not shown.
Binary file modified lib/ServiceStack.Interfaces.dll
Binary file not shown.
Binary file modified lib/ServiceStack.Text.pdb
Binary file not shown.
252 changes: 126 additions & 126 deletions src/ServiceStack.OrmLite.SqlServer/SqlServerOrmLiteDialectProvider.cs
Original file line number Diff line number Diff line change
@@ -1,128 +1,128 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;

namespace ServiceStack.OrmLite.SqlServer
{
public class SqlServerOrmLiteDialectProvider
: OrmLiteDialectProviderBase
{
public static SqlServerOrmLiteDialectProvider Instance = new SqlServerOrmLiteDialectProvider();

private static DateTime timeSpanOffset = new DateTime(1900,01,01);

public SqlServerOrmLiteDialectProvider()
{
base.AutoIncrementDefinition = "IDENTITY(1,1)";
base.StringColumnDefinition = "VARCHAR(8000)";
//base.DateTimeColumnDefinition = base.StringColumnDefinition;
base.BoolColumnDefinition = base.IntColumnDefinition;
base.GuidColumnDefinition = "UniqueIdentifier";
base.RealColumnDefinition = "FLOAT";
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;

namespace ServiceStack.OrmLite.SqlServer
{
public class SqlServerOrmLiteDialectProvider
: OrmLiteDialectProviderBase
{
public static SqlServerOrmLiteDialectProvider Instance = new SqlServerOrmLiteDialectProvider();

private static DateTime timeSpanOffset = new DateTime(1900,01,01);

public SqlServerOrmLiteDialectProvider()
{
base.AutoIncrementDefinition = "IDENTITY(1,1)";
base.StringColumnDefinition = "VARCHAR(8000)";
//base.DateTimeColumnDefinition = base.StringColumnDefinition;
base.BoolColumnDefinition = base.IntColumnDefinition;
base.GuidColumnDefinition = "UniqueIdentifier";
base.RealColumnDefinition = "FLOAT";
base.DecimalColumnDefinition = "DECIMAL(38,6)";
base.TimeColumnDefinition = "TIME"; //SQLSERVER 2008+

base.InitColumnTypeMap();
}

public override IDbConnection CreateConnection(string connectionString, Dictionary<string, string> options)
{
var isFullConnectionString = connectionString.Contains(";");

if (!isFullConnectionString)
{
var filePath = connectionString;

var filePathWithExt = filePath.ToLower().EndsWith(".mdf")
? filePath
: filePath + ".mdf";

var fileName = Path.GetFileName(filePathWithExt);
var dbName = fileName.Substring(0, fileName.Length - ".mdf".Length);

connectionString = string.Format(
@"Data Source=.\SQLEXPRESS;AttachDbFilename={0};Initial Catalog={1};Integrated Security=True;User Instance=True;",
filePathWithExt, dbName);
}

if (options != null)
{
foreach (var option in options)
{
if (option.Key.ToLower() == "read only")
{
if (option.Value.ToLower() == "true")
{
connectionString += "Mode = Read Only;";
}
continue;
}
connectionString += option.Key + "=" + option.Value + ";";
}
}

return new SqlConnection(connectionString);
}

public override object ConvertDbValue(object value, Type type)
{
try
{
if (value == null || value is DBNull) return null;

if (type == typeof(bool) && !(value is bool))
{
var intVal = Convert.ToInt32(value.ToString());
return intVal != 0;
}

if (type == typeof(TimeSpan) && value is DateTime)
{
var dateTimeValue = (DateTime)value;
return dateTimeValue - timeSpanOffset;
}

return base.ConvertDbValue(value, type);
}
catch (Exception ex)
{
throw;
}
}

public override string GetQuotedValue(object value, Type fieldType)
{
if (value == null) return "NULL";

if (fieldType == typeof(Guid))
{
var guidValue = (Guid)value;
return string.Format("CAST('{0}' AS UNIQUEIDENTIFIER)", guidValue);
}
if (fieldType == typeof(DateTime))
{
var dateValue = (DateTime)value;
const string iso8601Format = "yyyy-MM-dd HH:mm:ss.fff";
return base.GetQuotedValue(dateValue.ToString(iso8601Format), typeof(string));
}
if (fieldType == typeof(bool))
{
var boolValue = (bool)value;
return base.GetQuotedValue(boolValue ? 1 : 0, typeof(int));
}

return base.GetQuotedValue(value, fieldType);
}

public override long GetLastInsertId(IDbCommand dbCmd)
{
dbCmd.CommandText = "SELECT SCOPE_IDENTITY()";
var result = dbCmd.ExecuteScalar();
if (result is DBNull) return default(long);
if (result is decimal) return Convert.ToInt64((decimal)result);
return (long)result;
}
}
base.TimeColumnDefinition = "TIME"; //SQLSERVER 2008+

base.InitColumnTypeMap();
}

public override IDbConnection CreateConnection(string connectionString, Dictionary<string, string> options)
{
var isFullConnectionString = connectionString.Contains(";");

if (!isFullConnectionString)
{
var filePath = connectionString;

var filePathWithExt = filePath.ToLower().EndsWith(".mdf")
? filePath
: filePath + ".mdf";

var fileName = Path.GetFileName(filePathWithExt);
var dbName = fileName.Substring(0, fileName.Length - ".mdf".Length);

connectionString = string.Format(
@"Data Source=.\SQLEXPRESS;AttachDbFilename={0};Initial Catalog={1};Integrated Security=True;User Instance=True;",
filePathWithExt, dbName);
}

if (options != null)
{
foreach (var option in options)
{
if (option.Key.ToLower() == "read only")
{
if (option.Value.ToLower() == "true")
{
connectionString += "Mode = Read Only;";
}
continue;
}
connectionString += option.Key + "=" + option.Value + ";";
}
}

return new SqlConnection(connectionString);
}

public override object ConvertDbValue(object value, Type type)
{
try
{
if (value == null || value is DBNull) return null;

if (type == typeof(bool) && !(value is bool))
{
var intVal = Convert.ToInt32(value.ToString());
return intVal != 0;
}

if (type == typeof(TimeSpan) && value is DateTime)
{
var dateTimeValue = (DateTime)value;
return dateTimeValue - timeSpanOffset;
}

return base.ConvertDbValue(value, type);
}
catch (Exception ex)
{
throw;
}
}

public override string GetQuotedValue(object value, Type fieldType)
{
if (value == null) return "NULL";

if (fieldType == typeof(Guid))
{
var guidValue = (Guid)value;
return string.Format("CAST('{0}' AS UNIQUEIDENTIFIER)", guidValue);
}
if (fieldType == typeof(DateTime))
{
var dateValue = (DateTime)value;
const string iso8601Format = "yyyy-MM-dd HH:mm:ss.fff";
return base.GetQuotedValue(dateValue.ToString(iso8601Format), typeof(string));
}
if (fieldType == typeof(bool))
{
var boolValue = (bool)value;
return base.GetQuotedValue(boolValue ? 1 : 0, typeof(int));
}

return base.GetQuotedValue(value, fieldType);
}

public override long GetLastInsertId(IDbCommand dbCmd)
{
dbCmd.CommandText = "SELECT SCOPE_IDENTITY()";
var result = dbCmd.ExecuteScalar();
if (result is DBNull) return default(long);
if (result is decimal) return Convert.ToInt64((decimal)result);
return (long)result;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public override IDbConnection CreateConnection(string connectionString, Dictiona
if (connectionString != ":memory:")
{
var existingDir = Path.GetDirectoryName(connectionString);
if (!Directory.Exists(existingDir))
if (!string.IsNullOrEmpty(existingDir) && !Directory.Exists(existingDir))
{
Directory.CreateDirectory(existingDir);
}
Expand Down
100 changes: 0 additions & 100 deletions src/ServiceStack.OrmLite/ExpressionPropertyInvoker.cs

This file was deleted.

Loading

0 comments on commit 450a746

Please sign in to comment.