/// <summary> /// Validates the Query SQL statement against database engine for its syntax and structural correctness. /// Validates only statement in <see cref="SqlStatement"/>. If derived class contains more than this one /// SQL statement - override this implementation and add all statement validations to it. /// </summary> /// <param name="databaseSession">The database session object.</param> /// <exception cref="DatabaseStatementSyntaxException">Throws when <see cref="SqlStatement"/> is incorrect.</exception> public virtual void Validate(IDatabaseSession databaseSession) { string result = databaseSession.QueryFirstOrDefault <string>("SELECT dbo.CheckSql(@tsql, @parameterTypes)", new { tsql = this.SqlStatement, parameterTypes = MsSqlValidationHelpers.GetParameterTypes(this.Parameters) }); if (result != "OK") { throw new DatabaseStatementSyntaxException(result, this.SqlStatement); } }
/// <summary> /// Actual executable method of database query which returns data from database. /// </summary> /// <param name="session">The database connection session.</param> public virtual T Execute(IDatabaseSession session) => session.QueryFirstOrDefault <T>(this.SqlStatement, this.Parameters);