From 505af2be16b39ef2101f291d3a85195777d651ac Mon Sep 17 00:00:00 2001 From: Vincent DARON Date: Tue, 26 Jul 2022 17:59:30 +0200 Subject: [PATCH 01/14] Ensure we are returning column in correct order in PostgreSQL, MySQL and SQLServer --- src/SimpleStack.Orm.MySQL/MySqlDialectProvider.cs | 2 +- .../MySqlConnectorDialectProvider.cs | 2 +- src/SimpleStack.Orm.PostgreSQL/PostgreSQLDialectProvider.cs | 2 ++ .../SqlServerOrmLiteDialectProvider.cs | 3 ++- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/SimpleStack.Orm.MySQL/MySqlDialectProvider.cs b/src/SimpleStack.Orm.MySQL/MySqlDialectProvider.cs index 85f7ca3..f80f32f 100644 --- a/src/SimpleStack.Orm.MySQL/MySqlDialectProvider.cs +++ b/src/SimpleStack.Orm.MySQL/MySqlDialectProvider.cs @@ -108,7 +108,7 @@ public override IEnumerable GetTableColumnDefinitions(IDbConn FROM INFORMATION_SCHEMA.STATISTICS WHERE INDEX_NAME NOT IN (SELECT INDEX_NAME FROM INFORMATION_SCHEMA.STATISTICS WHERE SEQ_IN_INDEX = 2 AND "+ whereClause + ") AND "+whereClause; - var columnQuery = "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE " + whereClause; + var columnQuery = "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE " + whereClause + " ORDER BY ordinal_position"; var indexedColumns = connection.Query(indexQuery, new {TableName = tableName, SchemaName = schemaName}) .ToDictionary(x => (string)x.COLUMN_NAME, x => (bool) (x.NON_UNIQUE == 0)); diff --git a/src/SimpleStack.Orm.MySQLConnector/MySqlConnectorDialectProvider.cs b/src/SimpleStack.Orm.MySQLConnector/MySqlConnectorDialectProvider.cs index 60cf733..6ce7703 100644 --- a/src/SimpleStack.Orm.MySQLConnector/MySqlConnectorDialectProvider.cs +++ b/src/SimpleStack.Orm.MySQLConnector/MySqlConnectorDialectProvider.cs @@ -110,7 +110,7 @@ public override IEnumerable GetTableColumnDefinitions(IDbConn FROM INFORMATION_SCHEMA.STATISTICS WHERE INDEX_NAME NOT IN (SELECT INDEX_NAME FROM INFORMATION_SCHEMA.STATISTICS WHERE SEQ_IN_INDEX = 2 AND "+ whereClause + ") AND "+whereClause; - var columnQuery = "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE " + whereClause; + var columnQuery = "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE " + whereClause + " ORDER BY ordinal_position"; var indexedColumns = connection.Query(indexQuery, new {TableName = tableName, SchemaName = schemaName}) .ToDictionary(x => (string)x.COLUMN_NAME, x => (bool) (x.NON_UNIQUE == 0)); diff --git a/src/SimpleStack.Orm.PostgreSQL/PostgreSQLDialectProvider.cs b/src/SimpleStack.Orm.PostgreSQL/PostgreSQLDialectProvider.cs index e3e5255..3c4d17c 100644 --- a/src/SimpleStack.Orm.PostgreSQL/PostgreSQLDialectProvider.cs +++ b/src/SimpleStack.Orm.PostgreSQL/PostgreSQLDialectProvider.cs @@ -180,6 +180,8 @@ public override IEnumerable GetTableColumnDefinitions(IDbConn sqlQuery += " AND table_schema = @SchemaName"; } + sqlQuery += " ORDER BY ordinal_position"; + var table = string.IsNullOrEmpty(schemaName) ? tableName : $"{schemaName}.{tableName}"; var pks = connection.Query($@"SELECT a.attname diff --git a/src/SimpleStack.Orm.SQLServer/SqlServerOrmLiteDialectProvider.cs b/src/SimpleStack.Orm.SQLServer/SqlServerOrmLiteDialectProvider.cs index c901a06..36d0e58 100644 --- a/src/SimpleStack.Orm.SQLServer/SqlServerOrmLiteDialectProvider.cs +++ b/src/SimpleStack.Orm.SQLServer/SqlServerOrmLiteDialectProvider.cs @@ -252,7 +252,8 @@ FROM sys.columns c LEFT JOIN sys.computed_columns cl ON cl.column_id = c.column_id AND c.object_id = cl.object_id LEFT JOIN sys.default_constraints dc ON dc.object_id = c.default_object_id INNER JOIN sys.types t ON t.user_type_id = c.user_type_id - where c.object_id = OBJECT_ID(@TableName);"; + where c.object_id = OBJECT_ID(@TableName) + order by c.column_id;"; string uniqueQuery = @"SELECT COL_NAME(ic.object_id,ic.column_id) AS COLUMN_NAME , is_unique IS_UNIQUE, is_primary_key IS_PRIMARYKEY FROM sys.indexes AS i From 587f077e8816c873850a6f320613c084fb0a6631 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 22 Jun 2022 18:15:50 +0000 Subject: [PATCH 02/14] Bump Newtonsoft.Json from 9.0.1 to 13.0.1 in /test/SimpleStack.Orm.Tests Bumps [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json) from 9.0.1 to 13.0.1. - [Release notes](https://github.com/JamesNK/Newtonsoft.Json/releases) - [Commits](https://github.com/JamesNK/Newtonsoft.Json/compare/9.0.1...13.0.1) --- updated-dependencies: - dependency-name: Newtonsoft.Json dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- test/SimpleStack.Orm.Tests/packages.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/SimpleStack.Orm.Tests/packages.config b/test/SimpleStack.Orm.Tests/packages.config index bf9add3..dc0f92f 100644 --- a/test/SimpleStack.Orm.Tests/packages.config +++ b/test/SimpleStack.Orm.Tests/packages.config @@ -2,7 +2,7 @@ - + From c2d92f7ef099d3339b4a099f8d1a9da1c78c2c48 Mon Sep 17 00:00:00 2001 From: Vincent DARON Date: Wed, 27 Jul 2022 18:23:31 +0200 Subject: [PATCH 03/14] Add CancellationTokens --- .../MySqlDialectProvider.cs | 5 +- .../MySqlConnectorDialectProvider.cs | 5 +- .../SqlServerOrmLiteDialectProvider.cs | 7 +- src/SimpleStack.Orm/DialectProviderBase.cs | 24 +-- src/SimpleStack.Orm/IDialectProvider.cs | 13 +- src/SimpleStack.Orm/OrmConnectionAsync.cs | 170 +++++++++--------- 6 files changed, 114 insertions(+), 110 deletions(-) diff --git a/src/SimpleStack.Orm.MySQL/MySqlDialectProvider.cs b/src/SimpleStack.Orm.MySQL/MySqlDialectProvider.cs index f80f32f..b0ac746 100644 --- a/src/SimpleStack.Orm.MySQL/MySqlDialectProvider.cs +++ b/src/SimpleStack.Orm.MySQL/MySqlDialectProvider.cs @@ -4,6 +4,7 @@ using System.Data.Common; using System.Linq; using System.Text; +using System.Threading; using Dapper; using MySql.Data.MySqlClient; using SimpleStack.Orm.Expressions.Statements; @@ -192,7 +193,7 @@ protected virtual DbType GetDbType(string dataType, int? length, string columnTy } } - public override CommandDefinition ToInsertStatement(InsertStatement insertStatement, CommandFlags flags) + public override CommandDefinition ToInsertStatement(InsertStatement insertStatement, CommandFlags flags, CancellationToken cancellationToken = new CancellationToken()) { var query = new StringBuilder("INSERT INTO "); query.Append(insertStatement.TableName); @@ -212,7 +213,7 @@ public override CommandDefinition ToInsertStatement(InsertStatement insertStatem query.Append(insertStatement.HasIdentity ? SelectIdentitySql : "SELECT 0"); - return new CommandDefinition(query.ToString(), insertStatement.Parameters, flags: flags); + return new CommandDefinition(query.ToString(), insertStatement.Parameters, flags: flags, cancellationToken: cancellationToken); } } } \ No newline at end of file diff --git a/src/SimpleStack.Orm.MySQLConnector/MySqlConnectorDialectProvider.cs b/src/SimpleStack.Orm.MySQLConnector/MySqlConnectorDialectProvider.cs index 6ce7703..bafb7f9 100644 --- a/src/SimpleStack.Orm.MySQLConnector/MySqlConnectorDialectProvider.cs +++ b/src/SimpleStack.Orm.MySQLConnector/MySqlConnectorDialectProvider.cs @@ -4,6 +4,7 @@ using System.Data.Common; using System.Linq; using System.Text; +using System.Threading; using Dapper; using MySqlConnector; using SimpleStack.Orm.Expressions.Statements; @@ -195,7 +196,7 @@ protected virtual DbType GetDbType(string dataType, int? length, string columnTy } } - public override CommandDefinition ToInsertStatement(InsertStatement insertStatement, CommandFlags flags) + public override CommandDefinition ToInsertStatement(InsertStatement insertStatement, CommandFlags flags, CancellationToken cancellationToken = new CancellationToken()) { var query = new StringBuilder("INSERT INTO "); query.Append(insertStatement.TableName); @@ -215,7 +216,7 @@ public override CommandDefinition ToInsertStatement(InsertStatement insertStatem query.Append(insertStatement.HasIdentity ? SelectIdentitySql : "SELECT 0"); - return new CommandDefinition(query.ToString(), insertStatement.Parameters, flags: flags); + return new CommandDefinition(query.ToString(), insertStatement.Parameters, flags: flags, cancellationToken: cancellationToken); } } } \ No newline at end of file diff --git a/src/SimpleStack.Orm.SQLServer/SqlServerOrmLiteDialectProvider.cs b/src/SimpleStack.Orm.SQLServer/SqlServerOrmLiteDialectProvider.cs index 36d0e58..eda7c2c 100644 --- a/src/SimpleStack.Orm.SQLServer/SqlServerOrmLiteDialectProvider.cs +++ b/src/SimpleStack.Orm.SQLServer/SqlServerOrmLiteDialectProvider.cs @@ -5,6 +5,7 @@ using System.IO; using System.Linq; using System.Text; +using System.Threading; using Dapper; using Microsoft.Data.SqlClient; using SimpleStack.Orm.Expressions.Statements; @@ -170,11 +171,11 @@ public override string ToAlterColumnStatement(Type modelType, FieldDefinition fi column); } - public override CommandDefinition ToSelectStatement(SelectStatement statement, CommandFlags flags) + public override CommandDefinition ToSelectStatement(SelectStatement statement, CommandFlags flags, CancellationToken cancellationToken = new CancellationToken()) { if (statement.Offset == null && (statement.MaxRows == null || statement.MaxRows == int.MaxValue)) { - return base.ToSelectStatement(statement, flags); + return base.ToSelectStatement(statement, flags, cancellationToken); } //Ensure we have an OrderBy clause, this is required by SQLServer paging (and makes more sense anyway) @@ -184,7 +185,7 @@ public override CommandDefinition ToSelectStatement(SelectStatement statement, C statement.OrderByExpression.Append(1); } - return base.ToSelectStatement(statement, flags); + return base.ToSelectStatement(statement, flags, cancellationToken); } public override string GetLimitExpression(int? skip, int? rows) diff --git a/src/SimpleStack.Orm/DialectProviderBase.cs b/src/SimpleStack.Orm/DialectProviderBase.cs index 4dd088e..a6f4479 100644 --- a/src/SimpleStack.Orm/DialectProviderBase.cs +++ b/src/SimpleStack.Orm/DialectProviderBase.cs @@ -16,6 +16,7 @@ using System.Linq; using System.Linq.Expressions; using System.Text; +using System.Threading; using System.Threading.Tasks; using Dapper; using SimpleStack.Orm.Attributes; @@ -103,7 +104,7 @@ public virtual string GetQuotedColumnName(string columnName) } /// - public virtual CommandDefinition ToSelectStatement(SelectStatement statement, CommandFlags flags) + public virtual CommandDefinition ToSelectStatement(SelectStatement statement, CommandFlags flags, CancellationToken cancellationToken = new CancellationToken()) { var sql = new StringBuilder("SELECT "); @@ -149,10 +150,10 @@ public virtual CommandDefinition ToSelectStatement(SelectStatement statement, Co } - return new CommandDefinition(sql.ToString(), statement.Parameters, flags: flags); + return new CommandDefinition(sql.ToString(), statement.Parameters, flags: flags, cancellationToken:cancellationToken); } - public virtual CommandDefinition ToCountStatement(CountStatement statement, CommandFlags flags) + public virtual CommandDefinition ToCountStatement(CountStatement statement, CommandFlags flags, CancellationToken cancellationToken = new CancellationToken()) { var sql = new StringBuilder("SELECT COUNT("); @@ -183,10 +184,10 @@ public virtual CommandDefinition ToCountStatement(CountStatement statement, Comm sql.Append(statement.HavingExpression); } - return new CommandDefinition(sql.ToString(), statement.Parameters, flags: flags); + return new CommandDefinition(sql.ToString(), statement.Parameters, flags: flags, cancellationToken:cancellationToken); } - public virtual CommandDefinition ToDeleteStatement(DeleteStatement statement) + public virtual CommandDefinition ToDeleteStatement(DeleteStatement statement, CancellationToken cancellationToken = new CancellationToken()) { var query = new StringBuilder("DELETE FROM "); query.Append(statement.TableName); @@ -196,10 +197,10 @@ public virtual CommandDefinition ToDeleteStatement(DeleteStatement statement) query.Append(statement.WhereExpression); } - return new CommandDefinition(query.ToString(), statement.Parameters); + return new CommandDefinition(query.ToString(), statement.Parameters, cancellationToken:cancellationToken); } - public virtual CommandDefinition ToInsertStatement(InsertStatement insertStatement, CommandFlags flags) + public virtual CommandDefinition ToInsertStatement(InsertStatement insertStatement, CommandFlags flags, CancellationToken cancellationToken = new CancellationToken()) { var query = new StringBuilder("INSERT INTO "); query.Append(insertStatement.TableName); @@ -218,11 +219,10 @@ public virtual CommandDefinition ToInsertStatement(InsertStatement insertStateme query.Append(insertStatement.HasIdentity ? SelectIdentitySql : "SELECT 0"); - return new CommandDefinition(query.ToString(), insertStatement.Parameters, flags: flags); + return new CommandDefinition(query.ToString(), insertStatement.Parameters, flags: flags, cancellationToken:cancellationToken); } - - public virtual CommandDefinition ToUpdateStatement(UpdateStatement statement, CommandFlags flags) + public virtual CommandDefinition ToUpdateStatement(UpdateStatement statement, CommandFlags flags, CancellationToken cancellationToken = new CancellationToken()) { var query = new StringBuilder("UPDATE "); query.Append(statement.TableName); @@ -248,7 +248,7 @@ public virtual CommandDefinition ToUpdateStatement(UpdateStatement statement, Co query.Append(statement.WhereExpression); } - return new CommandDefinition(query.ToString(), statement.Parameters, flags: flags); + return new CommandDefinition(query.ToString(), statement.Parameters, flags: flags, cancellationToken:cancellationToken); } /// Converts a tableType to a create table statement. @@ -347,7 +347,7 @@ public virtual List ToCreateIndexStatements(ModelDefinition modelDef) /// The database. /// Name of the table. /// true if it succeeds, false if it fails. - public virtual bool DoesTableExist(IDbConnection connection, string tableName, string schemaName = null) + public virtual bool DoesTableExist(IDbConnection connection, string tableName, string schemaName) { return false; } diff --git a/src/SimpleStack.Orm/IDialectProvider.cs b/src/SimpleStack.Orm/IDialectProvider.cs index f4097a0..9e0e6b3 100644 --- a/src/SimpleStack.Orm/IDialectProvider.cs +++ b/src/SimpleStack.Orm/IDialectProvider.cs @@ -13,6 +13,7 @@ using System.Collections.Generic; using System.Data; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; using Dapper; using SimpleStack.Orm.Expressions.Statements; @@ -73,15 +74,15 @@ public interface IDialectProvider string GetQuotedColumnName(string columnName); - CommandDefinition ToInsertStatement(InsertStatement insertStatement, CommandFlags flags); + CommandDefinition ToInsertStatement(InsertStatement insertStatement, CommandFlags flags, CancellationToken cancellationToken = new CancellationToken()); - CommandDefinition ToSelectStatement(SelectStatement statement, CommandFlags flags); + CommandDefinition ToSelectStatement(SelectStatement statement, CommandFlags flags, CancellationToken cancellationToken = new CancellationToken()); - CommandDefinition ToUpdateStatement(UpdateStatement statement, CommandFlags flags); + CommandDefinition ToUpdateStatement(UpdateStatement statement, CommandFlags flags, CancellationToken cancellationToken = new CancellationToken()); - CommandDefinition ToCountStatement(CountStatement statement, CommandFlags flags); + CommandDefinition ToCountStatement(CountStatement statement, CommandFlags flags, CancellationToken cancellationToken = new CancellationToken()); - CommandDefinition ToDeleteStatement(DeleteStatement deleteStatement); + CommandDefinition ToDeleteStatement(DeleteStatement deleteStatement, CancellationToken cancellationToken = new CancellationToken()); /// Converts a tableType to a create table statement. /// Model Definition. @@ -113,7 +114,7 @@ public interface IDialectProvider /// The database. /// Name of the table. /// true if it exists, false otherwise. - bool DoesTableExist(IDbConnection connection, string tableName, string schemaName = null); + bool DoesTableExist(IDbConnection connection, string tableName, string schemaName); /// Query if schema exist. /// The database. diff --git a/src/SimpleStack.Orm/OrmConnectionAsync.cs b/src/SimpleStack.Orm/OrmConnectionAsync.cs index 3d21b24..6980ab8 100644 --- a/src/SimpleStack.Orm/OrmConnectionAsync.cs +++ b/src/SimpleStack.Orm/OrmConnectionAsync.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; using Dapper; using SimpleStack.Orm.Attributes; @@ -20,9 +21,9 @@ public partial class OrmConnection /// the command flags /// IEnumerable of results as dynamix objects public Task> SelectAsync(string tableName, - Action selectStatement, CommandFlags flags = CommandFlags.Buffered) + Action selectStatement, CommandFlags flags = CommandFlags.Buffered, CancellationToken cancellationToken = new CancellationToken()) { - return SelectAsync(tableName, null, selectStatement, flags); + return SelectAsync(tableName, null, selectStatement, flags,cancellationToken); } /// @@ -34,13 +35,13 @@ public Task> SelectAsync(string tableName, /// the command flags /// IEnumerable of results as dynamix objects public Task> SelectAsync(string tableName, string schemaName, - Action selectStatement, CommandFlags flags = CommandFlags.Buffered) + Action selectStatement, CommandFlags flags = CommandFlags.Buffered, CancellationToken cancellationToken = new CancellationToken()) { var statement = new DynamicSelectStatement(DialectProvider); selectStatement(statement.From(tableName, schemaName)); - var cmd = DialectProvider.ToSelectStatement(statement.Statement, flags); + var cmd = DialectProvider.ToSelectStatement(statement.Statement, flags, cancellationToken); return this.QueryAsync(cmd.CommandText, cmd.Parameters, cmd.Transaction, cmd.CommandTimeout, cmd.CommandType); } @@ -53,11 +54,11 @@ public Task> SelectAsync(string tableName, string schemaNam /// /// public Task> SelectAsync(Expression> predicate, - CommandFlags flags = CommandFlags.Buffered) + CommandFlags flags = CommandFlags.Buffered, CancellationToken cancellationToken = new CancellationToken()) { var select = new TypedSelectStatement(DialectProvider); select.Where(predicate); - return this.QueryAsync(DialectProvider.ToSelectStatement(select.Statement, flags)); + return this.QueryAsync(DialectProvider.ToSelectStatement(select.Statement, flags,cancellationToken)); } /// @@ -68,11 +69,11 @@ public Task> SelectAsync(Expression> predicate, /// /// public Task> SelectAsync(Action> expression, - CommandFlags flags = CommandFlags.Buffered) + CommandFlags flags = CommandFlags.Buffered, CancellationToken cancellationToken = new CancellationToken()) { var select = new TypedSelectStatement(DialectProvider); expression(select); - return this.QueryAsync(DialectProvider.ToSelectStatement(select.Statement, flags)); + return this.QueryAsync(DialectProvider.ToSelectStatement(select.Statement, flags, cancellationToken)); } /// @@ -81,10 +82,10 @@ public Task> SelectAsync(Action> expre /// Command flags /// /// - public Task> SelectAsync(CommandFlags flags = CommandFlags.Buffered) + public Task> SelectAsync(CommandFlags flags = CommandFlags.Buffered, CancellationToken cancellationToken = new CancellationToken()) { return this.QueryAsync( - DialectProvider.ToSelectStatement(new TypedSelectStatement(DialectProvider).Statement, flags)); + DialectProvider.ToSelectStatement(new TypedSelectStatement(DialectProvider).Statement, flags, cancellationToken)); } /// @@ -163,12 +164,12 @@ public async Task FirstOrDefaultAsync(Action> expr /// The Type specifying the target table /// The Type of the result /// - public Task GetScalarAsync(Expression> field) + public Task GetScalarAsync(Expression> field, CancellationToken cancellationToken = new CancellationToken()) { var select = new TypedSelectStatement(DialectProvider); select.Select(field); return this.ExecuteScalarAsync( - DialectProvider.ToSelectStatement(select.Statement, CommandFlags.None)); + DialectProvider.ToSelectStatement(select.Statement, CommandFlags.None, cancellationToken)); } /// @@ -183,13 +184,13 @@ public Task GetScalarAsync(Expression> field) /// The type of the result /// public Task GetScalarAsync(Expression> field, - Expression> predicate) + Expression> predicate, CancellationToken cancellationToken = new CancellationToken()) { var select = new TypedSelectStatement(DialectProvider); select.Select(field); select.Where(predicate); return this.ExecuteScalarAsync( - DialectProvider.ToSelectStatement(select.Statement, CommandFlags.None)); + DialectProvider.ToSelectStatement(select.Statement, CommandFlags.None, cancellationToken)); } /// @@ -198,13 +199,13 @@ public Task GetScalarAsync(Expression> field, /// The Select Statement action /// /// - public Task CountAsync(Action> expression) + public Task CountAsync(Action> expression, CancellationToken cancellationToken = new CancellationToken()) { var select = new TypedSelectStatement(DialectProvider); expression(select); return this.ExecuteScalarAsync( - DialectProvider.ToCountStatement(select.Statement, CommandFlags.None)); + DialectProvider.ToCountStatement(select.Statement, CommandFlags.None, cancellationToken)); } /// @@ -213,9 +214,9 @@ public Task CountAsync(Action> expression) /// the where clause expression /// /// - public Task CountAsync(Expression> expression) + public Task CountAsync(Expression> expression, CancellationToken cancellationToken = new CancellationToken()) { - return CountAsync(e => e.Where(expression)); + return CountAsync(e => e.Where(expression), cancellationToken); } /// @@ -224,9 +225,9 @@ public Task CountAsync(Expression> expression) /// The table name /// The Select Statement action /// - public Task CountAsync(string tableName, Action expression) + public Task CountAsync(string tableName, Action expression, CancellationToken cancellationToken = new CancellationToken()) { - return CountAsync(tableName, null, expression); + return CountAsync(tableName, null, expression, cancellationToken); } /// @@ -237,13 +238,13 @@ public Task CountAsync(string tableName, Action ex /// The Select Statement action /// public Task CountAsync(string tableName, string schemaName, - Action expression) + Action expression, CancellationToken cancellationToken = new CancellationToken()) { var select = new DynamicSelectStatement(DialectProvider); expression(select.From(tableName, schemaName)); return this.ExecuteScalarAsync( - DialectProvider.ToCountStatement(select.Statement, CommandFlags.None)); + DialectProvider.ToCountStatement(select.Statement, CommandFlags.None, cancellationToken)); } /// @@ -251,9 +252,9 @@ public Task CountAsync(string tableName, string schemaName, /// /// /// - public Task CountAsync() + public Task CountAsync(CancellationToken cancellationToken = new CancellationToken()) { - return CountAsync(e => { }); + return CountAsync(e => { }, cancellationToken); } /// @@ -262,11 +263,11 @@ public Task CountAsync() /// the object to update /// /// - public Task UpdateAsync(T model) + public Task UpdateAsync(T model, CancellationToken cancellationToken = new CancellationToken()) { var s = new TypedUpdateStatement(DialectProvider); s.ValuesOnly(model); - var cmd = DialectProvider.ToUpdateStatement(s.Statement, CommandFlags.None); + var cmd = DialectProvider.ToUpdateStatement(s.Statement, CommandFlags.None, cancellationToken); return this.ExecuteScalarAsync(cmd); } @@ -278,11 +279,11 @@ public Task UpdateAsync(T model) /// /// /// - public Task UpdateAsync(T model, Expression> onlyFields) + public Task UpdateAsync(T model, Expression> onlyFields, CancellationToken cancellationToken = new CancellationToken()) { var s = new TypedUpdateStatement(DialectProvider); s.ValuesOnly(model, onlyFields); - var cmd = DialectProvider.ToUpdateStatement(s.Statement, CommandFlags.None); + var cmd = DialectProvider.ToUpdateStatement(s.Statement, CommandFlags.None, cancellationToken); return this.ExecuteScalarAsync(cmd); } @@ -296,7 +297,7 @@ public Task UpdateAsync(T model, Expression> onlyFie /// /// public Task UpdateAllAsync(object obj, Expression> onlyField, - Expression> where = null) + Expression> where = null, CancellationToken cancellationToken = new CancellationToken()) { var s = new TypedUpdateStatement(DialectProvider); if (where != null) @@ -306,7 +307,7 @@ public Task UpdateAllAsync(object obj, Expression> o s.Values(obj, onlyField); - var cmd = DialectProvider.ToUpdateStatement(s.Statement, CommandFlags.None); + var cmd = DialectProvider.ToUpdateStatement(s.Statement, CommandFlags.None, cancellationToken); return this.ExecuteScalarAsync(cmd); } @@ -317,9 +318,9 @@ public Task UpdateAllAsync(object obj, Expression> o /// /// /// - public Task InsertAsync(T obj) + public Task InsertAsync(T obj, CancellationToken cancellationToken = new CancellationToken()) { - return InsertAsync(obj); + return InsertAsync(obj, cancellationToken); } /// @@ -329,13 +330,13 @@ public Task InsertAsync(T obj) /// /// /// - public Task InsertAsync(T obj) + public Task InsertAsync(T obj, CancellationToken cancellationToken = new CancellationToken()) { try { var insertStatement = new TypedInsertStatement(DialectProvider); insertStatement.Values(obj, Array.Empty()); - var commandDefinition = DialectProvider.ToInsertStatement(insertStatement.Statement, CommandFlags.None); + var commandDefinition = DialectProvider.ToInsertStatement(insertStatement.Statement, CommandFlags.None, cancellationToken); return this.ExecuteScalarAsync(commandDefinition); } catch (Exception e) @@ -350,9 +351,9 @@ public Task InsertAsync(T obj) /// The objects to insert /// /// - public Task> InsertAsync(IEnumerable objs) + public Task> InsertAsync(IEnumerable objs, CancellationToken cancellationToken = new CancellationToken()) { - return InsertAsync(objs); + return InsertAsync(objs, cancellationToken); } /// @@ -361,7 +362,7 @@ public Task> InsertAsync(IEnumerable objs) /// The objects to insert /// /// - public async Task> InsertAsync(IEnumerable objs) + public async Task> InsertAsync(IEnumerable objs, CancellationToken cancellationToken = new CancellationToken()) { if (objs == null) { @@ -376,7 +377,7 @@ public async Task> InsertAsync(IEnumerable objs) insertStatement.Values(t, new List()); result.Add(await this.ExecuteScalarAsync( - DialectProvider.ToInsertStatement(insertStatement.Statement, CommandFlags.None)).ConfigureAwait(false)); + DialectProvider.ToInsertStatement(insertStatement.Statement, CommandFlags.None, cancellationToken)).ConfigureAwait(false)); } return result; @@ -390,14 +391,14 @@ public async Task> InsertAsync(IEnumerable objs) /// /// /// - public Task InsertOnlyAsync(T obj, Expression> onlyFields) + public Task InsertOnlyAsync(T obj, Expression> onlyFields, CancellationToken cancellationToken = new CancellationToken()) where T : new() { var insertStatement = new TypedInsertStatement(DialectProvider); insertStatement.Values(obj, onlyFields); return this.ExecuteScalarAsync( - DialectProvider.ToInsertStatement(insertStatement.Statement, CommandFlags.None)); + DialectProvider.ToInsertStatement(insertStatement.Statement, CommandFlags.None, cancellationToken)); } /// @@ -406,9 +407,9 @@ public Task InsertOnlyAsync(T obj, Expression> onlyF /// The where clause /// /// - public Task DeleteAllAsync(Expression> where = null) + public Task DeleteAllAsync(Expression> where = null, CancellationToken cancellationToken = new CancellationToken()) { - return DeleteAllAsync(x => { x.Where(where); }); + return DeleteAllAsync(x => { x.Where(where); }, cancellationToken); } /// @@ -417,11 +418,11 @@ public Task DeleteAllAsync(Expression> where = null) /// the where statement action /// /// - public Task DeleteAllAsync(Action> where) + public Task DeleteAllAsync(Action> where, CancellationToken cancellationToken = new CancellationToken()) { var s = new TypedDeleteStatement(DialectProvider); where(s); - return this.ExecuteScalarAsync(DialectProvider.ToDeleteStatement(s.Statement)); + return this.ExecuteScalarAsync(DialectProvider.ToDeleteStatement(s.Statement, cancellationToken)); } @@ -431,12 +432,12 @@ public Task DeleteAllAsync(Action> where) /// The object to delete /// /// - public Task DeleteAsync(T obj) + public Task DeleteAsync(T obj, CancellationToken cancellationToken = new CancellationToken()) { var s = new TypedDeleteStatement(DialectProvider); s.AddPrimaryKeyWhereCondition(obj); - - return this.ExecuteScalarAsync(DialectProvider.ToDeleteStatement(s.Statement)); + + return this.ExecuteScalarAsync(DialectProvider.ToDeleteStatement(s.Statement, cancellationToken: cancellationToken)); } /// @@ -446,15 +447,15 @@ public Task DeleteAsync(T obj) /// /// /// If the table already exists and cannot be dropped - public async Task CreateTableAsync(bool dropIfExists) + public async Task CreateTableAsync(bool dropIfExists, CancellationToken cancellationToken = new CancellationToken()) { - if (!dropIfExists && await TableExistsAsync().ConfigureAwait(false)) + if (!dropIfExists && await TableExistsAsync(cancellationToken).ConfigureAwait(false)) { throw new OrmException("Table already exists"); } var tableType = typeof(T); - await CreateTableAsync(dropIfExists, tableType).ConfigureAwait(false); + await CreateTableAsync(dropIfExists, tableType, cancellationToken).ConfigureAwait(false); } /// @@ -464,14 +465,14 @@ public async Task CreateTableAsync(bool dropIfExists) /// True to drop the table if it already exists /// /// - public async Task CreateTableAsync(Type tableType, bool dropIfExists) + public async Task CreateTableAsync(Type tableType, bool dropIfExists, CancellationToken cancellationToken = new CancellationToken()) { - if (!dropIfExists && await TableExistsAsync(tableType)) + if (!dropIfExists && await TableExistsAsync(tableType, cancellationToken)) { throw new OrmException("Table already exists"); } - await CreateTableAsync(dropIfExists, tableType); + await CreateTableAsync(dropIfExists, tableType, cancellationToken); } /// @@ -479,10 +480,10 @@ public async Task CreateTableAsync(Type tableType, bool dropIfExists) /// /// /// - public Task CreateTableIfNotExistsAsync() + public Task CreateTableIfNotExistsAsync(CancellationToken cancellationToken = new CancellationToken()) { var tableType = typeof(T); - return CreateTableAsync(false, tableType); + return CreateTableAsync(false, tableType, cancellationToken); } /// @@ -490,9 +491,9 @@ public Task CreateTableIfNotExistsAsync() /// /// /// - public async Task CreateTableIfNotExistsAsync(Type tableType) + public async Task CreateTableIfNotExistsAsync(Type tableType, CancellationToken cancellationToken = new CancellationToken()) { - await CreateTableAsync(false, tableType); + await CreateTableAsync(false, tableType, cancellationToken); } /// @@ -500,9 +501,10 @@ public async Task CreateTableIfNotExistsAsync(Type tableType) /// /// Name of the schema /// - public Task CreateSchemaIfNotExistsAsync(string schemaName) + public Task CreateSchemaIfNotExistsAsync(string schemaName, CancellationToken cancellationToken = new CancellationToken()) { - return this.ExecuteScalarAsync(DialectProvider.GetCreateSchemaStatement(schemaName, true)); + return this.ExecuteScalarAsync(new CommandDefinition(DialectProvider.GetCreateSchemaStatement(schemaName, true), + cancellationToken: cancellationToken)); } /// @@ -510,9 +512,10 @@ public Task CreateSchemaIfNotExistsAsync(string schemaName) /// /// /// - public Task CreateSchemaAsync(string schemaName) + public Task CreateSchemaAsync(string schemaName, CancellationToken cancellationToken = new CancellationToken()) { - return this.ExecuteScalarAsync(DialectProvider.GetCreateSchemaStatement(schemaName, false)); + return this.ExecuteScalarAsync(new CommandDefinition(DialectProvider.GetCreateSchemaStatement(schemaName, false), + cancellationToken: cancellationToken)); } /// @@ -520,11 +523,10 @@ public Task CreateSchemaAsync(string schemaName) /// /// /// - public Task TableExistsAsync() + public Task TableExistsAsync(CancellationToken cancellationToken = new CancellationToken()) { var tableModelDef = typeof(T).GetModelDefinition(); - return Task.Run(() => - DialectProvider.DoesTableExist(this, + return Task.FromResult(DialectProvider.DoesTableExist(this, tableModelDef.Alias ?? tableModelDef.ModelName, tableModelDef.Schema)); } @@ -534,11 +536,10 @@ public Task TableExistsAsync() /// /// /// - public async Task TableExistsAsync(Type tableType) + public Task TableExistsAsync(Type tableType, CancellationToken cancellationToken = new CancellationToken()) { var tableModelDef = tableType.GetModelDefinition(); - return await Task.Run(() => - DialectProvider.DoesTableExist(this, + return Task.FromResult(DialectProvider.DoesTableExist(this, tableModelDef.Alias ?? tableModelDef.ModelName, tableModelDef.Schema)); } @@ -549,10 +550,9 @@ public async Task TableExistsAsync(Type tableType) /// the table name /// the schema name /// - public Task TableExistsAsync(string tableName, string schema = null) + public Task TableExistsAsync(string tableName, string schema = null, CancellationToken cancellationToken = new CancellationToken()) { - return Task.Run(() => - DialectProvider.DoesTableExist(this, tableName, schema)); + return Task.FromResult(DialectProvider.DoesTableExist(this, tableName, schema)); } /// @@ -560,12 +560,12 @@ public Task TableExistsAsync(string tableName, string schema = null) /// /// /// True if table did exists and has been dropped - public async Task DropTableIfExistsAsync() + public async Task DropTableIfExistsAsync(CancellationToken cancellationToken = new CancellationToken()) { - if (await TableExistsAsync().ConfigureAwait(false)) + if (await TableExistsAsync(cancellationToken)) { var tableModelDef = typeof(T).GetModelDefinition(); - await DropTableAsync(tableModelDef).ConfigureAwait(false); + await DropTableAsync(tableModelDef, cancellationToken).ConfigureAwait(false); } return false; @@ -576,12 +576,12 @@ public async Task DropTableIfExistsAsync() /// /// /// True if table did exists and has been dropped - public async Task DropTableIfExistsAsync(Type tableType) + public async Task DropTableIfExistsAsync(Type tableType,CancellationToken cancellationToken = new CancellationToken()) { - if (await TableExistsAsync(tableType)) + if (await TableExistsAsync(tableType, cancellationToken)) { var tableModelDef = tableType.GetModelDefinition(); - await DropTableAsync(tableModelDef); + await DropTableAsync(tableModelDef, cancellationToken); } return false; @@ -611,7 +611,7 @@ public Task> GetTableColumnsAsync(string tableNam return Task.Run(() => DialectProvider.GetTableColumnDefinitions(DbConnection, tableName, schemaName)); } - private async Task CreateTableAsync(bool overwrite, Type modelType) + private async Task CreateTableAsync(bool overwrite, Type modelType, CancellationToken cancellationToken = new CancellationToken()) { var modelDef = modelType.GetModelDefinition(); @@ -621,18 +621,18 @@ private async Task CreateTableAsync(bool overwrite, Type modelType) if (overwrite && tableExists) { - await DropTableAsync(modelDef).ConfigureAwait(false); + await DropTableAsync(modelDef, cancellationToken).ConfigureAwait(false); tableExists = false; } if (!tableExists) { - await this.ExecuteAsync(dialectProvider.ToCreateTableStatement(modelDef)).ConfigureAwait(false); + await this.ExecuteAsync(dialectProvider.ToCreateTableStatement(modelDef), cancellationToken).ConfigureAwait(false); var sqlIndexes = dialectProvider.ToCreateIndexStatements(modelDef); foreach (var sqlIndex in sqlIndexes) { - await this.ExecuteAsync(sqlIndex).ConfigureAwait(false); + await this.ExecuteAsync(sqlIndex, cancellationToken).ConfigureAwait(false); } var sequenceList = dialectProvider.SequenceList(modelDef); @@ -643,7 +643,7 @@ private async Task CreateTableAsync(bool overwrite, Type modelType) if (dialectProvider.DoesSequenceExist(this, seq) == false) { var seqSql = dialectProvider.ToCreateSequenceStatement(modelDef, seq); - await this.ExecuteAsync(seqSql).ConfigureAwait(false); + await this.ExecuteAsync(seqSql, cancellationToken).ConfigureAwait(false); } } } @@ -652,21 +652,21 @@ private async Task CreateTableAsync(bool overwrite, Type modelType) var sequences = dialectProvider.ToCreateSequenceStatements(modelDef); foreach (var seq in sequences) { - await this.ExecuteAsync(seq).ConfigureAwait(false); + await this.ExecuteAsync(seq, cancellationToken).ConfigureAwait(false); } } } } - private async Task DropTableAsync(ModelDefinition modelDef) + private async Task DropTableAsync(ModelDefinition modelDef, CancellationToken cancellationToken = new CancellationToken()) { var dropTableFks = DialectProvider.GetDropForeignKeyConstraints(modelDef); if (!string.IsNullOrEmpty(dropTableFks)) { - await this.ExecuteAsync(dropTableFks).ConfigureAwait(false); + await this.ExecuteAsync(dropTableFks, cancellationToken).ConfigureAwait(false); } - await this.ExecuteAsync(DialectProvider.GetDropTableStatement(modelDef)).ConfigureAwait(false); + await this.ExecuteAsync(DialectProvider.GetDropTableStatement(modelDef), cancellationToken).ConfigureAwait(false); } } } \ No newline at end of file From c5645ef90e07bb4a9a1a5804c063d89bdfae2bcd Mon Sep 17 00:00:00 2001 From: Vincent DARON Date: Wed, 27 Jul 2022 22:09:14 +0200 Subject: [PATCH 04/14] Implement CancellationToken for table exist and Create Table --- .../MySqlDialectProvider.cs | 18 +---------- .../MySqlConnectorDialectProvider.cs | 16 ---------- .../PostgreSQLDialectProvider.cs | 30 ++++++++++-------- .../SqliteDialectProvider.cs | 22 ++++++------- .../SqlServerOrmLiteDialectProvider.cs | 17 ---------- .../SqliteDialectProvider.cs | 22 ++++++------- src/SimpleStack.Orm/DialectProviderBase.cs | 31 +++++++++---------- src/SimpleStack.Orm/IDialectProvider.cs | 16 ++-------- src/SimpleStack.Orm/OrmConnectionAsync.cs | 20 ++++++------ 9 files changed, 62 insertions(+), 130 deletions(-) diff --git a/src/SimpleStack.Orm.MySQL/MySqlDialectProvider.cs b/src/SimpleStack.Orm.MySQL/MySqlDialectProvider.cs index b0ac746..316d106 100644 --- a/src/SimpleStack.Orm.MySQL/MySqlDialectProvider.cs +++ b/src/SimpleStack.Orm.MySQL/MySqlDialectProvider.cs @@ -50,23 +50,7 @@ public override string GetQuotedName(string name) { return string.Format("`{0}`", name); } - - /// Query if 'dbCmd' does table exist. - /// The database command. - /// Name of the table. - /// true if it succeeds, false if it fails. - public override bool DoesTableExist(IDbConnection connection, string tableName, string schemaName = null) - { - //Same as SQL Server apparently? - var sql = $@"SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES - WHERE TABLE_NAME = '{tableName}' - AND TABLE_SCHEMA = '{schemaName ?? connection.Database}'"; - - var result = connection.ExecuteScalar(sql); - - return result > 0; - } - + public override string GetCreateSchemaStatement(string schema, bool ignoreIfExists) { return $"CREATE SCHEMA {(ignoreIfExists ? "IF NOT EXISTS" : string.Empty)} {schema}"; diff --git a/src/SimpleStack.Orm.MySQLConnector/MySqlConnectorDialectProvider.cs b/src/SimpleStack.Orm.MySQLConnector/MySqlConnectorDialectProvider.cs index bafb7f9..8cc0506 100644 --- a/src/SimpleStack.Orm.MySQLConnector/MySqlConnectorDialectProvider.cs +++ b/src/SimpleStack.Orm.MySQLConnector/MySqlConnectorDialectProvider.cs @@ -53,22 +53,6 @@ public override string GetQuotedName(string name) return string.Format("`{0}`", name); } - /// Query if 'dbCmd' does table exist. - /// The database command. - /// Name of the table. - /// true if it succeeds, false if it fails. - public override bool DoesTableExist(IDbConnection connection, string tableName, string schemaName = null) - { - //Same as SQL Server apparently? - var sql = $@"SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES - WHERE TABLE_NAME = '{tableName}' - AND TABLE_SCHEMA = '{schemaName ?? connection.Database}'"; - - var result = connection.ExecuteScalar(sql); - - return result > 0; - } - public override string GetCreateSchemaStatement(string schema, bool ignoreIfExists) { return $"CREATE SCHEMA {(ignoreIfExists ? "IF NOT EXISTS" : string.Empty)} {schema}"; diff --git a/src/SimpleStack.Orm.PostgreSQL/PostgreSQLDialectProvider.cs b/src/SimpleStack.Orm.PostgreSQL/PostgreSQLDialectProvider.cs index 3c4d17c..caf160b 100644 --- a/src/SimpleStack.Orm.PostgreSQL/PostgreSQLDialectProvider.cs +++ b/src/SimpleStack.Orm.PostgreSQL/PostgreSQLDialectProvider.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Linq.Expressions; using System.Text; +using System.Threading; using Dapper; using Npgsql; @@ -95,27 +96,30 @@ public override string GetColumnDefinition( return sql.ToString(); } - - /// Query if 'dbCmd' does table exist. - /// The database command. - /// Name of the table. - /// true if it succeeds, false if it fails. - public override bool DoesTableExist(IDbConnection connection, string tableName, string schemaName = null) + + public override CommandDefinition ToTableExistStatement(string tableName, string schemaName, + CancellationToken cancellationToken = new CancellationToken()) { - var query = @"SELECT COUNT(*) FROM pg_class + var sql = $@"SELECT COUNT(*) FROM pg_class LEFT JOIN pg_namespace n ON n.oid = pg_class.relnamespace - WHERE relname = :table AND nspname = "; + WHERE relname = {GetParameterName(0)}"; + var parameters = new Dictionary + { + {GetParameterName(0), tableName}, + }; + if (string.IsNullOrEmpty(schemaName)) - query += "current_schema()"; + { + sql += " AND nspname = current_schema()"; + } else { - query += $"'{NamingStrategy.GetTableName(schemaName)}'"; + sql += $" AND nspname = {GetParameterName(1)}"; + parameters.Add(GetParameterName(1),schemaName); } - var result = connection.ExecuteScalar(query, new {table = NamingStrategy.GetTableName(tableName)}); - - return result > 0; + return new CommandDefinition(sql, parameters, cancellationToken: cancellationToken); } // /// Gets quoted table name. diff --git a/src/SimpleStack.Orm.SDSQLite/SqliteDialectProvider.cs b/src/SimpleStack.Orm.SDSQLite/SqliteDialectProvider.cs index d9f2340..ebd57ce 100644 --- a/src/SimpleStack.Orm.SDSQLite/SqliteDialectProvider.cs +++ b/src/SimpleStack.Orm.SDSQLite/SqliteDialectProvider.cs @@ -4,6 +4,7 @@ using System.Data.Common; using System.Data.SQLite; using System.Text.RegularExpressions; +using System.Threading; using System.Threading.Tasks; using Dapper; @@ -42,21 +43,16 @@ public override string GetQuotedTableName(string tableName, string schemaName = ? $"{EscapeChar}{NamingStrategy.GetTableName(tableName)}{EscapeChar}" : $"{EscapeChar}{NamingStrategy.GetTableName(schemaName)}_{NamingStrategy.GetTableName(tableName)}{EscapeChar}"; } - - /// Query if 'dbCmd' does table exist. - /// The database command. - /// Name of the table. - /// true if it succeeds, false if it fails. - public override bool DoesTableExist(IDbConnection connection, string tableName, string schemaName = null) + + public override CommandDefinition ToTableExistStatement(string tableName, string schemaName, + CancellationToken cancellationToken = new CancellationToken()) { var name = string.IsNullOrEmpty(schemaName) ? tableName : $"{schemaName}_{tableName}"; - - var sql = string.Format("SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name = '{0}'" - , name); - - var result = connection.ExecuteScalar(sql); - - return result > 0; + + var sql = $"SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name = {GetParameterName(0)}"; + var parameters = new Dictionary {{GetParameterName(0), tableName}}; + + return new CommandDefinition(sql, parameters, cancellationToken: cancellationToken); } /// Gets column definition. diff --git a/src/SimpleStack.Orm.SQLServer/SqlServerOrmLiteDialectProvider.cs b/src/SimpleStack.Orm.SQLServer/SqlServerOrmLiteDialectProvider.cs index eda7c2c..048f767 100644 --- a/src/SimpleStack.Orm.SQLServer/SqlServerOrmLiteDialectProvider.cs +++ b/src/SimpleStack.Orm.SQLServer/SqlServerOrmLiteDialectProvider.cs @@ -52,24 +52,7 @@ public override DbConnection CreateIDbConnection(string connectionString) return new SqlConnection(connectionString); } - - /// Query if 'dbCmd' does table exist. - /// The database command. - /// Name of the table. - /// true if it succeeds, false if it fails. - public override bool DoesTableExist(IDbConnection connection, string tableName, string schemaName = null) - { - var sql = String.Format("SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '{0}'" - ,tableName); - - if (!string.IsNullOrEmpty(schemaName)) - sql += $" AND TABLE_SCHEMA = '{schemaName}'"; - var result = connection.ExecuteScalar(sql); - - return result > 0; - } - public override string GetCreateSchemaStatement(string schema, bool ignoreIfExists) { return ignoreIfExists ? diff --git a/src/SimpleStack.Orm.SQLite/SqliteDialectProvider.cs b/src/SimpleStack.Orm.SQLite/SqliteDialectProvider.cs index 1fbc1d8..90de811 100644 --- a/src/SimpleStack.Orm.SQLite/SqliteDialectProvider.cs +++ b/src/SimpleStack.Orm.SQLite/SqliteDialectProvider.cs @@ -3,6 +3,7 @@ using System.Data; using System.Data.Common; using System.Text.RegularExpressions; +using System.Threading; using System.Threading.Tasks; using Dapper; using Microsoft.Data.Sqlite; @@ -43,21 +44,16 @@ public override string GetQuotedTableName(string tableName, string schemaName = ? $"{EscapeChar}{NamingStrategy.GetTableName(tableName)}{EscapeChar}" : $"{EscapeChar}{NamingStrategy.GetTableName(schemaName)}_{NamingStrategy.GetTableName(tableName)}{EscapeChar}"; } - - /// Query if 'dbCmd' does table exist. - /// The database command. - /// Name of the table. - /// true if it succeeds, false if it fails. - public override bool DoesTableExist(IDbConnection connection, string tableName, string schemaName = null) + + public override CommandDefinition ToTableExistStatement(string tableName, string schemaName, + CancellationToken cancellationToken = new CancellationToken()) { var name = string.IsNullOrEmpty(schemaName) ? tableName : $"{schemaName}_{tableName}"; - - var sql = string.Format("SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name = '{0}'" - , name); - - var result = connection.ExecuteScalar(sql); - - return result > 0; + + var sql = $"SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name = {GetParameterName(0)}"; + var parameters = new Dictionary {{GetParameterName(0), tableName}}; + + return new CommandDefinition(sql, parameters, cancellationToken: cancellationToken); } /// Gets column definition. diff --git a/src/SimpleStack.Orm/DialectProviderBase.cs b/src/SimpleStack.Orm/DialectProviderBase.cs index a6f4479..cd13869 100644 --- a/src/SimpleStack.Orm/DialectProviderBase.cs +++ b/src/SimpleStack.Orm/DialectProviderBase.cs @@ -254,7 +254,7 @@ public virtual string GetQuotedColumnName(string columnName) /// Converts a tableType to a create table statement. /// Model Definition. /// tableType as a string. - public virtual string ToCreateTableStatement(ModelDefinition modelDef) + public virtual CommandDefinition ToCreateTableStatement(ModelDefinition modelDef, CancellationToken cancellationToken = new CancellationToken()) { var sbColumns = new StringBuilder(); var sbConstraints = new StringBuilder(); @@ -306,8 +306,8 @@ public virtual string ToCreateTableStatement(ModelDefinition modelDef) sbPrimaryKeys.Append(")"); } - return - $"CREATE TABLE {GetQuotedTableName(modelDef)} \n(\n {sbColumns}{sbPrimaryKeys}{sbConstraints} \n); \n"; + return new CommandDefinition($"CREATE TABLE {GetQuotedTableName(modelDef)} \n(\n {sbColumns}{sbPrimaryKeys}{sbConstraints} \n); \n", + cancellationToken:cancellationToken); } /// Converts a tableType to a create index statements. @@ -343,22 +343,19 @@ public virtual List ToCreateIndexStatements(ModelDefinition modelDef) return sqlIndexes; } - /// Query if 'dbCmd' does table exist. - /// The database. - /// Name of the table. - /// true if it succeeds, false if it fails. - public virtual bool DoesTableExist(IDbConnection connection, string tableName, string schemaName) + public virtual CommandDefinition ToTableExistStatement(string tableName, string schemaName, + CancellationToken cancellationToken = new CancellationToken()) { - return false; - } + var sql = $"SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = {GetParameterName(0)}"; + var parameters = new Dictionary {{GetParameterName(0), tableName}}; - /// Query if 'dbCmd' does table exist. - /// The database. - /// Name of the table. - /// true if it succeeds, false if it fails. - public virtual bool DoesSchemaExist(IDbConnection connection, string schemaName) - { - return false; + if (!string.IsNullOrEmpty(schemaName)) + { + sql += $" AND TABLE_SCHEMA = {GetParameterName(1)}"; + parameters.Add(GetParameterName(1), schemaName); + } + + return new CommandDefinition(sql, parameters, cancellationToken: cancellationToken); } /// Query if 'dbCmd' does sequence exist. diff --git a/src/SimpleStack.Orm/IDialectProvider.cs b/src/SimpleStack.Orm/IDialectProvider.cs index 9e0e6b3..d48de98 100644 --- a/src/SimpleStack.Orm/IDialectProvider.cs +++ b/src/SimpleStack.Orm/IDialectProvider.cs @@ -83,11 +83,13 @@ public interface IDialectProvider CommandDefinition ToCountStatement(CountStatement statement, CommandFlags flags, CancellationToken cancellationToken = new CancellationToken()); CommandDefinition ToDeleteStatement(DeleteStatement deleteStatement, CancellationToken cancellationToken = new CancellationToken()); + + CommandDefinition ToTableExistStatement(string tableName, string schemaName, CancellationToken cancellationToken = new CancellationToken()); /// Converts a tableType to a create table statement. /// Model Definition. /// tableType as a string. - string ToCreateTableStatement(ModelDefinition modelDefinition); + CommandDefinition ToCreateTableStatement(ModelDefinition modelDefinition, CancellationToken cancellationToken = new CancellationToken()); /// Converts a tableType to a create index statements. /// Model Definition. @@ -110,18 +112,6 @@ public interface IDialectProvider /// A List<string> List SequenceList(ModelDefinition modelDefinition); - /// Query if table exist. - /// The database. - /// Name of the table. - /// true if it exists, false otherwise. - bool DoesTableExist(IDbConnection connection, string tableName, string schemaName); - - /// Query if schema exist. - /// The database. - /// Name of the table. - /// true if it exists, false otherwise. - bool DoesSchemaExist(IDbConnection connection, string schemaName); - /// Query if 'dbCmd' does sequence exist. /// The database command. /// Name of the sequenc. diff --git a/src/SimpleStack.Orm/OrmConnectionAsync.cs b/src/SimpleStack.Orm/OrmConnectionAsync.cs index 6980ab8..a0d10cf 100644 --- a/src/SimpleStack.Orm/OrmConnectionAsync.cs +++ b/src/SimpleStack.Orm/OrmConnectionAsync.cs @@ -525,10 +525,7 @@ public Task UpdateAllAsync(object obj, Expression> o /// public Task TableExistsAsync(CancellationToken cancellationToken = new CancellationToken()) { - var tableModelDef = typeof(T).GetModelDefinition(); - return Task.FromResult(DialectProvider.DoesTableExist(this, - tableModelDef.Alias ?? tableModelDef.ModelName, - tableModelDef.Schema)); + return TableExistsAsync(typeof(T), cancellationToken); } /// @@ -539,9 +536,9 @@ public Task UpdateAllAsync(object obj, Expression> o public Task TableExistsAsync(Type tableType, CancellationToken cancellationToken = new CancellationToken()) { var tableModelDef = tableType.GetModelDefinition(); - return Task.FromResult(DialectProvider.DoesTableExist(this, - tableModelDef.Alias ?? tableModelDef.ModelName, - tableModelDef.Schema)); + + return TableExistsAsync(tableModelDef.Alias ?? tableModelDef.ModelName, tableModelDef.Schema, + cancellationToken); } /// @@ -550,9 +547,10 @@ public Task UpdateAllAsync(object obj, Expression> o /// the table name /// the schema name /// - public Task TableExistsAsync(string tableName, string schema = null, CancellationToken cancellationToken = new CancellationToken()) + public async Task TableExistsAsync(string tableName, string schema = null, CancellationToken cancellationToken = new CancellationToken()) { - return Task.FromResult(DialectProvider.DoesTableExist(this, tableName, schema)); + return await this.ExecuteScalarAsync( + DialectProvider.ToTableExistStatement(tableName, schema, cancellationToken: cancellationToken)) > 0; } /// @@ -617,7 +615,7 @@ public Task> GetTableColumnsAsync(string tableNam var dialectProvider = DialectProvider; var tableName = dialectProvider.NamingStrategy.GetTableName(modelDef.ModelName); - var tableExists = dialectProvider.DoesTableExist(this, tableName, modelDef.Schema); + var tableExists = await TableExistsAsync(tableName, modelDef.Schema, cancellationToken); if (overwrite && tableExists) { @@ -627,7 +625,7 @@ public Task> GetTableColumnsAsync(string tableNam if (!tableExists) { - await this.ExecuteAsync(dialectProvider.ToCreateTableStatement(modelDef), cancellationToken).ConfigureAwait(false); + await this.ExecuteAsync(dialectProvider.ToCreateTableStatement(modelDef)).ConfigureAwait(false); var sqlIndexes = dialectProvider.ToCreateIndexStatements(modelDef); foreach (var sqlIndex in sqlIndexes) From 15ab279cdd52fb65a894adb7aee674eaec73903c Mon Sep 17 00:00:00 2001 From: Vincent DARON Date: Wed, 27 Jul 2022 23:59:51 +0200 Subject: [PATCH 05/14] Ensure NamingConventions are applied in PostgreSQL code to detect if tables exists fix unit tests --- .../PostgreSQLDialectProvider.cs | 6 +- .../SqliteDialectProvider.cs | 2 +- .../SqlServerOrmLiteDialectProvider.cs | 2 +- .../SqliteDialectProvider.cs | 2 +- src/SimpleStack.Orm/DialectProviderBase.cs | 2 +- src/SimpleStack.Orm/OrmConnectionAsync.cs | 25 +- src/SimpleStack.Orm/OrmConnectionSync.cs | 12 +- .../SimpleStack.Orm.xUnit/CreateTableTests.cs | 249 ++++++++++++++---- .../SimpleStack.Orm.xUnit.csproj | 1 + 9 files changed, 215 insertions(+), 86 deletions(-) diff --git a/src/SimpleStack.Orm.PostgreSQL/PostgreSQLDialectProvider.cs b/src/SimpleStack.Orm.PostgreSQL/PostgreSQLDialectProvider.cs index caf160b..319f6b4 100644 --- a/src/SimpleStack.Orm.PostgreSQL/PostgreSQLDialectProvider.cs +++ b/src/SimpleStack.Orm.PostgreSQL/PostgreSQLDialectProvider.cs @@ -103,10 +103,10 @@ public override CommandDefinition ToTableExistStatement(string tableName, string var sql = $@"SELECT COUNT(*) FROM pg_class LEFT JOIN pg_namespace n ON n.oid = pg_class.relnamespace WHERE relname = {GetParameterName(0)}"; - + var parameters = new Dictionary { - {GetParameterName(0), tableName}, + {GetParameterName(0), NamingStrategy.GetTableName(tableName)}, }; if (string.IsNullOrEmpty(schemaName)) @@ -116,7 +116,7 @@ public override CommandDefinition ToTableExistStatement(string tableName, string else { sql += $" AND nspname = {GetParameterName(1)}"; - parameters.Add(GetParameterName(1),schemaName); + parameters.Add(GetParameterName(1),NamingStrategy.GetTableName(schemaName)); } return new CommandDefinition(sql, parameters, cancellationToken: cancellationToken); diff --git a/src/SimpleStack.Orm.SDSQLite/SqliteDialectProvider.cs b/src/SimpleStack.Orm.SDSQLite/SqliteDialectProvider.cs index ebd57ce..f429c89 100644 --- a/src/SimpleStack.Orm.SDSQLite/SqliteDialectProvider.cs +++ b/src/SimpleStack.Orm.SDSQLite/SqliteDialectProvider.cs @@ -50,7 +50,7 @@ public override CommandDefinition ToTableExistStatement(string tableName, string var name = string.IsNullOrEmpty(schemaName) ? tableName : $"{schemaName}_{tableName}"; var sql = $"SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name = {GetParameterName(0)}"; - var parameters = new Dictionary {{GetParameterName(0), tableName}}; + var parameters = new Dictionary {{GetParameterName(0), name}}; return new CommandDefinition(sql, parameters, cancellationToken: cancellationToken); } diff --git a/src/SimpleStack.Orm.SQLServer/SqlServerOrmLiteDialectProvider.cs b/src/SimpleStack.Orm.SQLServer/SqlServerOrmLiteDialectProvider.cs index 048f767..33e400e 100644 --- a/src/SimpleStack.Orm.SQLServer/SqlServerOrmLiteDialectProvider.cs +++ b/src/SimpleStack.Orm.SQLServer/SqlServerOrmLiteDialectProvider.cs @@ -57,7 +57,7 @@ public override string GetCreateSchemaStatement(string schema, bool ignoreIfExis { return ignoreIfExists ? $@"IF NOT EXISTS ( SELECT * FROM sys.schemas WHERE name = N'{schema}' ) - EXEC('CREATE SCHEMA [app]')" : + EXEC('CREATE SCHEMA [{schema}]')" : $"CREATE SCHEMA {schema}"; } diff --git a/src/SimpleStack.Orm.SQLite/SqliteDialectProvider.cs b/src/SimpleStack.Orm.SQLite/SqliteDialectProvider.cs index 90de811..358c56e 100644 --- a/src/SimpleStack.Orm.SQLite/SqliteDialectProvider.cs +++ b/src/SimpleStack.Orm.SQLite/SqliteDialectProvider.cs @@ -51,7 +51,7 @@ public override CommandDefinition ToTableExistStatement(string tableName, string var name = string.IsNullOrEmpty(schemaName) ? tableName : $"{schemaName}_{tableName}"; var sql = $"SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name = {GetParameterName(0)}"; - var parameters = new Dictionary {{GetParameterName(0), tableName}}; + var parameters = new Dictionary {{GetParameterName(0), name}}; return new CommandDefinition(sql, parameters, cancellationToken: cancellationToken); } diff --git a/src/SimpleStack.Orm/DialectProviderBase.cs b/src/SimpleStack.Orm/DialectProviderBase.cs index cd13869..60d6c43 100644 --- a/src/SimpleStack.Orm/DialectProviderBase.cs +++ b/src/SimpleStack.Orm/DialectProviderBase.cs @@ -347,7 +347,7 @@ public virtual CommandDefinition ToTableExistStatement(string tableName, string CancellationToken cancellationToken = new CancellationToken()) { var sql = $"SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = {GetParameterName(0)}"; - var parameters = new Dictionary {{GetParameterName(0), tableName}}; + var parameters = new Dictionary {{GetParameterName(0), NamingStrategy.GetTableName(tableName)}}; if (!string.IsNullOrEmpty(schemaName)) { diff --git a/src/SimpleStack.Orm/OrmConnectionAsync.cs b/src/SimpleStack.Orm/OrmConnectionAsync.cs index a0d10cf..f35171f 100644 --- a/src/SimpleStack.Orm/OrmConnectionAsync.cs +++ b/src/SimpleStack.Orm/OrmConnectionAsync.cs @@ -296,7 +296,7 @@ public Task CountAsync(string tableName, string schemaName, /// /// /// - public Task UpdateAllAsync(object obj, Expression> onlyField, + public async Task UpdateAllAsync(object obj, Expression> onlyField, Expression> where = null, CancellationToken cancellationToken = new CancellationToken()) { var s = new TypedUpdateStatement(DialectProvider); @@ -308,7 +308,7 @@ public Task UpdateAllAsync(object obj, Expression> o s.Values(obj, onlyField); var cmd = DialectProvider.ToUpdateStatement(s.Statement, CommandFlags.None, cancellationToken); - return this.ExecuteScalarAsync(cmd); + return await this.ExecuteScalarAsync(cmd); } /// @@ -330,14 +330,14 @@ public Task UpdateAllAsync(object obj, Expression> o /// /// /// - public Task InsertAsync(T obj, CancellationToken cancellationToken = new CancellationToken()) + public async Task InsertAsync(T obj, CancellationToken cancellationToken = new CancellationToken()) { try { var insertStatement = new TypedInsertStatement(DialectProvider); insertStatement.Values(obj, Array.Empty()); var commandDefinition = DialectProvider.ToInsertStatement(insertStatement.Statement, CommandFlags.None, cancellationToken); - return this.ExecuteScalarAsync(commandDefinition); + return await this.ExecuteScalarAsync(commandDefinition); } catch (Exception e) { @@ -351,18 +351,7 @@ public Task UpdateAllAsync(object obj, Expression> o /// The objects to insert /// /// - public Task> InsertAsync(IEnumerable objs, CancellationToken cancellationToken = new CancellationToken()) - { - return InsertAsync(objs, cancellationToken); - } - - /// - /// Insert multiple objects at once in the database - /// - /// The objects to insert - /// - /// - public async Task> InsertAsync(IEnumerable objs, CancellationToken cancellationToken = new CancellationToken()) + public async Task> InsertAsync(IEnumerable objs, CancellationToken cancellationToken = new CancellationToken()) { if (objs == null) { @@ -391,13 +380,13 @@ public Task UpdateAllAsync(object obj, Expression> o /// /// /// - public Task InsertOnlyAsync(T obj, Expression> onlyFields, CancellationToken cancellationToken = new CancellationToken()) + public async Task InsertOnlyAsync(T obj, Expression> onlyFields, CancellationToken cancellationToken = new CancellationToken()) where T : new() { var insertStatement = new TypedInsertStatement(DialectProvider); insertStatement.Values(obj, onlyFields); - return this.ExecuteScalarAsync( + return await this.ExecuteScalarAsync( DialectProvider.ToInsertStatement(insertStatement.Statement, CommandFlags.None, cancellationToken)); } diff --git a/src/SimpleStack.Orm/OrmConnectionSync.cs b/src/SimpleStack.Orm/OrmConnectionSync.cs index 090e4ca..8e25d59 100644 --- a/src/SimpleStack.Orm/OrmConnectionSync.cs +++ b/src/SimpleStack.Orm/OrmConnectionSync.cs @@ -224,17 +224,9 @@ public TKey Insert(T obj) /// The objects. public IEnumerable Insert(IEnumerable objs) { - return InsertAsync(objs).Result; + return InsertAsync(objs).Result; } - - /// An OrmConnection method that inserts all. - /// Generic type parameter. - /// The objects. - public IEnumerable Insert(IEnumerable objs) - { - return InsertAsync(objs).Result; - } - + /// An OrmConnection method that inserts an only. /// Generic type parameter. /// The object. diff --git a/test/SimpleStack.Orm.xUnit/CreateTableTests.cs b/test/SimpleStack.Orm.xUnit/CreateTableTests.cs index 4ad140d..0dad5f7 100644 --- a/test/SimpleStack.Orm.xUnit/CreateTableTests.cs +++ b/test/SimpleStack.Orm.xUnit/CreateTableTests.cs @@ -1,62 +1,174 @@ using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; using System.Linq; using System.Threading.Tasks; +using DotNet.Testcontainers.Builders; +using DotNet.Testcontainers.Configurations; +using DotNet.Testcontainers.Containers; +using Microsoft.Data.Sqlite; using SimpleStack.Orm.Attributes; +using SimpleStack.Orm.MySQL; +using SimpleStack.Orm.MySQLConnector; +using SimpleStack.Orm.PostgreSQL; +using SimpleStack.Orm.Sqlite; +using SimpleStack.Orm.SqlServer; using SimpleStack.Orm.xUnit.Tools; using Xunit; namespace SimpleStack.Orm.xUnit { - public class CreateTableTests : IDisposable + public enum DialectType { - public void Dispose() + MySQL, + MySQLConnector, + PostgreSQL, + SQLServer, + SqLite, + SDSqLite, + } + + public class BaseTest : IDisposable + { + private readonly string _sqliteTempFile = Path.GetRandomFileName(); + private readonly string _sqliteTempFile2 = Path.GetRandomFileName(); + + private readonly TestcontainerDatabase _mysql = new TestcontainersBuilder() + .WithDatabase(new MySqlTestcontainerConfiguration + { + Database = "db", + Username = "mysql", + Password = "passwword" + }) + .WithImage("redis:latest") + .Build(); + private readonly TestcontainerDatabase _mysqlConnector = new TestcontainersBuilder() + .WithDatabase(new MySqlTestcontainerConfiguration + { + Database = "db", + Username = "mysql", + Password = "passwword" + }) + .Build(); + private readonly TestcontainerDatabase _postgresql = new TestcontainersBuilder() + .WithDatabase(new PostgreSqlTestcontainerConfiguration + { + Database = "db", + Username = "postgres", + Password = "postgres", + }) + .Build(); + + private readonly TestcontainerDatabase _sqlServer = new TestcontainersBuilder() + .WithDatabase(new MsSqlTestcontainerConfiguration { - foreach (var factory in ConnectionFactories.All) + Password = "#testingDockerPassword#" + }) + .Build(); + + protected Dictionary _ormConnectionFactories = + new Dictionary(); + + public BaseTest() + { + _mysql.StartAsync().Wait(); + _mysqlConnector.StartAsync().Wait(); + _postgresql.StartAsync().Wait(); + _sqlServer.StartAsync().Wait(); + + _ormConnectionFactories.Add(DialectType.MySQL,new OrmConnectionFactory(new MySqlDialectProvider(), _mysql.ConnectionString)); + _ormConnectionFactories.Add(DialectType.MySQLConnector,new OrmConnectionFactory(new MySqlConnectorDialectProvider(), _mysqlConnector.ConnectionString)); + _ormConnectionFactories.Add(DialectType.PostgreSQL,new OrmConnectionFactory(new PostgreSQLDialectProvider(), _postgresql.ConnectionString)); + _ormConnectionFactories.Add(DialectType.SQLServer,new OrmConnectionFactory(new SqlServerDialectProvider(), $"{_sqlServer.ConnectionString};TrustServerCertificate=true")); + + var builder = new SqliteConnectionStringBuilder { - using (var c = ((OrmConnectionFactory) factory[0]).OpenConnection()) - { - c.DropTableIfExists(); - c.DropTableIfExists(); - c.DropTableIfExists(); - c.DropTableIfExists(); - c.DropTableIfExists(); - c.DropTableIfExists(); - } - } + DataSource = _sqliteTempFile, + Mode = SqliteOpenMode.ReadWriteCreate, + Cache = SqliteCacheMode.Shared + }; + + _ormConnectionFactories.Add(DialectType.SqLite,new OrmConnectionFactory(new SqliteDialectProvider(), builder.ToString())); + _ormConnectionFactories.Add(DialectType.SDSqLite, new OrmConnectionFactory(new SDSQLite.SqliteDialectProvider(), + $"Data Source={_sqliteTempFile2};foreign keys=true;Version=3;New=True;BinaryGUID=False")); } + + public void Dispose() + { + _mysql.DisposeAsync().AsTask().Wait(); + _mysqlConnector.DisposeAsync().AsTask().Wait(); + _postgresql.DisposeAsync().AsTask().Wait(); + _sqlServer.DisposeAsync().AsTask().Wait(); + + File.Delete(_sqliteTempFile); + File.Delete(_sqliteTempFile2); + } + + public async Task OpenConnection(DialectType dialect) + { + return await _ormConnectionFactories[dialect].OpenConnectionAsync(); + } + } + public class CreateTableTests : IClassFixture + { + private readonly BaseTest _baseTest; + + public CreateTableTests(BaseTest baseTest) + { + _baseTest = baseTest; + } + [Theory] - [MemberData(nameof(ConnectionFactories.All), MemberType = typeof(ConnectionFactories))] - public async Task CreateTableWithoutPrimaryKeys(OrmConnectionFactory factory) + [InlineData(DialectType.MySQL)] + [InlineData(DialectType.MySQLConnector)] + [InlineData(DialectType.PostgreSQL)] + [InlineData(DialectType.SqLite)] + [InlineData(DialectType.SDSqLite)] + [InlineData(DialectType.SQLServer)] + public async Task CreateTableWithoutPrimaryKeys(DialectType dialect) { - using (var c = factory.OpenConnection()) + using (var c = await _baseTest.OpenConnection(dialect)) { Assert.False(await c.TableExistsAsync()); await c.CreateTableAsync(true); - Assert.Equal(1, await c.InsertAsync(new NoPk())); + // Assert.Equal(1, await c.InsertAsync(new NoPk())); Assert.True(await c.TableExistsAsync()); } } - + [Theory] - [MemberData(nameof(ConnectionFactories.All), MemberType = typeof(ConnectionFactories))] - public async Task CreateTableWithOnePk(OrmConnectionFactory factory) + [InlineData(DialectType.MySQL)] + [InlineData(DialectType.MySQLConnector)] + [InlineData(DialectType.PostgreSQL)] + [InlineData(DialectType.SqLite)] + [InlineData(DialectType.SDSqLite)] + [InlineData(DialectType.SQLServer)] + public async Task CreateTableWithOnePk(DialectType dialect) { - using (var c = factory.OpenConnection()) + using (var c = await _baseTest.OpenConnection(dialect)) { Assert.False(await c.TableExistsAsync()); await c.CreateTableAsync(true); Assert.True(await c.TableExistsAsync()); - Assert.Equal(1, await c.InsertAsync(new OnePk {Pk = "1"})); + + Assert.Equal(1,await c.InsertAsync(new OnePk {Pk = "1"})); await Assert.ThrowsAsync(async () => await c.InsertAsync(new OnePk {Pk = "1"})); } } [Theory] - [MemberData(nameof(ConnectionFactories.All), MemberType = typeof(ConnectionFactories))] - public async Task CreateTableWithTwoPks(OrmConnectionFactory factory) + [InlineData(DialectType.MySQL)] + [InlineData(DialectType.MySQLConnector)] + [InlineData(DialectType.PostgreSQL)] + [InlineData(DialectType.SqLite)] + [InlineData(DialectType.SDSqLite)] + [InlineData(DialectType.SQLServer)] + public async Task CreateTableWithTwoPks(DialectType dialect) { - using (var c = factory.OpenConnection()) + using (var c = await _baseTest.OpenConnection(dialect)) { Assert.False(await c.TableExistsAsync()); await c.CreateTableAsync(true); @@ -69,10 +181,15 @@ await Assert.ThrowsAsync(async () => } [Theory] - [MemberData(nameof(ConnectionFactories.All), MemberType = typeof(ConnectionFactories))] - public async Task CreateTableWithForeignKey(OrmConnectionFactory factory) + [InlineData(DialectType.MySQL)] + [InlineData(DialectType.MySQLConnector)] + [InlineData(DialectType.PostgreSQL)] + [InlineData(DialectType.SqLite)] + [InlineData(DialectType.SDSqLite)] + [InlineData(DialectType.SQLServer)] + public async Task CreateTableWithForeignKey(DialectType dialect) { - using (var c = factory.OpenConnection()) + using (var c = await _baseTest.OpenConnection(dialect)) { Assert.False(await c.TableExistsAsync()); Assert.False(await c.TableExistsAsync()); @@ -90,10 +207,15 @@ public async Task CreateTableWithForeignKey(OrmConnectionFactory factory) } [Theory] - [MemberData(nameof(ConnectionFactories.All), MemberType = typeof(ConnectionFactories))] - public async Task CreateTableWithAliases(OrmConnectionFactory factory) + [InlineData(DialectType.MySQL)] + [InlineData(DialectType.MySQLConnector)] + [InlineData(DialectType.PostgreSQL)] + [InlineData(DialectType.SqLite)] + [InlineData(DialectType.SDSqLite)] + [InlineData(DialectType.SQLServer)] + public async Task CreateTableWithAliases(DialectType dialect) { - using (var c = factory.OpenConnection()) + using (var c = await _baseTest.OpenConnection(dialect)) { await c.CreateTableAsync(true); @@ -102,41 +224,51 @@ public async Task CreateTableWithAliases(OrmConnectionFactory factory) c.Select(x => { Assert.Equal(c.DialectProvider.GetQuotedTableName("withaliasrenamed"), x.Statement.TableName); - Assert.Equal(c.DialectProvider.GetQuotedColumnName("columnAlias") + " AS Column1", + Assert.Equal(c.DialectProvider.GetQuotedColumnName("columnAlias") + " AS " + c.DialectProvider.GetQuotedColumnName("Column1"), x.Statement.Columns[0]); }); } } [Theory] - [MemberData(nameof(ConnectionFactories.All), MemberType = typeof(ConnectionFactories))] - public async Task CreateTableWithAliasAndSchema(OrmConnectionFactory factory) + // [InlineData(DialectType.MySQL)] + // [InlineData(DialectType.MySQLConnector)] + [InlineData(DialectType.PostgreSQL)] + [InlineData(DialectType.SqLite)] + [InlineData(DialectType.SDSqLite)] + [InlineData(DialectType.SQLServer)] + public async Task CreateTableWithAliasAndSchema(DialectType dialect) { - using (var c = factory.OpenConnection()) + using (var c = await _baseTest.OpenConnection(dialect)) { await c.CreateSchemaIfNotExistsAsync("TS"); await c.CreateTableAsync(true); Assert.True(await c.TableExistsAsync()); - Assert.NotEmpty(c.GetTables("TS") + Assert.NotEmpty((await c.GetTablesAsync("TS")) .Select(x => x.SchemaName == "TS" && x.Name == "withaliasansschema")); c.Select(x => { Assert.Equal(c.DialectProvider.GetQuotedTableName("withaliasansschema", "TS"), x.Statement.TableName); - Assert.Equal(c.DialectProvider.GetQuotedColumnName("columnAlias") + " AS Column1", + Assert.Equal(c.DialectProvider.GetQuotedColumnName("columnAlias") + " AS " + c.DialectProvider.GetQuotedColumnName("Column1"), x.Statement.Columns[0]); }); } } [Theory] - [MemberData(nameof(ConnectionFactories.All), MemberType = typeof(ConnectionFactories))] - public async Task CreateTableThatAlreadyExistThrowError(OrmConnectionFactory factory) + [InlineData(DialectType.MySQL)] + [InlineData(DialectType.MySQLConnector)] + [InlineData(DialectType.PostgreSQL)] + [InlineData(DialectType.SqLite)] + [InlineData(DialectType.SDSqLite)] + [InlineData(DialectType.SQLServer)] + public async Task CreateTableThatAlreadyExistThrowError(DialectType dialect) { - using (var c = await factory.OpenConnectionAsync()) + using (var c = await _baseTest.OpenConnection(dialect)) { await c.CreateTableAsync(true); @@ -154,10 +286,15 @@ public async Task CreateTableThatAlreadyExistThrowError(OrmConnectionFactory fac } [Theory] - [MemberData(nameof(ConnectionFactories.All), MemberType = typeof(ConnectionFactories))] - public async Task CreateTableAndDropTable(OrmConnectionFactory factory) + [InlineData(DialectType.MySQL)] + [InlineData(DialectType.MySQLConnector)] + [InlineData(DialectType.PostgreSQL)] + [InlineData(DialectType.SqLite)] + [InlineData(DialectType.SDSqLite)] + [InlineData(DialectType.SQLServer)] + public async Task CreateTableAndDropTable(DialectType dialect) { - using (var c = await factory.OpenConnectionAsync()) + using (var c = await _baseTest.OpenConnection(dialect)) { await c.CreateTableAsync(false); Assert.True(await c.TableExistsAsync()); @@ -171,10 +308,15 @@ public async Task CreateTableAndDropTable(OrmConnectionFactory factory) } [Theory] - [MemberData(nameof(ConnectionFactories.All), MemberType = typeof(ConnectionFactories))] - public async Task CreateTableWithColumnsAndAttributes(OrmConnectionFactory factory) + [InlineData(DialectType.MySQL)] + [InlineData(DialectType.MySQLConnector)] + [InlineData(DialectType.PostgreSQL)] + [InlineData(DialectType.SqLite)] + [InlineData(DialectType.SDSqLite)] + [InlineData(DialectType.SQLServer)] + public async Task CreateTableWithColumnsAndAttributes(DialectType dialect) { - using (var c = await factory.OpenConnectionAsync()) + using (var c = await _baseTest.OpenConnection(dialect)) { Assert.False(await c.TableExistsAsync()); await c.CreateTableAsync(false); @@ -231,14 +373,19 @@ await Assert.ThrowsAsync(() => c.InsertAsync(new WithAttributes } [Theory] - [MemberData(nameof(ConnectionFactories.All), MemberType = typeof(ConnectionFactories))] - public void GetTableColumnInfo(OrmConnectionFactory factory) + [InlineData(DialectType.MySQL)] + [InlineData(DialectType.MySQLConnector)] + [InlineData(DialectType.PostgreSQL)] + [InlineData(DialectType.SqLite)] + [InlineData(DialectType.SDSqLite)] + [InlineData(DialectType.SQLServer)] + public async Task GetTableColumnInfo(DialectType dialect) { - using (var conn = factory.OpenConnection()) + using (var conn = await _baseTest.OpenConnection(dialect)) { - conn.CreateTable(true); + await conn.CreateTableAsync(true); - var t = conn.GetTableColumns("WithAttributes").ToList(); + var t = (await conn.GetTableColumnsAsync("WithAttributes")).ToList(); Assert.NotNull(t); Assert.NotEmpty(t); diff --git a/test/SimpleStack.Orm.xUnit/SimpleStack.Orm.xUnit.csproj b/test/SimpleStack.Orm.xUnit/SimpleStack.Orm.xUnit.csproj index 14d0c54..59fd12b 100644 --- a/test/SimpleStack.Orm.xUnit/SimpleStack.Orm.xUnit.csproj +++ b/test/SimpleStack.Orm.xUnit/SimpleStack.Orm.xUnit.csproj @@ -8,6 +8,7 @@ + From 793924ddfdd01b1bfaf61b2592ad20d92e605e76 Mon Sep 17 00:00:00 2001 From: Vincent DARON Date: Sun, 14 Aug 2022 17:32:19 +0200 Subject: [PATCH 06/14] create database on SQLServer for test if not exists --- test/SimpleStack.Orm.Tests/ExpressionTests.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/SimpleStack.Orm.Tests/ExpressionTests.cs b/test/SimpleStack.Orm.Tests/ExpressionTests.cs index 9f8ff16..fb9cf0b 100644 --- a/test/SimpleStack.Orm.Tests/ExpressionTests.cs +++ b/test/SimpleStack.Orm.Tests/ExpressionTests.cs @@ -237,6 +237,15 @@ public class SQLServerTests : ExpressionTests { public SQLServerTests() : base(new SqlServerDialectProvider(),@"server=localhost,21433;User id=sa;Password=Simplestack2022!;database=test;Encrypt=True;TrustServerCertificate=True") { + var conn = new OrmConnectionFactory(new SqlServerDialectProvider(), + @"server=localhost,21433;User id=sa;Password=Simplestack2022!;Encrypt=True;TrustServerCertificate=True"); + using (var c = conn.OpenConnection()) + { + c.Execute(@"IF NOT EXISTS(SELECT * FROM sys.databases WHERE name = 'test') + BEGIN + CREATE DATABASE [test] + END"); + } } public override void Can_Select_Logical_Bitwise_xor_int_expression() From b2d8f5e39097e0710cf91aee1d0bede8d7a694d0 Mon Sep 17 00:00:00 2001 From: Vincent DARON Date: Wed, 27 Jul 2022 09:26:14 +0200 Subject: [PATCH 07/14] Upgrade latest Dapper --- .../SimpleStack.Orm.MySQL.csproj | 2 +- .../SimpleStack.Orm.MySQLConnector.csproj | 2 +- .../SimpleStack.Orm.PostgreSQL.csproj | 2 +- .../SimpleStack.Orm.SDSQLite.csproj | 6 +-- .../SimpleStack.Orm.SQLite.csproj | 6 +-- .../SqliteDialectProvider.cs | 2 + src/SimpleStack.Orm/DialectProviderBase.cs | 8 +++- src/SimpleStack.Orm/SimpleStack.Orm.csproj | 2 +- test/SimpleStack.Orm.Tests/ExpressionTests.cs | 40 ++++++++++--------- .../ExpressionVisitorTests.cs | 2 +- .../GetTableColumnsTests.cs | 15 +++---- test/SimpleStack.Orm.Tests/TestType.cs | 2 +- 12 files changed, 47 insertions(+), 42 deletions(-) diff --git a/src/SimpleStack.Orm.MySQL/SimpleStack.Orm.MySQL.csproj b/src/SimpleStack.Orm.MySQL/SimpleStack.Orm.MySQL.csproj index eb95aef..271e7f2 100644 --- a/src/SimpleStack.Orm.MySQL/SimpleStack.Orm.MySQL.csproj +++ b/src/SimpleStack.Orm.MySQL/SimpleStack.Orm.MySQL.csproj @@ -27,7 +27,7 @@ - + diff --git a/src/SimpleStack.Orm.MySQLConnector/SimpleStack.Orm.MySQLConnector.csproj b/src/SimpleStack.Orm.MySQLConnector/SimpleStack.Orm.MySQLConnector.csproj index 41d01e6..38847e9 100644 --- a/src/SimpleStack.Orm.MySQLConnector/SimpleStack.Orm.MySQLConnector.csproj +++ b/src/SimpleStack.Orm.MySQLConnector/SimpleStack.Orm.MySQLConnector.csproj @@ -25,7 +25,7 @@ - + diff --git a/src/SimpleStack.Orm.PostgreSQL/SimpleStack.Orm.PostgreSQL.csproj b/src/SimpleStack.Orm.PostgreSQL/SimpleStack.Orm.PostgreSQL.csproj index da14033..6ec33d7 100644 --- a/src/SimpleStack.Orm.PostgreSQL/SimpleStack.Orm.PostgreSQL.csproj +++ b/src/SimpleStack.Orm.PostgreSQL/SimpleStack.Orm.PostgreSQL.csproj @@ -25,7 +25,7 @@ - + diff --git a/src/SimpleStack.Orm.SDSQLite/SimpleStack.Orm.SDSQLite.csproj b/src/SimpleStack.Orm.SDSQLite/SimpleStack.Orm.SDSQLite.csproj index e537be3..2aae8ee 100644 --- a/src/SimpleStack.Orm.SDSQLite/SimpleStack.Orm.SDSQLite.csproj +++ b/src/SimpleStack.Orm.SDSQLite/SimpleStack.Orm.SDSQLite.csproj @@ -30,9 +30,9 @@ - - - + + + diff --git a/src/SimpleStack.Orm.SQLite/SimpleStack.Orm.SQLite.csproj b/src/SimpleStack.Orm.SQLite/SimpleStack.Orm.SQLite.csproj index f68754a..963ef29 100644 --- a/src/SimpleStack.Orm.SQLite/SimpleStack.Orm.SQLite.csproj +++ b/src/SimpleStack.Orm.SQLite/SimpleStack.Orm.SQLite.csproj @@ -25,9 +25,9 @@ - - - + + + diff --git a/src/SimpleStack.Orm.SQLite/SqliteDialectProvider.cs b/src/SimpleStack.Orm.SQLite/SqliteDialectProvider.cs index 358c56e..449b3ce 100644 --- a/src/SimpleStack.Orm.SQLite/SqliteDialectProvider.cs +++ b/src/SimpleStack.Orm.SQLite/SqliteDialectProvider.cs @@ -14,6 +14,8 @@ namespace SimpleStack.Orm.Sqlite /// A sqlite ORM lite dialect provider base. public class SqliteDialectProvider : DialectProviderBase { + + private static readonly Regex PrecisionAndScaleRegex = new Regex(@"\w+\((?\d+),?(?\d+)?\)",RegexOptions.Compiled); /// diff --git a/src/SimpleStack.Orm/DialectProviderBase.cs b/src/SimpleStack.Orm/DialectProviderBase.cs index 60d6c43..287bcdb 100644 --- a/src/SimpleStack.Orm/DialectProviderBase.cs +++ b/src/SimpleStack.Orm/DialectProviderBase.cs @@ -645,8 +645,12 @@ protected virtual string GetDefaultValueDefinition(object defaultValue) /// The column type definition. public virtual string GetColumnTypeDefinition(Type fieldType, string fieldName, int? fieldLength) { + // DateTime has been removed from Dapper DBTypes + if(fieldType == typeof(DateTime)) + return TypesMapper.GetFieldDefinition(DbType.DateTime2, fieldLength); + #pragma warning disable 618 - var dbType = SqlMapper.LookupDbType(fieldType, fieldName, false, out var typeHandler); + var dbType = SqlMapper.LookupDbType(fieldType, fieldName, true, out var typeHandler); #pragma warning restore 618 if (typeHandler is ITypeHandlerColumnType typeHandlerColumnType) @@ -655,7 +659,7 @@ public virtual string GetColumnTypeDefinition(Type fieldType, string fieldName, fieldLength = typeHandlerColumnType.Length; } - return TypesMapper.GetFieldDefinition(dbType, fieldLength); + return TypesMapper.GetFieldDefinition(dbType.GetValueOrDefault(DbType.Object), fieldLength); } /// Gets foreign key on delete clause. diff --git a/src/SimpleStack.Orm/SimpleStack.Orm.csproj b/src/SimpleStack.Orm/SimpleStack.Orm.csproj index ce5629a..f570e93 100644 --- a/src/SimpleStack.Orm/SimpleStack.Orm.csproj +++ b/src/SimpleStack.Orm/SimpleStack.Orm.csproj @@ -21,7 +21,7 @@ - + diff --git a/test/SimpleStack.Orm.Tests/ExpressionTests.cs b/test/SimpleStack.Orm.Tests/ExpressionTests.cs index fb9cf0b..174230b 100644 --- a/test/SimpleStack.Orm.Tests/ExpressionTests.cs +++ b/test/SimpleStack.Orm.Tests/ExpressionTests.cs @@ -44,23 +44,7 @@ public virtual void Setup() private readonly OrmConnectionFactory _connectionFactory; - public class GuidAsByteArray : ITypeHandlerColumnType - { - public void SetValue(IDbDataParameter parameter, object value) - { - parameter.DbType = DbType.Binary; - parameter.Value = ((Guid) value).ToByteArray(); - } - - public object Parse(Type destinationType, object value) - { - return new Guid((byte[]) value); - } - - public int? Length => Guid.Empty.ToByteArray().Length; - - public DbType ColumnType => DbType.Binary; - } + public class EnumAsStringTypeHandler : ITypeHandlerColumnType { @@ -98,7 +82,7 @@ public object Parse(Type destinationType, object value) public DbType ColumnType => DbType.Int32; } - public class JsonTypeHandler : SqlMapper.ITypeHandler, ITypeHandlerColumnType + public class JsonTypeHandler : ITypeHandlerColumnType { private readonly JsonSerializer s = new JsonSerializer(); @@ -318,11 +302,29 @@ public override void Can_Select_Logical_Bitwise_rightshift_int_expression() public class SQLLiteTests : ExpressionTests { + public class GuidAsString : ITypeHandlerColumnType + { + public void SetValue(IDbDataParameter parameter, object value) + { + parameter.DbType = DbType.String; + parameter.Value = ((Guid)value).ToString("N"); + } + + public object Parse(Type destinationType, object value) + { + return Guid.Parse((string)value); + } + + public int? Length => 32; + + public DbType ColumnType => DbType.String; + } + public override void Setup() { base.Setup(); - SqlMapper.AddTypeHandler(typeof(Guid), new GuidAsByteArray()); + SqlMapper.AddTypeHandler(typeof(Guid), new GuidAsString()); } public SQLLiteTests() : base(new SqliteDialectProvider(), GetConnectionString()) { diff --git a/test/SimpleStack.Orm.Tests/ExpressionVisitorTests.cs b/test/SimpleStack.Orm.Tests/ExpressionVisitorTests.cs index 8184b46..c48b9ac 100644 --- a/test/SimpleStack.Orm.Tests/ExpressionVisitorTests.cs +++ b/test/SimpleStack.Orm.Tests/ExpressionVisitorTests.cs @@ -543,7 +543,7 @@ public class TestType2 /// Gets or sets the complex object col. /// The complex object col. - public TestType2 ComplexObjCol { get; set; } + //public TestType2 ComplexObjCol { get; set; } public long LongCol { get; set; } diff --git a/test/SimpleStack.Orm.Tests/GetTableColumnsTests.cs b/test/SimpleStack.Orm.Tests/GetTableColumnsTests.cs index a28b716..3ea6445 100644 --- a/test/SimpleStack.Orm.Tests/GetTableColumnsTests.cs +++ b/test/SimpleStack.Orm.Tests/GetTableColumnsTests.cs @@ -19,7 +19,7 @@ public virtual void CanGetColumns() db.CreateTable(true); var columns = db.GetTableColumns("TestType2").ToArray(); - Assert.AreEqual(8, columns.Length); + Assert.AreEqual(7, columns.Length); Assert.AreEqual("id", columns[0].Name.ToLower()); Assert.AreEqual(true, columns[0].PrimaryKey); @@ -50,17 +50,14 @@ public virtual void CanGetColumns() Assert.AreEqual(false, columns[5].PrimaryKey); Assert.False(columns[5].Unique); Assert.AreEqual(DbType.Guid, columns[5].DbType); - - Assert.AreEqual("complexobjcol", columns[6].Name.ToLower()); - Assert.AreEqual(false, columns[6].PrimaryKey); - Assert.False(columns[6].Unique); + // SQLServer return String for this type //Assert.AreEqual(DbType.Binary, columns[6].DbType); - Assert.AreEqual("longcol", columns[7].Name.ToLower()); - Assert.AreEqual(false, columns[7].PrimaryKey); - Assert.False(columns[7].Unique); - Assert.AreEqual(DbType.Int64, columns[7].DbType); + Assert.AreEqual("longcol", columns[6].Name.ToLower()); + Assert.AreEqual(false, columns[6].PrimaryKey); + Assert.False(columns[6].Unique); + Assert.AreEqual(DbType.Int64, columns[6].DbType); } } diff --git a/test/SimpleStack.Orm.Tests/TestType.cs b/test/SimpleStack.Orm.Tests/TestType.cs index c440e2d..2b44dc9 100644 --- a/test/SimpleStack.Orm.Tests/TestType.cs +++ b/test/SimpleStack.Orm.Tests/TestType.cs @@ -18,7 +18,7 @@ public class TestType /// Gets or sets the nullable col. /// The nullable col. - public TestType2 NullableCol { get; set; } + //public TestType2 NullableCol { get; set; } /// Gets or sets the identifier. /// The identifier. From be6fa2ede2f663f45223e168a770ecf957a1e613 Mon Sep 17 00:00:00 2001 From: Vincent DARON Date: Sun, 14 Aug 2022 17:41:04 +0200 Subject: [PATCH 08/14] Update database drivers --- .../SimpleStack.Orm.Logging.MicrosoftExtensions.csproj | 4 ++-- .../SimpleStack.Orm.MySQLConnector.csproj | 2 +- .../SimpleStack.Orm.PostgreSQL.csproj | 2 +- .../SimpleStack.Orm.SDSQLite.csproj | 4 ++-- .../SimpleStack.Orm.SQLServer.csproj | 2 +- src/SimpleStack.Orm.SQLite/SimpleStack.Orm.SQLite.csproj | 4 ++-- test/SimpleStack.Orm.Tests/SimpleStack.Orm.Tests.csproj | 7 +++---- test/SimpleStack.Orm.xUnit/SimpleStack.Orm.xUnit.csproj | 7 +++++-- 8 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/SimpleStack.Orm.Logging.MicrosoftExtensions/SimpleStack.Orm.Logging.MicrosoftExtensions.csproj b/src/SimpleStack.Orm.Logging.MicrosoftExtensions/SimpleStack.Orm.Logging.MicrosoftExtensions.csproj index e42b897..a1060c2 100644 --- a/src/SimpleStack.Orm.Logging.MicrosoftExtensions/SimpleStack.Orm.Logging.MicrosoftExtensions.csproj +++ b/src/SimpleStack.Orm.Logging.MicrosoftExtensions/SimpleStack.Orm.Logging.MicrosoftExtensions.csproj @@ -6,8 +6,8 @@ - - + + diff --git a/src/SimpleStack.Orm.MySQLConnector/SimpleStack.Orm.MySQLConnector.csproj b/src/SimpleStack.Orm.MySQLConnector/SimpleStack.Orm.MySQLConnector.csproj index 38847e9..7f46cc8 100644 --- a/src/SimpleStack.Orm.MySQLConnector/SimpleStack.Orm.MySQLConnector.csproj +++ b/src/SimpleStack.Orm.MySQLConnector/SimpleStack.Orm.MySQLConnector.csproj @@ -25,7 +25,7 @@ - + diff --git a/src/SimpleStack.Orm.PostgreSQL/SimpleStack.Orm.PostgreSQL.csproj b/src/SimpleStack.Orm.PostgreSQL/SimpleStack.Orm.PostgreSQL.csproj index 6ec33d7..6d87b2c 100644 --- a/src/SimpleStack.Orm.PostgreSQL/SimpleStack.Orm.PostgreSQL.csproj +++ b/src/SimpleStack.Orm.PostgreSQL/SimpleStack.Orm.PostgreSQL.csproj @@ -25,7 +25,7 @@ - + diff --git a/src/SimpleStack.Orm.SDSQLite/SimpleStack.Orm.SDSQLite.csproj b/src/SimpleStack.Orm.SDSQLite/SimpleStack.Orm.SDSQLite.csproj index 2aae8ee..e0f1d1b 100644 --- a/src/SimpleStack.Orm.SDSQLite/SimpleStack.Orm.SDSQLite.csproj +++ b/src/SimpleStack.Orm.SDSQLite/SimpleStack.Orm.SDSQLite.csproj @@ -31,8 +31,8 @@ - - + + diff --git a/src/SimpleStack.Orm.SQLServer/SimpleStack.Orm.SQLServer.csproj b/src/SimpleStack.Orm.SQLServer/SimpleStack.Orm.SQLServer.csproj index ed918e3..c11331a 100644 --- a/src/SimpleStack.Orm.SQLServer/SimpleStack.Orm.SQLServer.csproj +++ b/src/SimpleStack.Orm.SQLServer/SimpleStack.Orm.SQLServer.csproj @@ -25,7 +25,7 @@ - + diff --git a/src/SimpleStack.Orm.SQLite/SimpleStack.Orm.SQLite.csproj b/src/SimpleStack.Orm.SQLite/SimpleStack.Orm.SQLite.csproj index 963ef29..82e7c22 100644 --- a/src/SimpleStack.Orm.SQLite/SimpleStack.Orm.SQLite.csproj +++ b/src/SimpleStack.Orm.SQLite/SimpleStack.Orm.SQLite.csproj @@ -26,8 +26,8 @@ - - + + diff --git a/test/SimpleStack.Orm.Tests/SimpleStack.Orm.Tests.csproj b/test/SimpleStack.Orm.Tests/SimpleStack.Orm.Tests.csproj index b146635..b5c05c2 100644 --- a/test/SimpleStack.Orm.Tests/SimpleStack.Orm.Tests.csproj +++ b/test/SimpleStack.Orm.Tests/SimpleStack.Orm.Tests.csproj @@ -23,10 +23,9 @@ - - - - + + + diff --git a/test/SimpleStack.Orm.xUnit/SimpleStack.Orm.xUnit.csproj b/test/SimpleStack.Orm.xUnit/SimpleStack.Orm.xUnit.csproj index 59fd12b..5c2935e 100644 --- a/test/SimpleStack.Orm.xUnit/SimpleStack.Orm.xUnit.csproj +++ b/test/SimpleStack.Orm.xUnit/SimpleStack.Orm.xUnit.csproj @@ -9,8 +9,11 @@ - - + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + From 11949a92a139d451ba0ddaed56f60f0692d736b5 Mon Sep 17 00:00:00 2001 From: avtc Date: Wed, 1 Feb 2023 21:34:09 +0200 Subject: [PATCH 09/14] Fix: Failed to set binary column to null using Update on MSSQL #37 --- .../MySqlDialectProvider.cs | 2 +- .../MySqlConnectorDialectProvider.cs | 2 +- src/SimpleStack.Orm/DialectProviderBase.cs | 10 ++++---- .../Expressions/Statements/Statement.cs | 23 +++++++++++++++++++ .../Statements/Typed/TypedDeleteStatement.cs | 1 + .../Statements/Typed/TypedInsertStatement.cs | 1 + .../Statements/Typed/TypedUpdateStatement.cs | 2 ++ test/SimpleStack.Orm.Tests/UpdateTests.cs | 18 +++++++++++++-- 8 files changed, 50 insertions(+), 9 deletions(-) diff --git a/src/SimpleStack.Orm.MySQL/MySqlDialectProvider.cs b/src/SimpleStack.Orm.MySQL/MySqlDialectProvider.cs index 316d106..4434e2c 100644 --- a/src/SimpleStack.Orm.MySQL/MySqlDialectProvider.cs +++ b/src/SimpleStack.Orm.MySQL/MySqlDialectProvider.cs @@ -197,7 +197,7 @@ protected virtual DbType GetDbType(string dataType, int? length, string columnTy query.Append(insertStatement.HasIdentity ? SelectIdentitySql : "SELECT 0"); - return new CommandDefinition(query.ToString(), insertStatement.Parameters, flags: flags, cancellationToken: cancellationToken); + return new CommandDefinition(query.ToString(), insertStatement.GetDynamicParameters(), flags: flags, cancellationToken: cancellationToken); } } } \ No newline at end of file diff --git a/src/SimpleStack.Orm.MySQLConnector/MySqlConnectorDialectProvider.cs b/src/SimpleStack.Orm.MySQLConnector/MySqlConnectorDialectProvider.cs index 8cc0506..bc099c6 100644 --- a/src/SimpleStack.Orm.MySQLConnector/MySqlConnectorDialectProvider.cs +++ b/src/SimpleStack.Orm.MySQLConnector/MySqlConnectorDialectProvider.cs @@ -200,7 +200,7 @@ protected virtual DbType GetDbType(string dataType, int? length, string columnTy query.Append(insertStatement.HasIdentity ? SelectIdentitySql : "SELECT 0"); - return new CommandDefinition(query.ToString(), insertStatement.Parameters, flags: flags, cancellationToken: cancellationToken); + return new CommandDefinition(query.ToString(), insertStatement.GetDynamicParameters(), flags: flags, cancellationToken: cancellationToken); } } } \ No newline at end of file diff --git a/src/SimpleStack.Orm/DialectProviderBase.cs b/src/SimpleStack.Orm/DialectProviderBase.cs index 287bcdb..f81ca40 100644 --- a/src/SimpleStack.Orm/DialectProviderBase.cs +++ b/src/SimpleStack.Orm/DialectProviderBase.cs @@ -150,7 +150,7 @@ public virtual string GetQuotedColumnName(string columnName) } - return new CommandDefinition(sql.ToString(), statement.Parameters, flags: flags, cancellationToken:cancellationToken); + return new CommandDefinition(sql.ToString(), statement.GetDynamicParameters(), flags: flags, cancellationToken:cancellationToken); } public virtual CommandDefinition ToCountStatement(CountStatement statement, CommandFlags flags, CancellationToken cancellationToken = new CancellationToken()) @@ -184,7 +184,7 @@ public virtual string GetQuotedColumnName(string columnName) sql.Append(statement.HavingExpression); } - return new CommandDefinition(sql.ToString(), statement.Parameters, flags: flags, cancellationToken:cancellationToken); + return new CommandDefinition(sql.ToString(), statement.GetDynamicParameters(), flags: flags, cancellationToken:cancellationToken); } public virtual CommandDefinition ToDeleteStatement(DeleteStatement statement, CancellationToken cancellationToken = new CancellationToken()) @@ -197,7 +197,7 @@ public virtual string GetQuotedColumnName(string columnName) query.Append(statement.WhereExpression); } - return new CommandDefinition(query.ToString(), statement.Parameters, cancellationToken:cancellationToken); + return new CommandDefinition(query.ToString(), statement.GetDynamicParameters(), cancellationToken:cancellationToken); } public virtual CommandDefinition ToInsertStatement(InsertStatement insertStatement, CommandFlags flags, CancellationToken cancellationToken = new CancellationToken()) @@ -219,7 +219,7 @@ public virtual string GetQuotedColumnName(string columnName) query.Append(insertStatement.HasIdentity ? SelectIdentitySql : "SELECT 0"); - return new CommandDefinition(query.ToString(), insertStatement.Parameters, flags: flags, cancellationToken:cancellationToken); + return new CommandDefinition(query.ToString(), insertStatement.GetDynamicParameters(), flags: flags, cancellationToken:cancellationToken); } public virtual CommandDefinition ToUpdateStatement(UpdateStatement statement, CommandFlags flags, CancellationToken cancellationToken = new CancellationToken()) @@ -248,7 +248,7 @@ public virtual string GetQuotedColumnName(string columnName) query.Append(statement.WhereExpression); } - return new CommandDefinition(query.ToString(), statement.Parameters, flags: flags, cancellationToken:cancellationToken); + return new CommandDefinition(query.ToString(), statement.GetDynamicParameters(), flags: flags, cancellationToken:cancellationToken); } /// Converts a tableType to a create table statement. diff --git a/src/SimpleStack.Orm/Expressions/Statements/Statement.cs b/src/SimpleStack.Orm/Expressions/Statements/Statement.cs index 80e6917..fdffd67 100644 --- a/src/SimpleStack.Orm/Expressions/Statements/Statement.cs +++ b/src/SimpleStack.Orm/Expressions/Statements/Statement.cs @@ -1,3 +1,4 @@ +using Dapper; using System.Collections.Generic; namespace SimpleStack.Orm.Expressions.Statements @@ -6,5 +7,27 @@ public abstract class Statement { public string TableName { get; set; } public IDictionary Parameters { get; } = new Dictionary(); + public IDictionary ParameterDefinitions { get; } = new Dictionary(); + } + + public static class StatementExtensions + { + // This is to fix MSSQL provider error happen on UpdateStatement during update binary column with null value: + // "Implicit conversion from data type nvarchar to varbinary is not allowed. Use the CONVERT function to run this query." + // When null parameter passed as object Dapper do not know the type and by default type is set to DbType.String. + public static DynamicParameters GetDynamicParameters(this Statement statement) + { + var result = new DynamicParameters(); + foreach (var pair in statement.Parameters) + { + if (statement.ParameterDefinitions.TryGetValue(pair.Key, out var definition)) +#pragma warning disable CS0618 // Type or member is obsolete + result.Add(pair.Key, pair.Value, SqlMapper.LookupDbType(definition.FieldType, pair.Key, demand: true, out _)); +#pragma warning restore CS0618 // Type or member is obsolete + else + result.Add(pair.Key, pair.Value); + } + return result; + } } } \ No newline at end of file diff --git a/src/SimpleStack.Orm/Expressions/Statements/Typed/TypedDeleteStatement.cs b/src/SimpleStack.Orm/Expressions/Statements/Typed/TypedDeleteStatement.cs index 4f2a959..850fef4 100644 --- a/src/SimpleStack.Orm/Expressions/Statements/Typed/TypedDeleteStatement.cs +++ b/src/SimpleStack.Orm/Expressions/Statements/Typed/TypedDeleteStatement.cs @@ -37,6 +37,7 @@ public TypedDeleteStatement AddPrimaryKeyWhereCondition(T values) Statement.WhereExpression.Append("="); Statement.WhereExpression.Append(pname); Statement.Parameters.Add(pname, pk.GetValue(values)); + Statement.ParameterDefinitions.Add(pname, pk); } return this; diff --git a/src/SimpleStack.Orm/Expressions/Statements/Typed/TypedInsertStatement.cs b/src/SimpleStack.Orm/Expressions/Statements/Typed/TypedInsertStatement.cs index ab5359d..89292c0 100644 --- a/src/SimpleStack.Orm/Expressions/Statements/Typed/TypedInsertStatement.cs +++ b/src/SimpleStack.Orm/Expressions/Statements/Typed/TypedInsertStatement.cs @@ -55,6 +55,7 @@ public TypedInsertStatement Values(T values, IEnumerable onlyFields) { var pname = _dialectProvider.GetParameterName(Statement.Parameters.Count); Statement.Parameters.Add(pname, v); + Statement.ParameterDefinitions.Add(pname, fieldDef); Statement.InsertFields.Add(_dialectProvider.GetQuotedColumnName(fieldDef.FieldName)); } } diff --git a/src/SimpleStack.Orm/Expressions/Statements/Typed/TypedUpdateStatement.cs b/src/SimpleStack.Orm/Expressions/Statements/Typed/TypedUpdateStatement.cs index ca212da..e57da7c 100644 --- a/src/SimpleStack.Orm/Expressions/Statements/Typed/TypedUpdateStatement.cs +++ b/src/SimpleStack.Orm/Expressions/Statements/Typed/TypedUpdateStatement.cs @@ -86,6 +86,7 @@ private TypedUpdateStatement Values(object values, IEnumerable onlyFi var pname = _dialectProvider.GetParameterName(Statement.Parameters.Count); Statement.UpdateFields.Add(_dialectProvider.GetQuotedColumnName(fieldDef.FieldName), pname); Statement.Parameters.Add(pname, fieldDef.GetValue(values)); + Statement.ParameterDefinitions.Add(pname, fieldDef); } //Add Primarykey filter if required @@ -104,6 +105,7 @@ private TypedUpdateStatement Values(object values, IEnumerable onlyFi Statement.WhereExpression.Append("="); Statement.WhereExpression.Append(pname); Statement.Parameters.Add(pname, pk.GetValue(values)); + Statement.ParameterDefinitions.Add(pname, pk); } } diff --git a/test/SimpleStack.Orm.Tests/UpdateTests.cs b/test/SimpleStack.Orm.Tests/UpdateTests.cs index bcb01be..5fb2895 100644 --- a/test/SimpleStack.Orm.Tests/UpdateTests.cs +++ b/test/SimpleStack.Orm.Tests/UpdateTests.cs @@ -31,16 +31,28 @@ public class ModelWithFieldsOfDifferentTypes /// true if , false if not. public bool Bool { get; set; } + public bool? NullBool { get; set; } + /// Gets or sets the date time. /// The date time. public DateTime DateTime { get; set; } + public DateTime? NullDateTime { get; set; } + /// Gets or sets the double. /// The double. public double Double { get; set; } + public double? NullDouble { get; set; } + public Guid Guid { get; set; } + public Guid? NullGuid { get; set; } + + public byte[] Bytes { get; set; } + + public byte[] NullBytes { get; set; } + /// Creates a new ModelWithFieldsOfDifferentTypes. /// The identifier. /// The ModelWithFieldsOfDifferentTypes. @@ -53,7 +65,8 @@ public static ModelWithFieldsOfDifferentTypes Create(int id) Double = 1.11d + id, LongId = 999 + id, Name = "Name" + id, - Guid = Guid.NewGuid() + Guid = Guid.NewGuid(), + Bytes = new[] { (byte)(id % 256) }, }; return row; @@ -71,7 +84,8 @@ public static ModelWithFieldsOfDifferentTypes CreateConstant(int id) Double = 1.11d + id, LongId = 999 + id, Name = "Name" + id, - Guid = Guid.Empty + Guid = Guid.Empty, + Bytes = new[] { (byte)(id % 256) }, }; return row; From d61e0538ac575bec3445bcdb672d32c7ad29e703 Mon Sep 17 00:00:00 2001 From: Vincent DARON Date: Wed, 8 Feb 2023 18:02:30 +0100 Subject: [PATCH 10/14] Review Statement parameters to make it more generic --- .../MySqlDialectProvider.cs | 4 +- .../MySqlConnectorDialectProvider.cs | 4 +- .../SqlServerOrmLiteDialectProvider.cs | 6 +-- src/SimpleStack.Orm/DialectProviderBase.cs | 25 +++++----- ...tor.cs => ColumnWhereExpressionVisitor.cs} | 7 +-- .../Expressions/ExpressionVisitor.cs | 24 +++++---- .../Dynamic/DynamicCountStatement.cs | 6 +-- .../Expressions/Statements/Statement.cs | 50 ++++++++++++------- .../Statements/Typed/TypedDeleteStatement.cs | 3 +- .../Statements/Typed/TypedInsertStatement.cs | 3 +- .../Statements/Typed/TypedUpdateStatement.cs | 6 +-- .../TableFieldsExpresionVisitor.cs | 3 +- .../Expressions/TableWhereExpresionVisitor.cs | 3 +- src/SimpleStack.Orm/IDialectProvider.cs | 2 +- 14 files changed, 82 insertions(+), 64 deletions(-) rename src/SimpleStack.Orm/Expressions/{ColumnWhereExpresionVisitor.cs => ColumnWhereExpressionVisitor.cs} (96%) diff --git a/src/SimpleStack.Orm.MySQL/MySqlDialectProvider.cs b/src/SimpleStack.Orm.MySQL/MySqlDialectProvider.cs index 4434e2c..454b99d 100644 --- a/src/SimpleStack.Orm.MySQL/MySqlDialectProvider.cs +++ b/src/SimpleStack.Orm.MySQL/MySqlDialectProvider.cs @@ -191,13 +191,13 @@ protected virtual DbType GetDbType(string dataType, int? length, string columnTy if (insertStatement.Parameters.Any()) { - query.Append(insertStatement.Parameters.Select(x => x.Key).Aggregate((x, y) => x + ", " + y)); + query.Append(insertStatement.Parameters.Select(x => x.ParameterName).Aggregate((x, y) => x + ", " + y)); } query.Append(");"); query.Append(insertStatement.HasIdentity ? SelectIdentitySql : "SELECT 0"); - return new CommandDefinition(query.ToString(), insertStatement.GetDynamicParameters(), flags: flags, cancellationToken: cancellationToken); + return new CommandDefinition(query.ToString(), insertStatement.Parameters.ToDynamicParameters(), flags: flags, cancellationToken: cancellationToken); } } } \ No newline at end of file diff --git a/src/SimpleStack.Orm.MySQLConnector/MySqlConnectorDialectProvider.cs b/src/SimpleStack.Orm.MySQLConnector/MySqlConnectorDialectProvider.cs index bc099c6..b25ee29 100644 --- a/src/SimpleStack.Orm.MySQLConnector/MySqlConnectorDialectProvider.cs +++ b/src/SimpleStack.Orm.MySQLConnector/MySqlConnectorDialectProvider.cs @@ -194,13 +194,13 @@ protected virtual DbType GetDbType(string dataType, int? length, string columnTy if (insertStatement.Parameters.Any()) { - query.Append(insertStatement.Parameters.Select(x => x.Key).Aggregate((x, y) => x + ", " + y)); + query.Append(insertStatement.Parameters.Select(x => x.ParameterName).Aggregate((x, y) => x + ", " + y)); } query.Append(");"); query.Append(insertStatement.HasIdentity ? SelectIdentitySql : "SELECT 0"); - return new CommandDefinition(query.ToString(), insertStatement.GetDynamicParameters(), flags: flags, cancellationToken: cancellationToken); + return new CommandDefinition(query.ToString(), insertStatement.Parameters.ToDynamicParameters(), flags: flags, cancellationToken: cancellationToken); } } } \ No newline at end of file diff --git a/src/SimpleStack.Orm.SQLServer/SqlServerOrmLiteDialectProvider.cs b/src/SimpleStack.Orm.SQLServer/SqlServerOrmLiteDialectProvider.cs index 33e400e..9fd20e3 100644 --- a/src/SimpleStack.Orm.SQLServer/SqlServerOrmLiteDialectProvider.cs +++ b/src/SimpleStack.Orm.SQLServer/SqlServerOrmLiteDialectProvider.cs @@ -197,7 +197,7 @@ public override string GetDatePartFunction(string name, string quotedColName) return $"DATEPART({name.ToLower()},{quotedColName})"; } - public override string GetStringFunction(string functionName, string quotedColumnName, IDictionary parameters, + public override string GetStringFunction(string functionName, string quotedColumnName, StatementParameters parameters, params string[] availableParameters) { switch (functionName.ToLower()) @@ -208,8 +208,8 @@ public override string GetStringFunction(string functionName, string quotedColum return $"ltrim(rtrim({quotedColumnName}))"; case "substring": //Ensure Offset is start at 1 instead of 0 - int offset = ((int) parameters[availableParameters[0]]) + 1; - parameters[availableParameters[0]] = offset; + int offset = ((int) parameters[availableParameters[0]].Value) + 1; + parameters[availableParameters[0]].Value = offset; if (parameters.Count == 2) { diff --git a/src/SimpleStack.Orm/DialectProviderBase.cs b/src/SimpleStack.Orm/DialectProviderBase.cs index f81ca40..5439734 100644 --- a/src/SimpleStack.Orm/DialectProviderBase.cs +++ b/src/SimpleStack.Orm/DialectProviderBase.cs @@ -150,7 +150,7 @@ public virtual string GetQuotedColumnName(string columnName) } - return new CommandDefinition(sql.ToString(), statement.GetDynamicParameters(), flags: flags, cancellationToken:cancellationToken); + return new CommandDefinition(sql.ToString(), statement.Parameters.ToDynamicParameters(), flags: flags, cancellationToken:cancellationToken); } public virtual CommandDefinition ToCountStatement(CountStatement statement, CommandFlags flags, CancellationToken cancellationToken = new CancellationToken()) @@ -184,7 +184,7 @@ public virtual string GetQuotedColumnName(string columnName) sql.Append(statement.HavingExpression); } - return new CommandDefinition(sql.ToString(), statement.GetDynamicParameters(), flags: flags, cancellationToken:cancellationToken); + return new CommandDefinition(sql.ToString(), statement.Parameters.ToDynamicParameters(), flags: flags, cancellationToken:cancellationToken); } public virtual CommandDefinition ToDeleteStatement(DeleteStatement statement, CancellationToken cancellationToken = new CancellationToken()) @@ -197,7 +197,7 @@ public virtual string GetQuotedColumnName(string columnName) query.Append(statement.WhereExpression); } - return new CommandDefinition(query.ToString(), statement.GetDynamicParameters(), cancellationToken:cancellationToken); + return new CommandDefinition(query.ToString(), statement.Parameters.ToDynamicParameters(), cancellationToken:cancellationToken); } public virtual CommandDefinition ToInsertStatement(InsertStatement insertStatement, CommandFlags flags, CancellationToken cancellationToken = new CancellationToken()) @@ -209,7 +209,7 @@ public virtual string GetQuotedColumnName(string columnName) query.Append(" ("); query.Append(insertStatement.InsertFields.Aggregate((x, y) => x + ", " + y)); query.Append(" ) VALUES ("); - query.Append(insertStatement.Parameters.Select(x => x.Key).Aggregate((x, y) => x + ", " + y)); + query.Append(insertStatement.Parameters.Select(x => x.ParameterName).Aggregate((x, y) => x + ", " + y)); query.Append(");"); } else @@ -219,7 +219,7 @@ public virtual string GetQuotedColumnName(string columnName) query.Append(insertStatement.HasIdentity ? SelectIdentitySql : "SELECT 0"); - return new CommandDefinition(query.ToString(), insertStatement.GetDynamicParameters(), flags: flags, cancellationToken:cancellationToken); + return new CommandDefinition(query.ToString(), insertStatement.Parameters.ToDynamicParameters(), flags: flags, cancellationToken:cancellationToken); } public virtual CommandDefinition ToUpdateStatement(UpdateStatement statement, CommandFlags flags, CancellationToken cancellationToken = new CancellationToken()) @@ -248,7 +248,7 @@ public virtual string GetQuotedColumnName(string columnName) query.Append(statement.WhereExpression); } - return new CommandDefinition(query.ToString(), statement.GetDynamicParameters(), flags: flags, cancellationToken:cancellationToken); + return new CommandDefinition(query.ToString(), statement.Parameters.ToDynamicParameters(), flags: flags, cancellationToken:cancellationToken); } /// Converts a tableType to a create table statement. @@ -539,7 +539,7 @@ public virtual string BindOperand(ExpressionType e, bool isIntegral) } public virtual string GetStringFunction(string functionName, string quotedColumnName, - IDictionary parameters, params string[] availableParameters) + StatementParameters parameters, params string[] availableParameters) { switch (functionName.ToLower()) { @@ -556,19 +556,18 @@ public virtual string GetStringFunction(string functionName, string quotedColumn case "tolower": return $"lower({quotedColumnName})"; case "startswith": - parameters[availableParameters[0]] = parameters[availableParameters[0]].ToString().ToUpper() + "%"; + parameters[availableParameters[0]].Value = parameters[availableParameters[0]].Value.ToString().ToUpper() + "%"; return $"upper({quotedColumnName}) LIKE {availableParameters[0]} "; case "endswith": - parameters[availableParameters[0]] = "%" + parameters[availableParameters[0]].ToString().ToUpper(); + parameters[availableParameters[0]].Value = "%" + parameters[availableParameters[0]].Value.ToString().ToUpper(); return $"upper({quotedColumnName}) LIKE {availableParameters[0]} "; case "contains": - parameters[availableParameters[0]] = - "%" + parameters[availableParameters[0]].ToString().ToUpper() + "%"; + parameters[availableParameters[0]].Value = "%" + parameters[availableParameters[0]].Value.ToString().ToUpper() + "%"; return $"upper({quotedColumnName}) LIKE {availableParameters[0]} "; case "substring": //Ensure Offset is start at 1 instead of 0 - var offset = (int) parameters[availableParameters[0]] + 1; - parameters[availableParameters[0]] = offset; + var offset = (int) parameters[availableParameters[0]].Value + 1; + parameters[availableParameters[0]].Value = offset; if (parameters.Count == 2) { diff --git a/src/SimpleStack.Orm/Expressions/ColumnWhereExpresionVisitor.cs b/src/SimpleStack.Orm/Expressions/ColumnWhereExpressionVisitor.cs similarity index 96% rename from src/SimpleStack.Orm/Expressions/ColumnWhereExpresionVisitor.cs rename to src/SimpleStack.Orm/Expressions/ColumnWhereExpressionVisitor.cs index c0752b2..33c66e0 100644 --- a/src/SimpleStack.Orm/Expressions/ColumnWhereExpresionVisitor.cs +++ b/src/SimpleStack.Orm/Expressions/ColumnWhereExpressionVisitor.cs @@ -2,15 +2,16 @@ using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; +using SimpleStack.Orm.Expressions.Statements; namespace SimpleStack.Orm.Expressions { - internal class ColumnWhereExpresionVisitor : ExpressionVisitor + internal class ColumnWhereExpressionVisitor : ExpressionVisitor { private readonly string _statement; - public ColumnWhereExpresionVisitor(IDialectProvider dialectProvider, - IDictionary parameters, + public ColumnWhereExpressionVisitor(IDialectProvider dialectProvider, + StatementParameters parameters, string statement) : base(dialectProvider, parameters) { diff --git a/src/SimpleStack.Orm/Expressions/ExpressionVisitor.cs b/src/SimpleStack.Orm/Expressions/ExpressionVisitor.cs index 87e0629..3b1a6ec 100644 --- a/src/SimpleStack.Orm/Expressions/ExpressionVisitor.cs +++ b/src/SimpleStack.Orm/Expressions/ExpressionVisitor.cs @@ -5,16 +5,17 @@ using System.Linq.Expressions; using System.Reflection; using System.Text; +using SimpleStack.Orm.Expressions.Statements; namespace SimpleStack.Orm.Expressions { internal abstract class ExpressionVisitor { protected readonly IDialectProvider DialectProvider; - protected readonly IDictionary Parameters; + protected readonly StatementParameters Parameters; protected ExpressionVisitor(IDialectProvider dialectProvider, - IDictionary parameters) + StatementParameters parameters) { DialectProvider = dialectProvider; Parameters = parameters; @@ -31,7 +32,7 @@ public virtual string VisitExpression(Expression exp) if (statement is ParameterPart pp) { - return (bool) Parameters[pp.Text] ? "1=1" : "1=0"; + return (bool) Parameters[pp.Text].Value ? "1=1" : "1=0"; } if (statement is ColumnAccessPart cp) @@ -236,7 +237,7 @@ protected virtual StatementPart VisitUnary(UnaryExpression unaryExpression) if (o is ParameterPart op && op.ParameterType == typeof(bool)) { - Parameters[op.Text] = !(bool) Parameters[op.Text]; + Parameters[op.Text].Value = !(bool) Parameters[op.Text].Value; return o; } @@ -310,7 +311,7 @@ protected virtual StatementPart VisitBinary(BinaryExpression binaryExpression) if (leftp?.ParameterType == typeof(bool) || rightp?.ParameterType == typeof(bool)) { - var boolValue = (bool) (leftp != null ? Parameters[leftp.Text] : Parameters[rightp.Text]); + var boolValue = (bool) (leftp != null ? Parameters[leftp.Text].Value : Parameters[rightp.Text].Value); if (operand == "AND") { if (boolValue) @@ -336,12 +337,12 @@ protected virtual StatementPart VisitBinary(BinaryExpression binaryExpression) { if (leftca != null && leftca.ColumnType.IsEnum() && rightp != null) { - Parameters[rightp.Text] = Enum.ToObject(leftca.ColumnType, Parameters[rightp.Text]); + Parameters[rightp.Text].Value = Enum.ToObject(leftca.ColumnType, Parameters[rightp.Text].Value); } if (rightca != null && rightca.ColumnType.IsEnum() && leftp != null) { - Parameters[leftp.Text] = Enum.ToObject(rightca.ColumnType, Parameters[leftp.Text]); + Parameters[leftp.Text].Value = Enum.ToObject(rightca.ColumnType, Parameters[leftp.Text].Value); } } @@ -432,9 +433,12 @@ protected virtual StatementPart VisitDateTimeMemberAccess(MemberExpression m) /// protected ParameterPart AddParameter(object param) { - var paramName = DialectProvider.GetParameterName(Parameters.Count); - Parameters.Add(paramName, param); - return new ParameterPart(paramName, param.GetType()); + var statementParameter = new StatementParameter( + DialectProvider.GetParameterName(Parameters.Count), + param.GetType(), + param); + Parameters.Add(statementParameter); + return new ParameterPart(statementParameter.ParameterName, statementParameter.Type); } protected class StatementPart diff --git a/src/SimpleStack.Orm/Expressions/Statements/Dynamic/DynamicCountStatement.cs b/src/SimpleStack.Orm/Expressions/Statements/Dynamic/DynamicCountStatement.cs index 6bb05a0..2f308db 100644 --- a/src/SimpleStack.Orm/Expressions/Statements/Dynamic/DynamicCountStatement.cs +++ b/src/SimpleStack.Orm/Expressions/Statements/Dynamic/DynamicCountStatement.cs @@ -65,7 +65,7 @@ public DynamicCountStatement Having(string columnName, Expression(_dialectProvider, Statement.Parameters, + new ColumnWhereExpressionVisitor(_dialectProvider, Statement.Parameters, _dialectProvider.GetQuotedColumnName(columnName)) .VisitExpression(predicate)); } @@ -87,9 +87,9 @@ public DynamicCountStatement OrRaw(string condition) return Where(condition, "OR"); } - internal ColumnWhereExpresionVisitor GetExpressionVisitor(string columnOrExpression) + internal ColumnWhereExpressionVisitor GetExpressionVisitor(string columnOrExpression) { - return new ColumnWhereExpresionVisitor(_dialectProvider, Statement.Parameters, columnOrExpression); + return new ColumnWhereExpressionVisitor(_dialectProvider, Statement.Parameters, columnOrExpression); } internal DynamicCountStatement Where(ExpressionVisitor visitor, Expression> func, diff --git a/src/SimpleStack.Orm/Expressions/Statements/Statement.cs b/src/SimpleStack.Orm/Expressions/Statements/Statement.cs index fdffd67..87e80ea 100644 --- a/src/SimpleStack.Orm/Expressions/Statements/Statement.cs +++ b/src/SimpleStack.Orm/Expressions/Statements/Statement.cs @@ -1,33 +1,49 @@ +using System; using Dapper; using System.Collections.Generic; +using System.Collections.ObjectModel; namespace SimpleStack.Orm.Expressions.Statements { - public abstract class Statement - { - public string TableName { get; set; } - public IDictionary Parameters { get; } = new Dictionary(); - public IDictionary ParameterDefinitions { get; } = new Dictionary(); - } - - public static class StatementExtensions + public class StatementParameters : KeyedCollection { - // This is to fix MSSQL provider error happen on UpdateStatement during update binary column with null value: - // "Implicit conversion from data type nvarchar to varbinary is not allowed. Use the CONVERT function to run this query." - // When null parameter passed as object Dapper do not know the type and by default type is set to DbType.String. - public static DynamicParameters GetDynamicParameters(this Statement statement) + protected override string GetKeyForItem(StatementParameter item) + { + return item.ParameterName; + } + + public DynamicParameters ToDynamicParameters() { var result = new DynamicParameters(); - foreach (var pair in statement.Parameters) + foreach (var pair in this) { - if (statement.ParameterDefinitions.TryGetValue(pair.Key, out var definition)) #pragma warning disable CS0618 // Type or member is obsolete - result.Add(pair.Key, pair.Value, SqlMapper.LookupDbType(definition.FieldType, pair.Key, demand: true, out _)); + result.Add(pair.ParameterName, pair.Value, + SqlMapper.LookupDbType(pair.Type, pair.ParameterName, demand: true, out _)); #pragma warning restore CS0618 // Type or member is obsolete - else - result.Add(pair.Key, pair.Value); } + return result; } } + + public class StatementParameter + { + public string ParameterName { get; } + public Type Type { get; } + public object Value { get; set; } + + public StatementParameter(string parameterName, Type type, object value) + { + ParameterName = parameterName; + Type = type; + Value = value; + } + } + + public abstract class Statement + { + public string TableName { get; set; } + public StatementParameters Parameters { get; } = new StatementParameters(); + } } \ No newline at end of file diff --git a/src/SimpleStack.Orm/Expressions/Statements/Typed/TypedDeleteStatement.cs b/src/SimpleStack.Orm/Expressions/Statements/Typed/TypedDeleteStatement.cs index 850fef4..bc6d36c 100644 --- a/src/SimpleStack.Orm/Expressions/Statements/Typed/TypedDeleteStatement.cs +++ b/src/SimpleStack.Orm/Expressions/Statements/Typed/TypedDeleteStatement.cs @@ -36,8 +36,7 @@ public TypedDeleteStatement AddPrimaryKeyWhereCondition(T values) Statement.WhereExpression.Append(_dialectProvider.GetQuotedColumnName(pk.FieldName)); Statement.WhereExpression.Append("="); Statement.WhereExpression.Append(pname); - Statement.Parameters.Add(pname, pk.GetValue(values)); - Statement.ParameterDefinitions.Add(pname, pk); + Statement.Parameters.Add(new StatementParameter(pname,pk.FieldType, pk.GetValue(values))); } return this; diff --git a/src/SimpleStack.Orm/Expressions/Statements/Typed/TypedInsertStatement.cs b/src/SimpleStack.Orm/Expressions/Statements/Typed/TypedInsertStatement.cs index 89292c0..ea56d87 100644 --- a/src/SimpleStack.Orm/Expressions/Statements/Typed/TypedInsertStatement.cs +++ b/src/SimpleStack.Orm/Expressions/Statements/Typed/TypedInsertStatement.cs @@ -54,8 +54,7 @@ public TypedInsertStatement Values(T values, IEnumerable onlyFields) if (v != null) { var pname = _dialectProvider.GetParameterName(Statement.Parameters.Count); - Statement.Parameters.Add(pname, v); - Statement.ParameterDefinitions.Add(pname, fieldDef); + Statement.Parameters.Add(new StatementParameter(pname,fieldDef.FieldType,v)); Statement.InsertFields.Add(_dialectProvider.GetQuotedColumnName(fieldDef.FieldName)); } } diff --git a/src/SimpleStack.Orm/Expressions/Statements/Typed/TypedUpdateStatement.cs b/src/SimpleStack.Orm/Expressions/Statements/Typed/TypedUpdateStatement.cs index e57da7c..52607f4 100644 --- a/src/SimpleStack.Orm/Expressions/Statements/Typed/TypedUpdateStatement.cs +++ b/src/SimpleStack.Orm/Expressions/Statements/Typed/TypedUpdateStatement.cs @@ -85,8 +85,7 @@ private TypedUpdateStatement Values(object values, IEnumerable onlyFi { var pname = _dialectProvider.GetParameterName(Statement.Parameters.Count); Statement.UpdateFields.Add(_dialectProvider.GetQuotedColumnName(fieldDef.FieldName), pname); - Statement.Parameters.Add(pname, fieldDef.GetValue(values)); - Statement.ParameterDefinitions.Add(pname, fieldDef); + Statement.Parameters.Add(new StatementParameter(pname,fieldDef.FieldType, fieldDef.GetValue(values))); } //Add Primarykey filter if required @@ -104,8 +103,7 @@ private TypedUpdateStatement Values(object values, IEnumerable onlyFi Statement.WhereExpression.Append(_dialectProvider.GetQuotedColumnName(pk.FieldName)); Statement.WhereExpression.Append("="); Statement.WhereExpression.Append(pname); - Statement.Parameters.Add(pname, pk.GetValue(values)); - Statement.ParameterDefinitions.Add(pname, pk); + Statement.Parameters.Add(new StatementParameter(pname,pk.FieldType, pk.GetValue(values))); } } diff --git a/src/SimpleStack.Orm/Expressions/TableFieldsExpresionVisitor.cs b/src/SimpleStack.Orm/Expressions/TableFieldsExpresionVisitor.cs index 5491754..94ca3f9 100644 --- a/src/SimpleStack.Orm/Expressions/TableFieldsExpresionVisitor.cs +++ b/src/SimpleStack.Orm/Expressions/TableFieldsExpresionVisitor.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Linq.Expressions; using System.Reflection; +using SimpleStack.Orm.Expressions.Statements; namespace SimpleStack.Orm.Expressions { @@ -13,7 +14,7 @@ internal sealed class TableWFieldsExpresionVisitor : ExpressionVisitor private readonly ModelDefinition _modelDefinition; public TableWFieldsExpresionVisitor(IDialectProvider dialectProvider, - IDictionary parameters, + StatementParameters parameters, ModelDefinition modelDefinition, bool addAliasSpecification) : base(dialectProvider, parameters) diff --git a/src/SimpleStack.Orm/Expressions/TableWhereExpresionVisitor.cs b/src/SimpleStack.Orm/Expressions/TableWhereExpresionVisitor.cs index fca5486..59467c8 100644 --- a/src/SimpleStack.Orm/Expressions/TableWhereExpresionVisitor.cs +++ b/src/SimpleStack.Orm/Expressions/TableWhereExpresionVisitor.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Linq.Expressions; using System.Reflection; +using SimpleStack.Orm.Expressions.Statements; namespace SimpleStack.Orm.Expressions { @@ -11,7 +12,7 @@ internal class TableWhereExpresionVisitor : ExpressionVisitor private readonly ModelDefinition _modelDefinition; public TableWhereExpresionVisitor(IDialectProvider dialectProvider, - IDictionary parameters, + StatementParameters parameters, ModelDefinition modelDefinition) : base(dialectProvider, parameters) { diff --git a/src/SimpleStack.Orm/IDialectProvider.cs b/src/SimpleStack.Orm/IDialectProvider.cs index d48de98..75d9d01 100644 --- a/src/SimpleStack.Orm/IDialectProvider.cs +++ b/src/SimpleStack.Orm/IDialectProvider.cs @@ -201,7 +201,7 @@ Task> GetTableDefinitions(IDbConnection connection string BindOperand(ExpressionType e, bool isIntegral); - string GetStringFunction(string functionName, string quotedColumnName, IDictionary parameters, + string GetStringFunction(string functionName, string quotedColumnName, StatementParameters parameters, params string[] availableParameters); } } \ No newline at end of file From 3a931548332f46055b322ec3289543c84b4a99c4 Mon Sep 17 00:00:00 2001 From: Vincent DARON Date: Wed, 8 Feb 2023 18:06:50 +0100 Subject: [PATCH 11/14] Add CancellationToken support of FirstAsync and FirstOrDefaultAsync --- src/SimpleStack.Orm/OrmConnectionAsync.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/SimpleStack.Orm/OrmConnectionAsync.cs b/src/SimpleStack.Orm/OrmConnectionAsync.cs index f35171f..8ea53e2 100644 --- a/src/SimpleStack.Orm/OrmConnectionAsync.cs +++ b/src/SimpleStack.Orm/OrmConnectionAsync.cs @@ -95,13 +95,13 @@ public Task> SelectAsync(Action> expre /// /// /// If the query does not returns any element - public async Task FirstAsync(Expression> predicate) + public async Task FirstAsync(Expression> predicate, CancellationToken cancellationToken = new CancellationToken()) { var r = await SelectAsync(x => { x.Where(predicate); x.Limit(1); - }).ConfigureAwait(false); + }, cancellationToken: cancellationToken).ConfigureAwait(false); return r.First(); } @@ -112,13 +112,13 @@ public async Task FirstAsync(Expression> predicate) /// /// /// If the query does not returns any element - public async Task FirstAsync(Action> expression) + public async Task FirstAsync(Action> expression, CancellationToken cancellationToken = new CancellationToken()) { var r = await SelectAsync(x => { expression(x); x.Limit(1); - }).ConfigureAwait(false); + }, cancellationToken: cancellationToken).ConfigureAwait(false); return r.First(); } @@ -128,13 +128,13 @@ public async Task FirstAsync(Action> expression) /// Where clause /// /// - public async Task FirstOrDefaultAsync(Expression> predicate) + public async Task FirstOrDefaultAsync(Expression> predicate, CancellationToken cancellationToken = new CancellationToken()) { var r = await SelectAsync(x => { x.Where(predicate); x.Limit(1); - }).ConfigureAwait(false); + }, cancellationToken: cancellationToken).ConfigureAwait(false); return r.FirstOrDefault(); } @@ -144,13 +144,13 @@ public async Task FirstOrDefaultAsync(Expression> predicate) /// /// /// - public async Task FirstOrDefaultAsync(Action> expression) + public async Task FirstOrDefaultAsync(Action> expression, CancellationToken cancellationToken = new CancellationToken()) { var r = await SelectAsync(x => { expression(x); x.Limit(1); - }).ConfigureAwait(false); + }, cancellationToken: cancellationToken).ConfigureAwait(false); return r.FirstOrDefault(); } From 11253496a8715bb5bb3891e4d8e60a80be094670 Mon Sep 17 00:00:00 2001 From: Vincent DARON Date: Sun, 2 Jun 2024 09:55:30 +0200 Subject: [PATCH 12/14] Migrate to Net6 and Net8 Keep netstandard for SimpleStack.Orm.SDSQlite Update all dependencies --- ...SimpleStack.Orm.Logging.MicrosoftExtensions.csproj | 6 +++--- .../SimpleStack.Orm.MySQL.csproj | 5 +++-- .../SimpleStack.Orm.MySQLConnector.csproj | 5 +++-- .../SimpleStack.Orm.PostgreSQL.csproj | 5 +++-- .../SimpleStack.Orm.SDSQLite.csproj | 11 ++++------- .../SimpleStack.Orm.SQLServer.csproj | 5 +++-- .../SimpleStack.Orm.SQLite.csproj | 7 ++++--- src/SimpleStack.Orm/SimpleStack.Orm.csproj | 3 ++- .../SimpleStack.Orm.Tests.csproj | 3 ++- 9 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/SimpleStack.Orm.Logging.MicrosoftExtensions/SimpleStack.Orm.Logging.MicrosoftExtensions.csproj b/src/SimpleStack.Orm.Logging.MicrosoftExtensions/SimpleStack.Orm.Logging.MicrosoftExtensions.csproj index a1060c2..b518708 100644 --- a/src/SimpleStack.Orm.Logging.MicrosoftExtensions/SimpleStack.Orm.Logging.MicrosoftExtensions.csproj +++ b/src/SimpleStack.Orm.Logging.MicrosoftExtensions/SimpleStack.Orm.Logging.MicrosoftExtensions.csproj @@ -1,13 +1,13 @@ - netstandard2.0 1.2.5 + net6.0;net8.0 + latestmajor - - + diff --git a/src/SimpleStack.Orm.MySQL/SimpleStack.Orm.MySQL.csproj b/src/SimpleStack.Orm.MySQL/SimpleStack.Orm.MySQL.csproj index 271e7f2..f32ec08 100644 --- a/src/SimpleStack.Orm.MySQL/SimpleStack.Orm.MySQL.csproj +++ b/src/SimpleStack.Orm.MySQL/SimpleStack.Orm.MySQL.csproj @@ -4,7 +4,7 @@ MySQL Provider for SimpleStack.Orm 1.0.2 SimpleStack Team;NServiceKit;ServiceStack - netstandard2.0 + net6.0;net8.0 SimpleStack.Orm.MySQL SimpleStack.Orm.MySQL MySQL;SimpleStack;Orm @@ -20,6 +20,7 @@ https://simplestack.org/ https://github.com/SimpleStack/simplestack.orm git + latestmajor @@ -27,7 +28,7 @@ - + diff --git a/src/SimpleStack.Orm.MySQLConnector/SimpleStack.Orm.MySQLConnector.csproj b/src/SimpleStack.Orm.MySQLConnector/SimpleStack.Orm.MySQLConnector.csproj index 7f46cc8..40aa58b 100644 --- a/src/SimpleStack.Orm.MySQLConnector/SimpleStack.Orm.MySQLConnector.csproj +++ b/src/SimpleStack.Orm.MySQLConnector/SimpleStack.Orm.MySQLConnector.csproj @@ -15,9 +15,10 @@ 1.2.0.0 1.2.0.0 1.2.5 - netstandard2.0 https://simplestack.org/ https://github.com/SimpleStack/simplestack.orm + net6.0;net8.0 + latestmajor @@ -25,7 +26,7 @@ - + diff --git a/src/SimpleStack.Orm.PostgreSQL/SimpleStack.Orm.PostgreSQL.csproj b/src/SimpleStack.Orm.PostgreSQL/SimpleStack.Orm.PostgreSQL.csproj index 6d87b2c..fe5dba5 100644 --- a/src/SimpleStack.Orm.PostgreSQL/SimpleStack.Orm.PostgreSQL.csproj +++ b/src/SimpleStack.Orm.PostgreSQL/SimpleStack.Orm.PostgreSQL.csproj @@ -4,7 +4,7 @@ PostgreSQL Provider for SimpleStack.Orm 1.0.2 SimpleStack Team;NServiceKit;ServiceStack - netstandard2.0 + net6.0;net8.0 SimpleStack.Orm.PostgreSQL SimpleStack.Orm.PostgreSQL npgsql;SimpleStack;PostgreSQL @@ -18,6 +18,7 @@ 1.2.5 https://simplestack.org/ https://github.com/SimpleStack/simplestack.orm + latestmajor @@ -25,7 +26,7 @@ - + diff --git a/src/SimpleStack.Orm.SDSQLite/SimpleStack.Orm.SDSQLite.csproj b/src/SimpleStack.Orm.SDSQLite/SimpleStack.Orm.SDSQLite.csproj index e0f1d1b..63aa361 100644 --- a/src/SimpleStack.Orm.SDSQLite/SimpleStack.Orm.SDSQLite.csproj +++ b/src/SimpleStack.Orm.SDSQLite/SimpleStack.Orm.SDSQLite.csproj @@ -4,7 +4,7 @@ SQLite Provider for SimpleStack.Orm based on System.Data.Sqlite 1.0.2 SimpleStack Team;NServiceKit;ServiceStack - netstandard2.0 + netstandard2.1 SimpleStack.Orm.SDSQLite SimpleStack.Orm.SDSQLite System.Data.Sqlite;SimpleStack;Sqlite @@ -19,10 +19,7 @@ SimpleStack.Orm.SDSQlite https://simplestack.org/ https://github.com/SimpleStack/simplestack.orm - - - - netstandard2.0 + latestmajor @@ -31,8 +28,8 @@ - - + + diff --git a/src/SimpleStack.Orm.SQLServer/SimpleStack.Orm.SQLServer.csproj b/src/SimpleStack.Orm.SQLServer/SimpleStack.Orm.SQLServer.csproj index c11331a..0c6bb07 100644 --- a/src/SimpleStack.Orm.SQLServer/SimpleStack.Orm.SQLServer.csproj +++ b/src/SimpleStack.Orm.SQLServer/SimpleStack.Orm.SQLServer.csproj @@ -15,9 +15,10 @@ 1.2.0.0 1.2.0.0 1.2.5 - netstandard2.0 https://simplestack.org/ https://github.com/SimpleStack/simplestack.orm + net6.0;net8.0 + latestmajor @@ -25,7 +26,7 @@ - + diff --git a/src/SimpleStack.Orm.SQLite/SimpleStack.Orm.SQLite.csproj b/src/SimpleStack.Orm.SQLite/SimpleStack.Orm.SQLite.csproj index 82e7c22..2058a18 100644 --- a/src/SimpleStack.Orm.SQLite/SimpleStack.Orm.SQLite.csproj +++ b/src/SimpleStack.Orm.SQLite/SimpleStack.Orm.SQLite.csproj @@ -4,7 +4,7 @@ SQLite Provider for SimpleStack.Orm based on Microsoft.Data.Sqlite 1.0.2 SimpleStack Team;NServiceKit;ServiceStack - netstandard2.0 + net6.0;net8.0 SimpleStack.Orm.SQLite SimpleStack.Orm.SQLite Microsoft.Data.Sqlite;SimpleStack;Sqlite @@ -18,6 +18,7 @@ 1.2.5 https://simplestack.org/ https://github.com/SimpleStack/simplestack.orm + latestmajor @@ -26,8 +27,8 @@ - - + + diff --git a/src/SimpleStack.Orm/SimpleStack.Orm.csproj b/src/SimpleStack.Orm/SimpleStack.Orm.csproj index f570e93..66a89df 100644 --- a/src/SimpleStack.Orm/SimpleStack.Orm.csproj +++ b/src/SimpleStack.Orm/SimpleStack.Orm.csproj @@ -15,9 +15,10 @@ 1.2.1.0 1.2.1.0 1.2.5 - netstandard2.0 https://simplestack.org/ https://github.com/SimpleStack/simplestack.orm + net6.0;net8.0;netstandard2.1 + latestmajor diff --git a/test/SimpleStack.Orm.Tests/SimpleStack.Orm.Tests.csproj b/test/SimpleStack.Orm.Tests/SimpleStack.Orm.Tests.csproj index b5c05c2..86deb9f 100644 --- a/test/SimpleStack.Orm.Tests/SimpleStack.Orm.Tests.csproj +++ b/test/SimpleStack.Orm.Tests/SimpleStack.Orm.Tests.csproj @@ -1,7 +1,6 @@  - netcoreapp3.1 SimpleStack.Orm.Tests SimpleStack.Orm.Tests true @@ -10,6 +9,8 @@ false false false + net6.0;net8.0 + latestmajor From 4958d2263f83a5b9f46e456d9a9052f818b8348d Mon Sep 17 00:00:00 2001 From: Vincent DARON Date: Sun, 2 Jun 2024 09:58:22 +0200 Subject: [PATCH 13/14] Update Dapper to 2.1.35 --- src/SimpleStack.Orm/SimpleStack.Orm.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SimpleStack.Orm/SimpleStack.Orm.csproj b/src/SimpleStack.Orm/SimpleStack.Orm.csproj index 66a89df..0a33e38 100644 --- a/src/SimpleStack.Orm/SimpleStack.Orm.csproj +++ b/src/SimpleStack.Orm/SimpleStack.Orm.csproj @@ -22,7 +22,7 @@ - + From 6fd74ad260546974ab731f27dde2e88dd5d97b68 Mon Sep 17 00:00:00 2001 From: Vincent DARON Date: Sun, 2 Jun 2024 10:01:50 +0200 Subject: [PATCH 14/14] Release 1.3.0 --- .../SimpleStack.Orm.Logging.MicrosoftExtensions.csproj | 4 +++- src/SimpleStack.Orm.MySQL/SimpleStack.Orm.MySQL.csproj | 6 +++--- .../SimpleStack.Orm.MySQLConnector.csproj | 6 +++--- .../SimpleStack.Orm.PostgreSQL.csproj | 6 +++--- .../SimpleStack.Orm.SDSQLite.csproj | 6 +++--- .../SimpleStack.Orm.SQLServer.csproj | 6 +++--- src/SimpleStack.Orm.SQLite/SimpleStack.Orm.SQLite.csproj | 6 +++--- src/SimpleStack.Orm/SimpleStack.Orm.csproj | 6 +++--- 8 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/SimpleStack.Orm.Logging.MicrosoftExtensions/SimpleStack.Orm.Logging.MicrosoftExtensions.csproj b/src/SimpleStack.Orm.Logging.MicrosoftExtensions/SimpleStack.Orm.Logging.MicrosoftExtensions.csproj index b518708..e4d4164 100644 --- a/src/SimpleStack.Orm.Logging.MicrosoftExtensions/SimpleStack.Orm.Logging.MicrosoftExtensions.csproj +++ b/src/SimpleStack.Orm.Logging.MicrosoftExtensions/SimpleStack.Orm.Logging.MicrosoftExtensions.csproj @@ -1,9 +1,11 @@ - 1.2.5 + 1.3.0 net6.0;net8.0 latestmajor + 1.3.0 + 1.3.0 diff --git a/src/SimpleStack.Orm.MySQL/SimpleStack.Orm.MySQL.csproj b/src/SimpleStack.Orm.MySQL/SimpleStack.Orm.MySQL.csproj index f32ec08..d0df1fe 100644 --- a/src/SimpleStack.Orm.MySQL/SimpleStack.Orm.MySQL.csproj +++ b/src/SimpleStack.Orm.MySQL/SimpleStack.Orm.MySQL.csproj @@ -14,9 +14,9 @@ false false 1.2.0-beta95 - 1.2.0.0 - 1.2.0.0 - 1.2.5 + 1.3.0 + 1.3.0 + 1.3.0 https://simplestack.org/ https://github.com/SimpleStack/simplestack.orm git diff --git a/src/SimpleStack.Orm.MySQLConnector/SimpleStack.Orm.MySQLConnector.csproj b/src/SimpleStack.Orm.MySQLConnector/SimpleStack.Orm.MySQLConnector.csproj index 40aa58b..04cf2e1 100644 --- a/src/SimpleStack.Orm.MySQLConnector/SimpleStack.Orm.MySQLConnector.csproj +++ b/src/SimpleStack.Orm.MySQLConnector/SimpleStack.Orm.MySQLConnector.csproj @@ -12,9 +12,9 @@ false false 1.2.0-beta95 - 1.2.0.0 - 1.2.0.0 - 1.2.5 + 1.3.0 + 1.3.0 + 1.3.0 https://simplestack.org/ https://github.com/SimpleStack/simplestack.orm net6.0;net8.0 diff --git a/src/SimpleStack.Orm.PostgreSQL/SimpleStack.Orm.PostgreSQL.csproj b/src/SimpleStack.Orm.PostgreSQL/SimpleStack.Orm.PostgreSQL.csproj index fe5dba5..cf1ba10 100644 --- a/src/SimpleStack.Orm.PostgreSQL/SimpleStack.Orm.PostgreSQL.csproj +++ b/src/SimpleStack.Orm.PostgreSQL/SimpleStack.Orm.PostgreSQL.csproj @@ -13,9 +13,9 @@ false false 1.2.0-beta95 - 1.2.1.0 - 1.2.1.0 - 1.2.5 + 1.3.0 + 1.3.0 + 1.3.0 https://simplestack.org/ https://github.com/SimpleStack/simplestack.orm latestmajor diff --git a/src/SimpleStack.Orm.SDSQLite/SimpleStack.Orm.SDSQLite.csproj b/src/SimpleStack.Orm.SDSQLite/SimpleStack.Orm.SDSQLite.csproj index 63aa361..347c335 100644 --- a/src/SimpleStack.Orm.SDSQLite/SimpleStack.Orm.SDSQLite.csproj +++ b/src/SimpleStack.Orm.SDSQLite/SimpleStack.Orm.SDSQLite.csproj @@ -13,9 +13,9 @@ false false 1.2.0-beta95 - 1.2.0.0 - 1.2.0.0 - 1.2.5 + 1.3.0 + 1.3.0 + 1.3.0 SimpleStack.Orm.SDSQlite https://simplestack.org/ https://github.com/SimpleStack/simplestack.orm diff --git a/src/SimpleStack.Orm.SQLServer/SimpleStack.Orm.SQLServer.csproj b/src/SimpleStack.Orm.SQLServer/SimpleStack.Orm.SQLServer.csproj index 0c6bb07..9c44737 100644 --- a/src/SimpleStack.Orm.SQLServer/SimpleStack.Orm.SQLServer.csproj +++ b/src/SimpleStack.Orm.SQLServer/SimpleStack.Orm.SQLServer.csproj @@ -12,9 +12,9 @@ false false 1.2.0-beta95 - 1.2.0.0 - 1.2.0.0 - 1.2.5 + 1.3.0 + 1.3.0 + 1.3.0 https://simplestack.org/ https://github.com/SimpleStack/simplestack.orm net6.0;net8.0 diff --git a/src/SimpleStack.Orm.SQLite/SimpleStack.Orm.SQLite.csproj b/src/SimpleStack.Orm.SQLite/SimpleStack.Orm.SQLite.csproj index 2058a18..8bdb189 100644 --- a/src/SimpleStack.Orm.SQLite/SimpleStack.Orm.SQLite.csproj +++ b/src/SimpleStack.Orm.SQLite/SimpleStack.Orm.SQLite.csproj @@ -13,9 +13,9 @@ false false 1.2.0-beta95 - 1.2.0.0 - 1.2.0.0 - 1.2.5 + 1.3.0 + 1.3.0 + 1.3.0 https://simplestack.org/ https://github.com/SimpleStack/simplestack.orm latestmajor diff --git a/src/SimpleStack.Orm/SimpleStack.Orm.csproj b/src/SimpleStack.Orm/SimpleStack.Orm.csproj index 0a33e38..91133a6 100644 --- a/src/SimpleStack.Orm/SimpleStack.Orm.csproj +++ b/src/SimpleStack.Orm/SimpleStack.Orm.csproj @@ -12,9 +12,9 @@ false 1.2.0-beta95 False - 1.2.1.0 - 1.2.1.0 - 1.2.5 + 1.3.0 + 1.3.0 + 1.3.0 https://simplestack.org/ https://github.com/SimpleStack/simplestack.orm net6.0;net8.0;netstandard2.1