private void Init(DbType dbType) { ISqlDialect dialect = null; switch (dbType) { case DbType.SQLServer: dialect = new SqlServerDialect(); break; case DbType.Oracle: dialect = new OracleDialect(); break; case DbType.DB2: dialect = new DB2DialectCustom(); break; case DbType.MySQL: dialect = new MySqlDialect(); break; default: throw new NotSupportedException("dbType"); } Config = new IdentityServerDapperExtensionsConfiguration(this, dialect); SqlGenerator = new SqlGeneratorImpl(Config); Db = new Database(Connection, SqlGenerator); }
/// <summary> /// 根据配置创建数据库连接 /// </summary> /// <returns></returns> public ISqlDialect CreateDialect() { ISqlDialect sqlDialect = null; switch (_dbType) { case DBType.SqlServer: sqlDialect = new SqlServerDialect(); break; case DBType.MySql: sqlDialect = new MySqlDialect(); break; case DBType.Oracle: sqlDialect = new OracleDialect(); break; case DBType.SqlCe: sqlDialect = new SqlCeDialect(); break; case DBType.SQLite: sqlDialect = new SqliteDialect(); break; } return(sqlDialect); }
public void QuoteString() { var dialect = new OracleDialect(); Assert.Equal("\"select * from TestEntity\"", dialect.QuoteString("`select * from TestEntity`")); Assert.Equal("SELECT * FROM TESTENTITY", dialect.QuoteString("select * from TestEntity")); }
public void ToSQL_Oracle_001() { var dialect = new OracleDialect(); var data = new Person { FirstName = "Chris", LastName = "Pietschmann" }; var target = new SQLinqInsert <Person>(data, dialect); var actual = (SQLinqInsertResult)target.ToSQL(); Assert.Equal("Person", actual.Table); Assert.Equal(7, actual.Fields.Count); Assert.Equal(":sqlinq_1", actual.Fields["ID"]); Assert.Equal(":sqlinq_2", actual.Fields["FirstName"]); Assert.Equal(":sqlinq_3", actual.Fields["LastName"]); Assert.Equal(":sqlinq_4", actual.Fields["Age"]); Assert.Equal(":sqlinq_5", actual.Fields["[Is_Employed]"]); Assert.Equal(":sqlinq_6", actual.Fields["ParentID"]); Assert.Equal(":sqlinq_7", actual.Fields["Column With Spaces"]); Assert.Equal(7, actual.Parameters.Count); Assert.Equal(Guid.Empty, actual.Parameters[":sqlinq_1"]); Assert.Equal("Chris", actual.Parameters[":sqlinq_2"]); Assert.Equal("Pietschmann", actual.Parameters[":sqlinq_3"]); Assert.Equal(0, actual.Parameters[":sqlinq_4"]); Assert.Equal(false, actual.Parameters[":sqlinq_5"]); Assert.Equal(Guid.Empty, actual.Parameters[":sqlinq_6"]); Assert.Equal(null, actual.Parameters[":sqlinq_7"]); }
/// <summary> /// 工厂模式 根据配置创建数据库 /// </summary> /// <returns></returns> public static ISqlDialect CreateSqlDialect() { ISqlDialect sqlDialect = null; switch (PubConstant.DbType.ToLower()) { case "mssql": sqlDialect = new SqlServerDialect(); break; case "mysql": sqlDialect = new MySqlDialect(); break; case "oracle": sqlDialect = new OracleDialect(); break; case "sqlce": sqlDialect = new SqlCeDialect(); break; case "sqlite": sqlDialect = new SqliteDialect(); break; } return(sqlDialect); }
/// <summary> /// Gets the Dapper Extensions Implementation /// </summary> public static IDapperImplementor Instance(DataBaseType dbType = DefaultDBType) { IDapperImplementor instance; if (!_instanceList.TryGetValue(dbType, out instance)) { ISqlDialect sqlDialect; switch (dbType) { case DataBaseType.SqlServer: sqlDialect = new SqlServerDialect(); break; case DataBaseType.Oracle: sqlDialect = new OracleDialect(); break; case DataBaseType.MySql: sqlDialect = new MySqlDialect(); break; default: sqlDialect = new SqlServerDialect(); break; } IDapperExtensionConfiguration iDapperExtensionsConfiguration = new DapperExtensionConfiguration( typeof(AutoClassMapper <>), new List <Assembly>(), sqlDialect ); instance = InstanceFactory(iDapperExtensionsConfiguration, dbType); _instanceList[dbType] = instance; } if (null == _DapperImplementor || _DapperImplementor.DbType != dbType) { _DapperImplementor = instance; } return(instance); }
public void ToSQL_Oracle_001() { var dialect = new OracleDialect(); var data = new Person { FirstName = "Chris", LastName = "Pietschmann" }; var target = new SQLinqInsert<Person>(data, dialect); var actual = (SQLinqInsertResult)target.ToSQL(); Assert.AreEqual("Person", actual.Table); Assert.AreEqual(7, actual.Fields.Count); Assert.AreEqual(":sqlinq_1", actual.Fields["ID"]); Assert.AreEqual(":sqlinq_2", actual.Fields["FirstName"]); Assert.AreEqual(":sqlinq_3", actual.Fields["LastName"]); Assert.AreEqual(":sqlinq_4", actual.Fields["Age"]); Assert.AreEqual(":sqlinq_5", actual.Fields["[Is_Employed]"]); Assert.AreEqual(":sqlinq_6", actual.Fields["ParentID"]); Assert.AreEqual(":sqlinq_7", actual.Fields["Column With Spaces"]); Assert.AreEqual(7, actual.Parameters.Count); Assert.AreEqual(Guid.Empty, actual.Parameters[":sqlinq_1"]); Assert.AreEqual("Chris", actual.Parameters[":sqlinq_2"]); Assert.AreEqual("Pietschmann", actual.Parameters[":sqlinq_3"]); Assert.AreEqual(0, actual.Parameters[":sqlinq_4"]); Assert.AreEqual(false, actual.Parameters[":sqlinq_5"]); Assert.AreEqual(Guid.Empty, actual.Parameters[":sqlinq_6"]); Assert.AreEqual(null, actual.Parameters[":sqlinq_7"]); }
public static void QuoteIdentifier_GivenNameWithDoubleQuote_ThrowsArgumentException() { const string input = "\"test_table"; var dialect = new OracleDialect(); Assert.That(() => dialect.QuoteIdentifier(input), Throws.ArgumentException); }
public static void QuoteIdentifier_GivenNameNullCharacter_ThrowsArgumentException() { var input = new string(new[] { 't', 'e', '\0', 's', 't' }); var dialect = new OracleDialect(); Assert.That(() => dialect.QuoteIdentifier(input), Throws.ArgumentException); }
public void GetIdentitySql() { var dialect = new OracleDialect(); Assert.Throws <NotImplementedException>(() => { dialect.GetIdentitySql("table"); }); }
public void GetSetSql() { var dialect = new OracleDialect(); var dictionary = new Dictionary <string, object>(); var query = dialect.GetSetSql("select * from TestEntity", 2, 10, dictionary); Assert.Contains("ROWNUM RNUM FROM", query); Assert.Equal(12, dictionary[":topLimit"]); Assert.Equal(2, dictionary[":toSkip"]); }
public static void QuoteIdentifier_GivenNameWithDotSeparators_ReturnsQuotedIdentifier() { const string input = "test.table.name"; const string expected = "\"test.table.name\""; var dialect = new OracleDialect(); var result = dialect.QuoteIdentifier(input); Assert.That(result, Is.EqualTo(expected)); }
public static void QuoteIdentifier_GivenRegularLocalName_ReturnsQuotedIdentifier() { const string input = "test_table"; const string expected = "\"test_table\""; var dialect = new OracleDialect(); var result = dialect.QuoteIdentifier(input); Assert.That(result, Is.EqualTo(expected)); }
public void UseWithSQLinqSubQuery_Oracle_001() { var dialect = new OracleDialect(); var query = new SQLinq<MyTable>(dialect); var result = query.ToSQL(); var actual = result.ToQuery(); var expected = "SELECT Identifier AS ID, FullName AS Name FROM (SELECT [Identifier], [FullName] FROM [tblSomeTable]) AS MyTable"; Assert.AreEqual(expected, actual); }
public void UseWithSQLinqSubQuery_Oracle_001() { var dialect = new OracleDialect(); var query = new SQLinq <MyTable>(dialect); var result = query.ToSQL(); var actual = result.ToQuery(); var expected = "SELECT Identifier AS ID, FullName AS Name FROM (SELECT [Identifier], [FullName] FROM [tblSomeTable]) AS MyTable"; Assert.AreEqual(expected, actual); }
public void ToSQL_Oracle_001() { var dialect = new OracleDialect(); var target = new SQLinqCollection(); target.Add(new SQLinq <ICar>(dialect)); var actual = (SQLinqCollectionResult)target.ToSQL(); Assert.AreEqual(1, actual.Queries.Count); Assert.AreEqual("SELECT * FROM ICar", actual.Queries[0]); }
public void UseWithSQLinqSubQuery_Oracle_002() { var dialect = new OracleDialect(); var query = from item in new SQLinq <MyTable>(dialect) where item.Name == "Chris" select item; var result = query.ToSQL(); var actual = result.ToQuery(); var expected = "SELECT Identifier AS ID, FullName AS Name FROM (SELECT [Identifier], [FullName] FROM [tblSomeTable]) AS MyTable WHERE FullName = :sqlinq_1"; Assert.AreEqual(expected, actual); }
public void UseWithSQLinqSubQuery_Oracle_002() { var dialect = new OracleDialect(); var query = from item in new SQLinq<MyTable>(dialect) where item.Name == "Chris" select item; var result = query.ToSQL(); var actual = result.ToQuery(); var expected = "SELECT Identifier AS ID, FullName AS Name FROM (SELECT [Identifier], [FullName] FROM [tblSomeTable]) AS MyTable WHERE FullName = :sqlinq_1"; Assert.AreEqual(expected, actual); }
public void ToSQL_Oracle_002() { var dialect = new OracleDialect(); var target = new SQLinqCollection(); target.Add(new SQLinq <ICar>(dialect).Where(d => d.WheelDiameter == 21)); target.Add(new SQLinq <ICar>(dialect).Where(d => d.WheelDiameter == 14)); var actual = (SQLinqCollectionResult)target.ToSQL(); Assert.AreEqual(2, actual.Queries.Count); Assert.AreEqual("SELECT * FROM ICar WHERE WheelDiameter = :sqlinq_1", actual.Queries[0]); Assert.AreEqual("SELECT * FROM ICar WHERE WheelDiameter = :sqlinq_2", actual.Queries[1]); Assert.AreEqual(2, actual.Parameters.Count); Assert.AreEqual(21, actual.Parameters[":sqlinq_1"]); Assert.AreEqual(14, actual.Parameters[":sqlinq_2"]); }
public static ISqlDialect ConvertESqlDialect(ESqlDialect sqlDialect) { ISqlDialect SqlDialect = null; switch (sqlDialect) { case ESqlDialect.DB2: SqlDialect = new DB2Dialect(); break; case ESqlDialect.MySQL: SqlDialect = new MySqlDialect(); break; case ESqlDialect.Oracle: SqlDialect = new OracleDialect(); break; case ESqlDialect.PostgreSql: SqlDialect = new PostgreSqlDialect(); break; case ESqlDialect.SqlCe: SqlDialect = new SqlCeDialect(); break; case ESqlDialect.Sqlite: SqlDialect = new SqliteDialect(); break; case ESqlDialect.SqlServer: SqlDialect = new SqlServerDialect(); break; } return(SqlDialect); }
public void OpenQuote() { var dialect = new OracleDialect(); Assert.Equal('"', dialect.OpenQuote); }
public void ParameterPrefix() { var dialect = new OracleDialect(); Assert.Equal(':', dialect.ParameterPrefix); }
public void SupportsMultipleStatements() { var dialect = new OracleDialect(); Assert.False(dialect.SupportsMultipleStatements); }
public void Setup() { Dialect = new OracleDialect(); }
public OracleDialectDataTests() { _dialect = new OracleDialect(); }
public void ToSQL_Oracle_001() { var dialect = new OracleDialect(); var target = new SQLinqCollection(); target.Add(new SQLinq<ICar>(dialect)); var actual = (SQLinqCollectionResult)target.ToSQL(); Assert.AreEqual(1, actual.Queries.Count); Assert.AreEqual("SELECT * FROM ICar", actual.Queries[0]); }
/// <summary> /// 活动Dapper扩展对象的实例 /// </summary> /// <param name="dbType">DB类型,默认SqlServer</param> /// <param name="ormMapperAssemblyList">ORM映射的程序集</param> /// <returns></returns> public static IDapperImplementor Instance(DataBaseType dbType = DefaultDBType, List <string> ormMapperAssemblyList = null) { IDapperImplementor instance; if (!_instanceList.TryGetValue(dbType, out instance)) { ISqlDialect sqlDialect; switch (dbType) { case DataBaseType.SqlServer: sqlDialect = new SqlServerDialect(); break; case DataBaseType.Oracle: sqlDialect = new OracleDialect(); break; case DataBaseType.MySql: sqlDialect = new MySqlDialect(); break; default: sqlDialect = new SqlServerDialect(); break; } List <Assembly> assemblyList = new List <Assembly>(); if (ormMapperAssemblyList != null) { foreach (var item in ormMapperAssemblyList) { assemblyList.Add(Assembly.Load(item)); } } else { if (!string.IsNullOrEmpty(ormMapperAssemblyStr)) { foreach (var item in ormMapperAssemblyStr.Split(';')) { if (!string.IsNullOrEmpty(item)) { assemblyList.Add(Assembly.Load(item)); } } } } IDapperExtensionConfiguration iDapperExtensionsConfiguration = new DapperExtensionConfiguration( typeof(AutoClassMapper <>), assemblyList, sqlDialect ); instance = InstanceFactory(iDapperExtensionsConfiguration, dbType); _instanceList[dbType] = instance; } if (!IsEnabledMultipleDBType) { if (null == _DapperImplementor) { _DapperImplementor = instance; } } else { if (null == _DapperImplementor_MultipleDBType || _DapperImplementor_MultipleDBType.DbType != dbType) { _DapperImplementor_MultipleDBType = instance; } } return(instance); }
public static void QuoteName_GivenEmptyString_ThrowsArgumentNullException() { var dialect = new OracleDialect(); Assert.That(() => dialect.QuoteName(string.Empty), Throws.ArgumentNullException); }
public OracleDialectSchemaTests() { _dialect = new OracleDialect(); }
public static void QuoteName_GivenWhiteSpace_ThrowsArgumentNullException() { var dialect = new OracleDialect(); Assert.That(() => dialect.QuoteName(" "), Throws.ArgumentNullException); }
public void CloseQuote() { var dialect = new OracleDialect(); Assert.Equal('"', dialect.CloseQuote); }
public void ToSQL_Oracle_002() { var dialect = new OracleDialect(); var target = new SQLinqCollection(); target.Add(new SQLinq<ICar>(dialect).Where(d => d.WheelDiameter == 21)); target.Add(new SQLinq<ICar>(dialect).Where(d => d.WheelDiameter == 14)); var actual = (SQLinqCollectionResult)target.ToSQL(); Assert.AreEqual(2, actual.Queries.Count); Assert.AreEqual("SELECT * FROM ICar WHERE WheelDiameter = :sqlinq_1", actual.Queries[0]); Assert.AreEqual("SELECT * FROM ICar WHERE WheelDiameter = :sqlinq_2", actual.Queries[1]); Assert.AreEqual(2, actual.Parameters.Count); Assert.AreEqual(21, actual.Parameters[":sqlinq_1"]); Assert.AreEqual(14, actual.Parameters[":sqlinq_2"]); }
public void SetUp() { _dialect = new OracleDialect(); }
public OrcaleCompiler() { Dialect = new OracleDialect(); Resolver = new OracleExpressionResolver(Dialect); }
public static void QuoteIdentifier_GivenNullOrWhiteSpaceIdentifier_ThrowsArgumentNullException(string identifier) { var dialect = new OracleDialect(); Assert.That(() => dialect.QuoteIdentifier(identifier), Throws.ArgumentNullException); }