Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
 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));
 }
Exemplo n.º 3
0
 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);
        }
Exemplo n.º 5
0
 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);
 }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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));
        }
Exemplo n.º 9
0
 public void ParamDoesntGetBound(string sql)
 {
     _params.AddWithValue(":param", "foo");
     SqlQueryParser.ParseRawQuery(sql, true, _params, _queries);
     Assert.That(_queries.Single().InputParameters, Is.Empty);
 }
Exemplo n.º 10
0
 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()));
 }
Exemplo n.º 11
0
 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()));
 }
Exemplo n.º 12
0
 public void ConsecutiveSemicolons()
 {
     SqlQueryParser.ParseRawQuery(";;SELECT 1", true, _params, _queries);
     Assert.That(_queries, Has.Count.EqualTo(3));
 }
Exemplo n.º 13
0
 public void TrimWhitespace()
 {
     SqlQueryParser.ParseRawQuery("   SELECT 1\t", true, _params, _queries);
     Assert.That(_queries.Single().Sql, Is.EqualTo("SELECT 1"));
 }
Exemplo n.º 14
0
 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));
 }
Exemplo n.º 15
0
 public void ParamGetsBoundNonAscii()
 {
     _params.AddWithValue("漢字", "foo");
     SqlQueryParser.ParseRawQuery("SELECT @漢字", true, _params, _queries);
     Assert.That(_queries.Single().InputParameters.Single(), Is.SameAs(_params.Single()));
 }