public void ReduceNumberOfStatements() { var parser = new SqlQueryParser(); var cmd = new NpgsqlCommand("SELECT 1; SELECT 2"); parser.ParseRawQuery(cmd); Assert.That(cmd.InternalBatchCommands, Has.Count.EqualTo(2)); cmd.CommandText = "SELECT 1"; parser.ParseRawQuery(cmd); Assert.That(cmd.InternalBatchCommands, Has.Count.EqualTo(1)); }
public void ParamSimple() { _params.AddWithValue(":p1", "foo"); _params.AddWithValue(":p2", "bar"); SqlQueryParser.ParseRawQuery("SELECT :p1, :p2", true, _params, _queries); Assert.That(_queries.Single().InputParameters, Is.EqualTo(_params)); }
public void Untouched(string sql) { _params.AddWithValue(":param", "foo"); SqlQueryParser.ParseRawQuery(sql, true, _params, _queries); Assert.That(_queries.Single().SQL, Is.EqualTo(sql)); Assert.That(_queries.Single().InputParameters, Is.Empty); }
public void NonConformantStrings() { var parser = new SqlQueryParser(false); parser.ParseRawQuery(@"SELECT 'abc\':str''a:str'", _params, _queries); Assert.That(_queries.Single().SQL, Is.EqualTo(@"SELECT 'abc\':str''a:str'")); Assert.That(_queries.Single().InputParameters, Is.Empty); }
public void MissingParamIsIgnored() { SqlQueryParser.ParseRawQuery("SELECT @p; SELECT 1", true, _params, _queries); Assert.That(_queries[0].SQL, Is.EqualTo("SELECT @p")); Assert.That(_queries[1].SQL, Is.EqualTo("SELECT 1")); Assert.That(_queries[0].InputParameters, Is.Empty); Assert.That(_queries[1].InputParameters, Is.Empty); }
List <NpgsqlBatchCommand> ParseCommand(string sql, NpgsqlParameter[] parameters, bool standardConformingStrings) { var cmd = new NpgsqlCommand(sql); cmd.Parameters.AddRange(parameters); var parser = new SqlQueryParser(); parser.ParseRawQuery(cmd, standardConformingStrings); return(cmd.InternalBatchCommands); }
public void NoOutputParameters() { var p = new NpgsqlParameter("p", DbType.String) { Direction = ParameterDirection.Output }; _params.Add(p); Assert.That(() => SqlQueryParser.ParseRawQuery("SELECT @p", true, _params, _queries), Throws.Exception); }
public void MultiqueryWithParams() { var p1 = new NpgsqlParameter("p1", DbType.String); _params.Add(p1); var p2 = new NpgsqlParameter("p2", DbType.String); _params.Add(p2); var p3 = new NpgsqlParameter("p3", DbType.String); _params.Add(p3); SqlQueryParser.ParseRawQuery("SELECT @p3, @p1; SELECT @p2, @p3", true, _params, _queries); Assert.That(_queries, Has.Count.EqualTo(2)); Assert.That(_queries[0].InputParameters[0], Is.SameAs(p3)); Assert.That(_queries[0].InputParameters[1], Is.SameAs(p1)); Assert.That(_queries[1].InputParameters[0], Is.SameAs(p2)); Assert.That(_queries[1].InputParameters[1], Is.SameAs(p3)); }
public void ParamDoesntGetBound(string sql) { _params.AddWithValue(":param", "foo"); SqlQueryParser.ParseRawQuery(sql, true, _params, _queries); Assert.That(_queries.Single().InputParameters, Is.Empty); }
public void ParamGetsBound(string sql) { _params.AddWithValue(":param", "foo"); SqlQueryParser.ParseRawQuery(sql, true, _params, _queries); Assert.That(_queries.Single().InputParameters.Single(), Is.SameAs(_params.Single())); }
public void ParamNameWithDot() { _params.AddWithValue(":a.parameter", "foo"); SqlQueryParser.ParseRawQuery("INSERT INTO data (field_char5) VALUES (:a.parameter)", true, _params, _queries); Assert.That(_queries.Single().InputParameters.Single(), Is.SameAs(_params.Single())); }
public void ConsecutiveSemicolons() { SqlQueryParser.ParseRawQuery(";;SELECT 1", true, _params, _queries); Assert.That(_queries, Has.Count.EqualTo(3)); }
public void TrimWhitespace() { SqlQueryParser.ParseRawQuery(" SELECT 1\t", true, _params, _queries); Assert.That(_queries.Single().Sql, Is.EqualTo("SELECT 1")); }
public void SemicolonAfterParentheses() { SqlQueryParser.ParseRawQuery("CREATE OR REPLACE RULE test AS ON UPDATE TO test DO (SELECT 1); SELECT 1", true, _params, _queries); Assert.That(_queries, Has.Count.EqualTo(2)); }
public void ParamGetsBoundNonAscii() { _params.AddWithValue("漢字", "foo"); SqlQueryParser.ParseRawQuery("SELECT @漢字", true, _params, _queries); Assert.That(_queries.Single().InputParameters.Single(), Is.SameAs(_params.Single())); }