Inheritance: SqlStatement, IPlSqlStatement
Ejemplo n.º 1
0
        public static void MultiSet()
        {
            var statement = new InsertStatement(ObjectName.Parse("t1"), new[] {
                "first_name", "last_name", "age"
            }, new[] {
                new SqlExpression[] {
                    SqlExpression.Constant("Antonello"),
                    SqlExpression.Constant("Provenzano"),
                    SqlExpression.Constant(34)
                },
                new SqlExpression[] {
                    SqlExpression.Constant("Sebastiano"),
                    SqlExpression.Constant("Provenzano"),
                    SqlExpression.Constant(33)
                },
            });

            var sql = statement.ToString();
            var expected = new StringBuilder();
            expected.AppendLine("INSERT INTO t1(first_name, last_name, age)");
            expected.AppendLine("  VALUES");
            expected.AppendLine("  ('Antonello', 'Provenzano', 34),");
            expected.Append("  ('Sebastiano', 'Provenzano', 33)");

            Assert.AreEqual(expected.ToString(), sql);
        }
        public static void MultiSet()
        {
            var statement = new InsertStatement(ObjectName.Parse("t1"), new[] {
                "first_name", "last_name", "age"
            }, new[] {
                new SqlExpression[] {
                    SqlExpression.Constant("Antonello"),
                    SqlExpression.Constant("Provenzano"),
                    SqlExpression.Constant(34)
                },
                new SqlExpression[] {
                    SqlExpression.Constant("Sebastiano"),
                    SqlExpression.Constant("Provenzano"),
                    SqlExpression.Constant(33)
                },
            });

            var sql      = statement.ToString();
            var expected = new StringBuilder();

            expected.AppendLine("INSERT INTO t1(first_name, last_name, age)");
            expected.AppendLine("  VALUES");
            expected.AppendLine("  ('Antonello', 'Provenzano', 34),");
            expected.Append("  ('Sebastiano', 'Provenzano', 33)");

            Assert.AreEqual(expected.ToString(), sql);
        }
        public void InsertTwoValues()
        {
            var tableName = ObjectName.Parse("APP.test_table");
            var columns = new [] { "first_name", "last_name", "active"};
            var values = new List<SqlExpression[]> {
                new[] {
                    SqlExpression.Constant("Antonello"),
                    SqlExpression.Constant("Provenzano"),
                    SqlExpression.Constant(true)
                },
                new [] {
                    SqlExpression.Constant("Mart"),
                    SqlExpression.Constant("Roosmaa"),
                    SqlExpression.Constant(false)
                }
            };

            var statement = new InsertStatement(tableName, columns, values);
            Query.ExecuteStatement(statement);

            var table = Query.GetTable(tableName);

            Assert.IsNotNull(table);
            Assert.AreEqual(2, table.RowCount);
        }
Ejemplo n.º 4
0
        public void InsertTwoValues()
        {
            var tableName = ObjectName.Parse("APP.test_table");
            var columns   = new [] { "first_name", "last_name", "active" };
            var values    = new List <SqlExpression[]> {
                new[] {
                    SqlExpression.Constant("Antonello"),
                    SqlExpression.Constant("Provenzano"),
                    SqlExpression.Constant(true)
                },
                new [] {
                    SqlExpression.Constant("Mart"),
                    SqlExpression.Constant("Roosmaa"),
                    SqlExpression.Constant(false)
                }
            };

            var statement = new InsertStatement(tableName, columns, values);

            Query.ExecuteStatement(statement);

            var table = Query.GetTable(tableName);

            Assert.IsNotNull(table);
            Assert.AreEqual(2, table.RowCount);
        }
Ejemplo n.º 5
0
        public static void WithNoColumns()
        {
            var statement = new InsertStatement(ObjectName.Parse("t1"), new[] {
                new SqlExpression[] {
                    SqlExpression.Constant("Antonello"),
                    SqlExpression.Constant("Provenzano"),
                    SqlExpression.Constant(34)
                },
            });

            var sql = statement.ToString();
            var expected = new StringBuilder();
            expected.Append("INSERT INTO t1 ");
            expected.Append("VALUES ('Antonello', 'Provenzano', 34)");

            Assert.AreEqual(expected.ToString(), sql);
        }
        public static void WithNoColumns()
        {
            var statement = new InsertStatement(ObjectName.Parse("t1"), new[] {
                new SqlExpression[] {
                    SqlExpression.Constant("Antonello"),
                    SqlExpression.Constant("Provenzano"),
                    SqlExpression.Constant(34)
                },
            });

            var sql      = statement.ToString();
            var expected = new StringBuilder();

            expected.Append("INSERT INTO t1 ");
            expected.Append("VALUES ('Antonello', 'Provenzano', 34)");

            Assert.AreEqual(expected.ToString(), sql);
        }
Ejemplo n.º 7
0
 protected virtual SqlStatement VisitInsert(InsertStatement statement)
 {
     return new InsertStatement(statement.TableName, statement.ColumnNames, statement.Values);
 }
Ejemplo n.º 8
0
        public void InsertWithColumns()
        {
            var columnNames = new string[] {"id", "text"};
            var values = new SqlExpression[][] {
                new SqlExpression[] {
                    SqlExpression.Constant(22),
                    SqlExpression.Constant("test"),
                },
            };

            var tableName = ObjectName.Parse("APP.test_table");
            var statement = new InsertStatement(tableName, columnNames, values);

            SerializeAndAssert(statement, (serialized, deserialized) => {
                Assert.IsNotNull(deserialized);
                Assert.IsNotNull(deserialized.TableName);
                Assert.IsNotNull(deserialized.ColumnNames);
                Assert.IsNotEmpty(deserialized.ColumnNames);
                Assert.IsNotNull(deserialized.Values);
                Assert.IsNotEmpty(deserialized.Values);
            });
        }
Ejemplo n.º 9
0
 protected virtual SqlStatement VisitInsert(InsertStatement statement)
 {
     return(new InsertStatement(statement.TableName, statement.ColumnNames, statement.Values));
 }