Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

removed duplicate files for sqlite providers

  • Loading branch information...
commit 2ef8bd53d3f347accd17b795ad4a57c19fc8f790 1 parent 7c78318
@BrannonKing BrannonKing authored
View
3  src/ServiceStack.OrmLite.Sqlite/ServiceStack.OrmLite.Sqlite.csproj
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -89,6 +89,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
+ <Compile Include="SqliteOrmLiteDialectProviderBase.cs" />
<Compile Include="SqliteOrmLiteDialectProvider.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SqliteExpressionVisitor.cs" />
View
160 src/ServiceStack.OrmLite.Sqlite/SqliteOrmLiteDialectProvider.cs
@@ -1,170 +1,16 @@
-using System;
-using System.Collections.Generic;
using System.Data;
-using System.Globalization;
-using System.IO;
-using System.Reflection;
-using System.Text;
using Mono.Data.Sqlite;
-using ServiceStack.Text.Common;
namespace ServiceStack.OrmLite.Sqlite
{
- public class SqliteOrmLiteDialectProvider
- : OrmLiteDialectProviderBase
+ public class SqliteOrmLiteDialectProvider: SqliteOrmLiteDialectProviderBase
{
+ // what's the purpose of this Instance field? (It's like a pseudo-wanna-be singleton?)
public static SqliteOrmLiteDialectProvider Instance = new SqliteOrmLiteDialectProvider();
- public SqliteOrmLiteDialectProvider()
+ protected override IDbConnection CreateConnection(string connectionString)
{
- base.DateTimeColumnDefinition = base.StringColumnDefinition;
- base.BoolColumnDefinition = base.IntColumnDefinition;
- base.GuidColumnDefinition = "CHAR(32)";
-
-
- base.InitColumnTypeMap();
- }
-
- public static string CreateFullTextCreateTableStatement(object objectWithProperties)
- {
- var sbColumns = new StringBuilder();
- foreach (var propertyInfo in objectWithProperties.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
- {
- var columnDefinition = (sbColumns.Length == 0)
- ? string.Format("{0} TEXT PRIMARY KEY", propertyInfo.Name)
- : string.Format(", {0} TEXT", propertyInfo.Name);
-
- sbColumns.AppendLine(columnDefinition);
- }
-
- var tableName = objectWithProperties.GetType().Name;
- var sql = string.Format("CREATE VIRTUAL TABLE \"{0}\" USING FTS3 ({1});", tableName, sbColumns);
-
- return sql;
- }
-
- public override IDbConnection CreateConnection(string connectionString, Dictionary<string, string> options)
- {
- var isFullConnectionString = connectionString.Contains(";");
-
- if (!isFullConnectionString)
- {
- if (connectionString != ":memory:")
- {
- var existingDir = Path.GetDirectoryName(connectionString);
- if (!string.IsNullOrEmpty(existingDir) && !Directory.Exists(existingDir))
- {
- Directory.CreateDirectory(existingDir);
- }
- }
- connectionString =
- @"Data Source=" + connectionString + ";Version=3;New=True;Compress=True;";
- }
-
- if (options != null)
- {
- foreach (var option in options)
- {
- connectionString += option.Key + "=" + option.Value + ";";
- }
- }
-
return new SqliteConnection(connectionString);
}
-
- public override string GetQuotedTableName(ModelDefinition modelDef)
- {
- if (!modelDef.IsInSchema)
- return base.GetQuotedTableName(modelDef);
-
- return string.Format("\"{0}_{1}\"", modelDef.Schema, modelDef.ModelName);
- }
-
- public override object ConvertDbValue(object value, Type type)
- {
- if (value == null || value is DBNull) return null;
-
- if (type == typeof(bool))
- {
- var intVal = int.Parse(value.ToString());
- return intVal != 0;
- }
- if (type == typeof(TimeSpan))
- {
- var dateValue = value as DateTime?;
- if (dateValue != null)
- {
- var now = DateTime.Now;
- var todayWithoutTime = new DateTime(now.Year, now.Month, now.Day);
- var ts = dateValue.Value - todayWithoutTime;
- return ts;
- }
- }
-
- try
- {
- 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 base.GetQuotedValue(guidValue.ToString("N"), typeof(string));
- }
- if (fieldType == typeof(DateTime))
- {
- var dateValue = (DateTime)value;
- return base.GetQuotedValue(
- DateTimeSerializer.ToShortestXsdDateTimeString(dateValue),
- 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 last_insert_rowid()";
- var result = dbCmd.ExecuteScalar();
- return (long)result;
- }
-
- public override SqlExpressionVisitor<T> ExpressionVisitor<T>()
- {
- return new SqliteExpressionVisitor<T>();
- }
-
- public override bool DoesTableExist(IDbCommand dbCmd, string tableName)
- {
- var sql = "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name = {0}"
- .SqlFormat(tableName);
-
- dbCmd.CommandText = sql;
- var result = dbCmd.GetLongScalar();
-
- return result > 0;
- }
-
- public override string GetColumnDefinition(string fieldName, Type fieldType, bool isPrimaryKey, bool autoIncrement, bool isNullable, int? fieldLength, int? scale, string defaultValue)
- {
- var ret = base.GetColumnDefinition(fieldName, fieldType, isPrimaryKey, autoIncrement, isNullable, fieldLength, scale, defaultValue);
- if (isPrimaryKey)
- return ret.Replace(" BIGINT ", " INTEGER ");
- return ret;
- }
}
}
View
167 src/ServiceStack.OrmLite.Sqlite/SqliteOrmLiteDialectProviderBase.cs
@@ -0,0 +1,167 @@
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.IO;
+using System.Reflection;
+using System.Text;
+using ServiceStack.Text.Common;
+
+namespace ServiceStack.OrmLite.Sqlite
+{
+ public abstract class SqliteOrmLiteDialectProviderBase: OrmLiteDialectProviderBase
+ {
+ public SqliteOrmLiteDialectProviderBase()
+ {
+ base.DateTimeColumnDefinition = base.StringColumnDefinition;
+ base.BoolColumnDefinition = base.IntColumnDefinition;
+ base.GuidColumnDefinition = "CHAR(32)";
+
+ base.InitColumnTypeMap();
+ }
+
+ public static string CreateFullTextCreateTableStatement(object objectWithProperties)
+ {
+ var sbColumns = new StringBuilder();
+ foreach (var propertyInfo in objectWithProperties.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
+ {
+ var columnDefinition = (sbColumns.Length == 0)
+ ? string.Format("{0} TEXT PRIMARY KEY", propertyInfo.Name)
+ : string.Format(", {0} TEXT", propertyInfo.Name);
+
+ sbColumns.AppendLine(columnDefinition);
+ }
+
+ var tableName = objectWithProperties.GetType().Name;
+ var sql = string.Format("CREATE VIRTUAL TABLE \"{0}\" USING FTS3 ({1});", tableName, sbColumns);
+
+ return sql;
+ }
+
+ public override IDbConnection CreateConnection(string connectionString, Dictionary<string, string> options)
+ {
+ var isFullConnectionString = connectionString.Contains(";");
+
+ if (!isFullConnectionString)
+ {
+ if (connectionString != ":memory:")
+ {
+ var existingDir = Path.GetDirectoryName(connectionString);
+ if (!string.IsNullOrEmpty(existingDir) && !Directory.Exists(existingDir))
+ {
+ Directory.CreateDirectory(existingDir);
+ }
+ }
+ connectionString =
+ @"Data Source=" + connectionString + ";Version=3;New=True;Compress=True;";
+ }
+
+ if (options != null)
+ {
+ foreach (var option in options)
+ {
+ connectionString += option.Key + "=" + option.Value + ";";
+ }
+ }
+
+ return CreateConnection(connectionString);
+ }
+
+ protected abstract IDbConnection CreateConnection(string connectionString);
+
+ public override string GetQuotedTableName(ModelDefinition modelDef)
+ {
+ if (!modelDef.IsInSchema)
+ return base.GetQuotedTableName(modelDef);
+
+ return string.Format("\"{0}_{1}\"", modelDef.Schema, modelDef.ModelName);
+ }
+
+ public override object ConvertDbValue(object value, Type type)
+ {
+ if (value == null || value is DBNull) return null;
+
+ if (type == typeof(bool))
+ {
+ var intVal = int.Parse(value.ToString());
+ return intVal != 0;
+ }
+ if (type == typeof(TimeSpan))
+ {
+ var dateValue = value as DateTime?;
+ if (dateValue != null)
+ {
+ var now = DateTime.Now;
+ var todayWithoutTime = new DateTime(now.Year, now.Month, now.Day);
+ var ts = dateValue.Value - todayWithoutTime;
+ return ts;
+ }
+ }
+
+ try
+ {
+ 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 base.GetQuotedValue(guidValue.ToString("N"), typeof(string));
+ }
+ if (fieldType == typeof(DateTime))
+ {
+ var dateValue = (DateTime)value;
+ return base.GetQuotedValue(
+ DateTimeSerializer.ToShortestXsdDateTimeString(dateValue),
+ 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 last_insert_rowid()";
+ var result = dbCmd.ExecuteScalar();
+ return (long)result;
+ }
+
+ public override SqlExpressionVisitor<T> ExpressionVisitor<T>()
+ {
+ return new SqliteExpressionVisitor<T>();
+ }
+
+ public override bool DoesTableExist(IDbCommand dbCmd, string tableName)
+ {
+ var sql = "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name = {0}"
+ .SqlFormat(tableName);
+
+ dbCmd.CommandText = sql;
+ var result = dbCmd.GetLongScalar();
+
+ return result > 0;
+ }
+
+ public override string GetColumnDefinition(string fieldName, Type fieldType, bool isPrimaryKey, bool autoIncrement, bool isNullable, int? fieldLength, int? scale, string defaultValue)
+ {
+ // http://www.sqlite.org/lang_createtable.html#rowid
+ var ret = base.GetColumnDefinition(fieldName, fieldType, isPrimaryKey, autoIncrement, isNullable, fieldLength, scale, defaultValue);
+ if (isPrimaryKey)
+ return ret.Replace(" BIGINT ", " INTEGER ");
+ return ret;
+ }
+ }
+}
View
7 src/ServiceStack.OrmLite.Sqlite32/ServiceStack.OrmLite.Sqlite32.csproj
@@ -47,8 +47,13 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="..\ServiceStack.OrmLite.Sqlite\SqliteExpressionVisitor.cs">
+ <Link>SqliteExpressionVisitor.cs</Link>
+ </Compile>
+ <Compile Include="..\ServiceStack.OrmLite.Sqlite\SqliteOrmLiteDialectProviderBase.cs">
+ <Link>SqliteOrmLiteDialectProviderBase.cs</Link>
+ </Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="SqliteExpressionVisitor.cs" />
<Compile Include="SqliteOrmLiteDialectProvider.cs" />
</ItemGroup>
<ItemGroup>
View
121 src/ServiceStack.OrmLite.Sqlite32/SqliteExpressionVisitor.cs
@@ -1,121 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Collections.ObjectModel;
-using System.Linq.Expressions;
-using ServiceStack.OrmLite;
-
-namespace ServiceStack.OrmLite.Sqlite
-{
- /// <summary>
- /// Description of SqliteExpressionVisitor.
- /// </summary>
- public class SqliteExpressionVisitor<T>: SqlExpressionVisitor<T>
- {
- public SqliteExpressionVisitor():base()
- {
- }
-
- protected override string VisitMethodCall(MethodCallExpression m)
- {
- List<Object> args = this.VisitExpressionList(m.Arguments);
-
- object r ;
- if (m.Object!=null)
- r=Visit(m.Object);
- else {
- r= args[0];
- args.RemoveAt(0);
- }
-
- switch (m.Method.Name) {
- case "ToUpper":
- return string.Format("upper({0})",r);
- case "ToLower":
- return string.Format("lower({0})",r);
- case "StartsWith":
- return string.Format("{0} like '{1}%'",r,RemoveQuote(args[0].ToString()) );
- case "EndsWith":
- return string.Format("{0} like '%{1}'",r,RemoveQuote(args[0].ToString()) );
- case "Contains":
- return string.Format("{0} like '%{1}%'",r,RemoveQuote(args[0].ToString()) );
- case "Substring":
- var startIndex = Int32.Parse(args[0].ToString() ) +1;
- if (args.Count==2){
- var length = Int32.Parse( args[1].ToString() );
- return string.Format("substr({0}, {1}, {2})",
- r,
- startIndex,
- length);
- }
- else
- return string.Format("substr({0}, {1})",
- r,
- startIndex);
- case "Round":
- case "Floor":
- case "Ceiling":
- case "Coalesce":
- case "Abs":
- case "Sum":
- return string.Format("{0}({1}{2})",
- m.Method.Name,
- r,
- args.Count==1? string.Format(",{0}", args[0]):"" );
- case "Concat":
- var s = new StringBuilder();
- foreach (var e in args) {
- s.AppendFormat( " || {0}", e);
- }
- return string.Format("{0}{1}",r, s.ToString());
-
- case "In":
-
- var member = Expression.Convert(m.Arguments[1], typeof(object));
- var lambda = Expression.Lambda<Func<object>>(member);
- var getter = lambda.Compile();
-
- var inArgs = getter() as object[];
-
- var sIn = new StringBuilder();
- foreach (var e in inArgs) {
- if(e.GetType().ToString()!="System.Collections.Generic.List`1[System.Object]"){
- sIn.AppendFormat("{0}{1}",
- sIn.Length>0 ? ",":"",
- OrmLiteConfig.DialectProvider.GetQuotedValue(e, e.GetType()));
- }
- else{
- var listArgs= e as IList<Object>;
- foreach(Object el in listArgs){
- sIn.AppendFormat("{0}{1}",
- sIn.Length>0 ? ",":"",
- OrmLiteConfig.DialectProvider.GetQuotedValue(el, el.GetType()) );
- }
- }
- }
-
- return string.Format("{0} {1} ({2})", r, m.Method.Name, sIn);
- case "Desc":
- return string.Format("{0} DESC", r);
- case "As":
- return string.Format("{0} As {1}", r,
- OrmLiteConfig.DialectProvider.GetQuotedName( RemoveQuote( args[0].ToString() ) ) );
- case "ToString":
- return r.ToString();
- default:
- Console.WriteLine("******* Returning '{0}' for '{1}' *******", r, m.Method.Name);
-
- var s2 = new StringBuilder();
- foreach (var e in args) {
- s2.AppendFormat(",{0}",
- OrmLiteConfig.DialectProvider.GetQuotedValue(e, e.GetType()) );
- }
- return string.Format("{0}({1}{2})", m.Method.Name, r, s2);
-
- }
-
- }
-
- }
-}
View
153 src/ServiceStack.OrmLite.Sqlite32/SqliteOrmLiteDialectProvider.cs
@@ -1,157 +1,16 @@
-using System;
-using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
-using System.IO;
-using System.Reflection;
-using System.Text;
-using ServiceStack.Text.Common;
namespace ServiceStack.OrmLite.Sqlite
{
- public class SqliteOrmLiteDialectProvider
- : OrmLiteDialectProviderBase
- {
- public static SqliteOrmLiteDialectProvider Instance = new SqliteOrmLiteDialectProvider();
-
- public SqliteOrmLiteDialectProvider()
- {
- base.DateTimeColumnDefinition = base.StringColumnDefinition;
- base.BoolColumnDefinition = base.IntColumnDefinition;
- base.GuidColumnDefinition = "CHAR(32)";
-
- base.InitColumnTypeMap();
- }
-
- public static string CreateFullTextCreateTableStatement(object objectWithProperties)
- {
- var sbColumns = new StringBuilder();
- foreach (var propertyInfo in objectWithProperties.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
- {
- var columnDefinition = (sbColumns.Length == 0)
- ? string.Format("{0} TEXT PRIMARY KEY", propertyInfo.Name)
- : string.Format(", {0} TEXT", propertyInfo.Name);
-
- sbColumns.AppendLine(columnDefinition);
- }
-
- var tableName = objectWithProperties.GetType().Name;
- var sql = string.Format("CREATE VIRTUAL TABLE \"{0}\" USING FTS3 ({1});", tableName, sbColumns);
-
- return sql;
- }
-
- public override IDbConnection CreateConnection(string connectionString, Dictionary<string, string> options)
- {
- var isFullConnectionString = connectionString.Contains(";");
-
- if (!isFullConnectionString)
- {
- if (connectionString != ":memory:")
- {
- var existingDir = Path.GetDirectoryName(connectionString);
- if (!Directory.Exists(existingDir))
- {
- Directory.CreateDirectory(existingDir);
- }
- }
- connectionString =
- @"Data Source=" + connectionString + ";Version=3;New=True;Compress=True;";
- }
-
- if (options != null)
- {
- foreach (var option in options)
- {
- connectionString += option.Key + "=" + option.Value + ";";
- }
- }
-
- return new SQLiteConnection(connectionString);
- }
-
- public override string GetQuotedTableName(ModelDefinition modelDef)
- {
- if (!modelDef.IsInSchema)
- return base.GetQuotedTableName(modelDef);
-
- return string.Format("\"{0}_{1}\"", modelDef.Schema, modelDef.ModelName);
- }
-
- public override object ConvertDbValue(object value, Type type)
- {
- if (value == null || value is DBNull) return null;
-
- if (type == typeof(bool))
- {
- var intVal = int.Parse(value.ToString());
- return intVal != 0;
- }
-
- try
- {
- 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 base.GetQuotedValue(guidValue.ToString("N"), typeof(string));
- }
- if (fieldType == typeof(DateTime))
- {
- var dateValue = (DateTime)value;
- return base.GetQuotedValue(
- DateTimeSerializer.ToShortestXsdDateTimeString(dateValue),
- 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 last_insert_rowid()";
- var result = dbCmd.ExecuteScalar();
- return (long)result;
- }
-
- public override SqlExpressionVisitor<T> ExpressionVisitor<T>()
- {
- return new SqliteExpressionVisitor<T>();
- }
-
- public override bool DoesTableExist(IDbCommand dbCmd, string tableName)
- {
- var sql = "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name = {0}"
- .SqlFormat(tableName);
-
- dbCmd.CommandText = sql;
- var result = dbCmd.GetLongScalar();
-
- return result > 0;
- }
+ public class SqliteOrmLiteDialectProvider: SqliteOrmLiteDialectProviderBase
+ {
+ // what's the purpose of this Instance field? (It's like a pseudo-wanna-be singleton?)
+ public static SqliteOrmLiteDialectProvider Instance = new SqliteOrmLiteDialectProvider();
- public override string GetColumnDefinition(string fieldName, Type fieldType, bool isPrimaryKey, bool autoIncrement, bool isNullable, int? fieldLength, int? scale, string defaultValue)
+ protected override IDbConnection CreateConnection(string connectionString)
{
- var ret = base.GetColumnDefinition(fieldName, fieldType, isPrimaryKey, autoIncrement, isNullable, fieldLength, scale, defaultValue);
- if (isPrimaryKey)
- return ret.Replace(" BIGINT ", " INTEGER ");
- return ret;
+ return new SQLiteConnection(connectionString);
}
}
}
View
7 src/ServiceStack.OrmLite.Sqlite64/ServiceStack.OrmLite.Sqlite64.csproj
@@ -46,8 +46,13 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="..\ServiceStack.OrmLite.Sqlite\SqliteExpressionVisitor.cs">
+ <Link>SqliteExpressionVisitor.cs</Link>
+ </Compile>
+ <Compile Include="..\ServiceStack.OrmLite.Sqlite\SqliteOrmLiteDialectProviderBase.cs">
+ <Link>SqliteOrmLiteDialectProviderBase.cs</Link>
+ </Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="SqliteExpressionVisitor.cs" />
<Compile Include="SqliteOrmLiteDialectProvider.cs" />
</ItemGroup>
<ItemGroup>
View
112 src/ServiceStack.OrmLite.Sqlite64/SqliteExpressionVisitor.cs
@@ -1,112 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Collections.ObjectModel;
-using System.Linq.Expressions;
-using ServiceStack.OrmLite;
-
-namespace ServiceStack.OrmLite.Sqlite
-{
- /// <summary>
- /// Description of SqliteExpressionVisitor.
- /// </summary>
- public class SqliteExpressionVisitor<T>: SqlExpressionVisitor<T>
- {
- public SqliteExpressionVisitor():base()
- {
- }
-
- protected override string VisitMethodCall(MethodCallExpression m)
- {
- List<Object> args = this.VisitExpressionList(m.Arguments);
-
- object r ;
- if (m.Object!=null)
- r=Visit(m.Object);
- else {
- r= args[0];
- args.RemoveAt(0);
- }
-
- switch (m.Method.Name) {
- case "ToUpper":
- return string.Format("upper({0})",r);
- case "ToLower":
- return string.Format("lower({0})",r);
- case "StartsWith":
- return string.Format("{0} like '{1}%'",r,RemoveQuote(args[0].ToString()) );
- case "EndsWith":
- return string.Format("{0} like '%{1}'",r,RemoveQuote(args[0].ToString()) );
- case "Contains":
- return string.Format("{0} like '%{1}%'",r,RemoveQuote(args[0].ToString()) );
- case "Substring":
- var startIndex = Int32.Parse(args[0].ToString() ) +1;
- if (args.Count==2){
- var length = Int32.Parse( args[1].ToString() );
- return string.Format("substr({0}, {1}, {2})",
- r,
- startIndex,
- length);
- }
- else
- return string.Format("substr({0}, {1})",
- r,
- startIndex);
- case "Round":
- case "Floor":
- case "Ceiling":
- case "Coalesce":
- case "Abs":
- case "Sum":
- return string.Format("{0}({1}{2})",
- m.Method.Name,
- r,
- args.Count==1? string.Format(",{0}", args[0]):"" );
- case "Concat":
- var s = new StringBuilder();
- foreach (var e in args) {
- s.AppendFormat( " || {0}", e);
- }
- return string.Format("{0}{1}",r, s.ToString());
-
- case "In":
-
- var member = Expression.Convert(m.Arguments[1], typeof(object));
- var lambda = Expression.Lambda<Func<object>>(member);
- var getter = lambda.Compile();
-
- var inArgs = getter() as IList<Object>;
-
-
- var sIn = new StringBuilder();
- foreach (var e in inArgs) {
- sIn.AppendFormat("{0}{1}",
- sIn.Length>0 ? ",":"",
- OrmLiteConfig.DialectProvider.GetQuotedValue(e, e.GetType()));
- }
-
- return string.Format("{0} {1} ({2})", r, m.Method.Name, sIn);
- case "Desc":
- return string.Format("{0} DESC", r);
- case "As":
- return string.Format("{0} As {1}", r,
- OrmLiteConfig.DialectProvider.GetQuotedName( RemoveQuote( args[0].ToString() ) ) );
- case "ToString":
- return r.ToString();
- default:
- Console.WriteLine("******* Returning '{0}' for '{1}' *******", r, m.Method.Name);
-
- var s2 = new StringBuilder();
- foreach (var e in args) {
- s2.AppendFormat(",{0}",
- OrmLiteConfig.DialectProvider.GetQuotedValue(e, e.GetType()) );
- }
- return string.Format("{0}({1}{2})", m.Method.Name, r, s2);
-
- }
-
- }
-
- }
-}
View
163 src/ServiceStack.OrmLite.Sqlite64/SqliteOrmLiteDialectProvider.cs
@@ -1,157 +1,16 @@
-using System;
-using System.Collections.Generic;
-using System.Data;
-using System.Data.SQLite;
-using System.IO;
-using System.Reflection;
-using System.Text;
-using ServiceStack.Text.Common;
-
-namespace ServiceStack.OrmLite.Sqlite
-{
- public class SqliteOrmLiteDialectProvider
- : OrmLiteDialectProviderBase
- {
- public static SqliteOrmLiteDialectProvider Instance = new SqliteOrmLiteDialectProvider();
-
- public SqliteOrmLiteDialectProvider()
- {
- base.DateTimeColumnDefinition = base.StringColumnDefinition;
- base.BoolColumnDefinition = base.IntColumnDefinition;
- base.GuidColumnDefinition = "CHAR(32)";
-
- base.InitColumnTypeMap();
- }
-
- public static string CreateFullTextCreateTableStatement(object objectWithProperties)
- {
- var sbColumns = new StringBuilder();
- foreach (var propertyInfo in objectWithProperties.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
- {
- var columnDefinition = (sbColumns.Length == 0)
- ? string.Format("{0} TEXT PRIMARY KEY", propertyInfo.Name)
- : string.Format(", {0} TEXT", propertyInfo.Name);
-
- sbColumns.AppendLine(columnDefinition);
- }
-
- var tableName = objectWithProperties.GetType().Name;
- var sql = string.Format("CREATE VIRTUAL TABLE \"{0}\" USING FTS3 ({1});", tableName, sbColumns);
-
- return sql;
- }
-
- public override IDbConnection CreateConnection(string connectionString, Dictionary<string, string> options)
- {
- var isFullConnectionString = connectionString.Contains(";");
-
- if (!isFullConnectionString)
- {
- if (connectionString != ":memory:")
- {
- var existingDir = Path.GetDirectoryName(connectionString);
- if (!Directory.Exists(existingDir))
- {
- Directory.CreateDirectory(existingDir);
- }
- }
- connectionString =
- @"Data Source=" + connectionString + ";Version=3;New=True;Compress=True;";
- }
-
- if (options != null)
- {
- foreach (var option in options)
- {
- connectionString += option.Key + "=" + option.Value + ";";
- }
- }
-
- return new SQLiteConnection(connectionString);
- }
-
- public override string GetQuotedTableName(ModelDefinition modelDef)
- {
- if (!modelDef.IsInSchema)
- return base.GetQuotedTableName(modelDef);
-
- return string.Format("\"{0}_{1}\"", modelDef.Schema, modelDef.ModelName);
- }
-
- public override object ConvertDbValue(object value, Type type)
- {
- if (value == null || value is DBNull) return null;
-
- if (type == typeof(bool))
- {
- var intVal = int.Parse(value.ToString());
- return intVal != 0;
- }
-
- try
- {
- 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 base.GetQuotedValue(guidValue.ToString("N"), typeof(string));
- }
- if (fieldType == typeof(DateTime))
- {
- var dateValue = (DateTime)value;
- return base.GetQuotedValue(
- DateTimeSerializer.ToShortestXsdDateTimeString(dateValue),
- 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 last_insert_rowid()";
- var result = dbCmd.ExecuteScalar();
- return (long)result;
- }
-
- public override SqlExpressionVisitor<T> ExpressionVisitor<T>()
- {
- return new SqliteExpressionVisitor<T>();
- }
+using System.Data;
+using System.Data.SQLite;
- public override bool DoesTableExist(IDbCommand dbCmd, string tableName)
- {
- var sql = "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name = {0}"
- .SqlFormat(tableName);
-
- dbCmd.CommandText = sql;
- var result = dbCmd.GetLongScalar();
-
- return result > 0;
- }
+namespace ServiceStack.OrmLite.Sqlite
+{
+ public class SqliteOrmLiteDialectProvider : SqliteOrmLiteDialectProviderBase
+ {
+ // what's the purpose of this Instance field? (It's like a pseudo-wanna-be singleton?)
+ public static SqliteOrmLiteDialectProvider Instance = new SqliteOrmLiteDialectProvider();
- public override string GetColumnDefinition(string fieldName, Type fieldType, bool isPrimaryKey, bool autoIncrement, bool isNullable, int? fieldLength, int? scale, string defaultValue)
+ protected override IDbConnection CreateConnection(string connectionString)
{
- var ret = base.GetColumnDefinition(fieldName, fieldType, isPrimaryKey, autoIncrement, isNullable, fieldLength, scale, defaultValue);
- if (isPrimaryKey)
- return ret.Replace(" BIGINT ", " INTEGER ");
- return ret;
+ return new SQLiteConnection(connectionString);
}
- }
+ }
}
View
48 tests/ServiceStack.OrmLite.Sqlite64Tests/OrmLiteTestBase.cs
@@ -1,48 +0,0 @@
-using System;
-using System.IO;
-using NUnit.Framework;
-using ServiceStack.Common.Utils;
-using ServiceStack.Logging;
-using ServiceStack.Logging.Support.Logging;
-using ServiceStack.OrmLite.Sqlite;
-
-namespace ServiceStack.OrmLite.Tests
-{
- public class OrmLiteTestBase
- {
- protected virtual string ConnectionString { get; set; }
-
- protected string GetFileConnectionString()
- {
- var connectionString = "~/App_Data/db.sqlite".MapAbsolutePath();
- if (File.Exists(connectionString))
- File.Delete(connectionString);
-
- return connectionString;
- }
-
- protected void CreateNewDatabase()
- {
- if (ConnectionString.Contains(".sqlite"))
- ConnectionString = GetFileConnectionString();
- }
-
- [TestFixtureSetUp]
- public void TestFixtureSetUp()
- {
- LogManager.LogFactory = new ConsoleLogFactory();
-
- OrmLiteConfig.DialectProvider = SqliteOrmLiteDialectProvider.Instance;
- //ConnectionString = ":memory:";
- ConnectionString = GetFileConnectionString();
-
- //OrmLiteConfig.DialectProvider = SqlServerOrmLiteDialectProvider.Instance;
- //ConnectionString = "~/App_Data/Database1.mdf".MapAbsolutePath();
- }
-
- public void Log(string text)
- {
- Console.WriteLine(text);
- }
- }
-}
View
8 tests/ServiceStack.OrmLite.Sqlite64Tests/ServiceStack.OrmLite.Sqlite64Tests.csproj
@@ -50,9 +50,13 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
- <Compile Include="OrmLiteTestBase.cs" />
+ <Compile Include="..\ServiceStack.OrmLite.Sqlite32Tests\OrmLiteTestBase.cs">
+ <Link>OrmLiteTestBase.cs</Link>
+ </Compile>
+ <Compile Include="..\ServiceStack.OrmLite.Sqlite32Tests\UseCase\SimpleUseCase.cs">
+ <Link>UseCase\SimpleUseCase.cs</Link>
+ </Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="UseCase\SimpleUseCase.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\ServiceStack.OrmLite.Sqlite64\ServiceStack.OrmLite.Sqlite64.csproj">
View
65 tests/ServiceStack.OrmLite.Sqlite64Tests/UseCase/SimpleUseCase.cs
@@ -1,65 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Data;
-using NUnit.Framework;
-using ServiceStack.Common.Utils;
-using ServiceStack.OrmLite.Sqlite;
-using ServiceStack.DataAnnotations;
-
-namespace ServiceStack.OrmLite.Tests.UseCase
-{
- [TestFixture]
- public class SimpleUseCase
- {
- [TestFixtureSetUp]
- public void TestFixtureSetUp()
- {
- //Inject your database provider here
- OrmLiteConfig.DialectProvider = new SqliteOrmLiteDialectProvider();
- }
-
- public class User
- {
- public long Id { get; set; }
-
- [Index]
- public string Name { get; set; }
-
- public DateTime CreatedDate { get; set; }
- }
-
- [Test]
- public void Simple_CRUD_example()
- {
- //using (IDbConnection db = ":memory:".OpenDbConnection())
- using (IDbConnection db = "~/App_Data/db.sqlite".MapAbsolutePath().OpenDbConnection())
- using (IDbCommand dbCmd = db.CreateCommand())
- {
- dbCmd.CreateTable<User>(true);
-
- dbCmd.Insert(new User { Id = 1, Name = "A", CreatedDate = DateTime.Now });
- dbCmd.Insert(new User { Id = 2, Name = "B", CreatedDate = DateTime.Now });
- dbCmd.Insert(new User { Id = 3, Name = "B", CreatedDate = DateTime.Now });
-
- var rowsB = dbCmd.Select<User>("Name = {0}", "B");
-
- Assert.That(rowsB, Has.Count.EqualTo(2));
-
- var rowIds = rowsB.ConvertAll(x => x.Id);
- Assert.That(rowIds, Is.EquivalentTo(new List<long> { 2, 3 }));
-
- rowsB.ForEach(x => dbCmd.Delete(x));
-
- rowsB = dbCmd.Select<User>("Name = {0}", "B");
- Assert.That(rowsB, Has.Count.EqualTo(0));
-
- var rowsLeft = dbCmd.Select<User>();
- Assert.That(rowsLeft, Has.Count.EqualTo(1));
-
- Assert.That(rowsLeft[0].Name, Is.EqualTo("A"));
- }
- }
-
- }
-
-}
Please sign in to comment.
Something went wrong with that request. Please try again.