Beispiel #1
0
        public void IdentityCanInsert()
        {
            using (var table = new FirebirdTestTable(Processor, null, "bogus int"))
            {
                Processor.Process(new CreateColumnExpression
                {
                    TableName = table.Name,
                    Column    = { Name = "id", IsIdentity = true, Type = DbType.Int64, IsPrimaryKey = true }
                });

                var insert = new InsertDataExpression {
                    TableName = table.Name
                };
                var item = new Model.InsertionDataDefinition();
                item.Add(new System.Collections.Generic.KeyValuePair <string, object>("BOGUS", 0));
                insert.Rows.Add(item);
                Processor.Process(insert);

                using (DataSet ds = Processor.ReadTableData(String.Empty, table.Name))
                {
                    ds.Tables.Count.ShouldBe(1);
                    ds.Tables[0].Rows.Count.ShouldBe(1);
                    ds.Tables[0].Rows[0]["BOGUS"].ShouldBe(0);
                    ds.Tables[0].Rows[0]["id"].ShouldBe(1);
                }
            }
        }
Beispiel #2
0
        public void CallingColumnExistsCanAcceptColumnNameWithSingleQuote()
        {
            var columnNameWithSingleQuote = quoter.QuoteColumnName("i'd");

            using (var table = new FirebirdTestTable(Processor, null, string.Format("{0} int", columnNameWithSingleQuote)))
                Processor.ColumnExists(null, table.Name, "i'd").ShouldBeTrue();
        }
        public override void CallingIndexExistsCanAcceptTableNameWithSingleQuote()
        {
            using (var table = new FirebirdTestTable("\"Test'Table\"", Processor, "id int"))
            {
                Processor.CheckTable(table.Name);
                Processor.LockTable(table.Name);
                var idxName = "\"idx_Test'Table\"";

                if (table.Connection.State != ConnectionState.Open)
                {
                    table.Connection.Open();
                }

                using (var cmd = table.Connection.CreateCommand())
                {
                    cmd.Transaction = table.Transaction;
                    cmd.CommandText = $"CREATE INDEX {idxName} ON {table.Name} (id)";
                    cmd.ExecuteNonQuery();
                }

                Processor.AutoCommit();

                Processor.IndexExists(null, table.Name, idxName).ShouldBeTrue();
            }
        }
        public override void CallingIndexExistsReturnsTrueIfIndexExistsWithSchema()
        {
            using (var table = new FirebirdTestTable(Processor, "id int"))
            {
                Processor.CheckTable(table.Name);
                Processor.LockTable(table.Name);
                var idxName = $"idx_{table.Name}";

                if (table.Connection.State != ConnectionState.Open)
                {
                    table.Connection.Open();
                }

                using (var cmd = table.Connection.CreateCommand())
                {
                    cmd.Transaction = table.Transaction;
                    cmd.CommandText = $"CREATE INDEX {Quoter.QuoteIndexName(idxName)} ON {Quoter.QuoteTableName(table.Name)} (id)";
                    cmd.ExecuteNonQuery();
                }

                Processor.AutoCommit();

                Processor.IndexExists("TestSchema", table.Name, idxName).ShouldBeTrue();
            }
        }
        public override void CallingColumnExistsCanAcceptColumnNameWithSingleQuote()
        {
            var columnNameWithSingleQuote = "\"i'd\"";

            using (var table = new FirebirdTestTable(Processor, string.Format("{0} int", columnNameWithSingleQuote)))
                Processor.ColumnExists(null, table.Name, "\"i'd\"").ShouldBeTrue();
        }
Beispiel #6
0
 public void CanCreateTrigger()
 {
     using (var table = new FirebirdTestTable(Processor, null, "id int"))
     {
         Processor.Process(Processor.CreateTriggerExpression(table.Name, "TestTrigger", true, TriggerEvent.Insert, "as begin end"));
         Processor.TriggerExists(String.Empty, table.Name, "TestTrigger").ShouldBeTrue();
     }
 }
Beispiel #7
0
        private void AddTestData(FirebirdTestTable table)
        {
            for (int i = 0; i < 3; i++)
            {
                using (var cmd = table.Connection.CreateCommand())
                {
                    cmd.Transaction = table.Transaction;
                    cmd.CommandText = string.Format("INSERT INTO {0} (id) VALUES ({1})", Quoter.QuoteTableName(table.Name), i);
                    cmd.ExecuteNonQuery();
                }
            }

            Processor.AutoCommit();
        }
Beispiel #8
0
 public void IdentityCanCreateIdentityColumn()
 {
     using (var table = new FirebirdTestTable(Processor, null, "bogus int"))
     {
         Processor.Process(new CreateColumnExpression
         {
             TableName = table.Name,
             Column    = { Name = "id", IsIdentity = true, Type = DbType.Int64 }
         });
         Processor.ColumnExists(String.Empty, table.Name, "id").ShouldBeTrue();
         Processor.SequenceExists(String.Empty, String.Format("gen_{0}_id", table.Name)).ShouldBeTrue();
         Processor.TriggerExists(String.Empty, table.Name, String.Format("gen_id_{0}_id", table.Name)).ShouldBeTrue();
     }
 }
Beispiel #9
0
        public void CanReadDataWithSchema()
        {
            using (var table = new FirebirdTestTable(Processor, "TestSchema", "id int"))
            {
                Processor.CheckTable(table.Name);
                AddTestData(table);

                using (DataSet ds = Processor.Read("SELECT * FROM {0}", Quoter.QuoteTableName(table.Name)))
                {
                    ds.ShouldNotBeNull();
                    ds.Tables.Count.ShouldBe(1);
                    ds.Tables[0].Rows.Count.ShouldBe(3);
                    ds.Tables[0].Rows[2][0].ShouldBe(2);
                }
            }
        }
Beispiel #10
0
        public void CanReadTableData()
        {
            using (var table = new FirebirdTestTable(Processor, null, "id int"))
            {
                Processor.CheckTable(table.Name);
                AddTestData(table);

                using (DataSet ds = Processor.ReadTableData(null, table.Name))
                {
                    ds.ShouldNotBeNull();
                    ds.Tables.Count.ShouldBe(1);
                    ds.Tables[0].Rows.Count.ShouldBe(3);
                    ds.Tables[0].Rows[2][0].ShouldBe(2);
                }
            }
        }
        public void CanReadTableDataWithSchema()
        {
            using (var table = new FirebirdTestTable(Processor, "TestSchema", "id int"))
            {
                Processor.CheckTable(table.Name);
                AddTestData(table);

                using (var ds = ((DataSetContainer)Processor.ReadTableData("TestSchema", table.Name)).DataSet)
                {
                    ds.ShouldNotBeNull();
                    ds.Tables.Count.ShouldBe(1);
                    ds.Tables[0].Rows.Count.ShouldBe(3);
                    ds.Tables[0].Rows[2][0].ShouldBe(2);
                }
            }
        }
Beispiel #12
0
        public void CanCreateAndDropSequenceWithExistCheck()
        {
            using (var table = new FirebirdTestTable(Processor, null, "id int"))
            {
                Processor.Process(new CreateSequenceExpression()
                {
                    Sequence = { Name = "Sequence" }
                });

                Processor.SequenceExists("", "", "Sequence").ShouldBeTrue();

                Processor.Process(new DeleteSequenceExpression()
                {
                    SequenceName = "Sequence"
                });

                Processor.SequenceExists("", "", "Sequence").ShouldBeFalse();
            }
        }
Beispiel #13
0
        public override void CallingIndexExistsReturnsTrueIfIndexExistsWithSchema()
        {
            using (var table = new FirebirdTestTable(Processor, "TestSchema", "id int"))
            {
                Processor.CheckTable(table.Name);
                Processor.LockTable(table.Name);
                var idxName = string.Format("idx_{0}", table.Name);

                using (var cmd = table.Connection.CreateCommand())
                {
                    cmd.Transaction = table.Transaction;
                    cmd.CommandText = string.Format("CREATE INDEX {0} ON {1} (id)", Quoter.QuoteIndexName(idxName), Quoter.QuoteTableName(table.Name));
                    cmd.ExecuteNonQuery();
                }

                Processor.AutoCommit();

                Processor.IndexExists("TestSchema", table.Name, idxName).ShouldBeTrue();
            }
        }
Beispiel #14
0
        public override void CallingIndexExistsCanAcceptIndexNameWithSingleQuote()
        {
            using (var table = new FirebirdTestTable(Processor, null, "id int"))
            {
                Processor.CheckTable(table.Name);
                Processor.LockTable(table.Name);
                var idxName = string.Format("\"id'x_{0}\"", table.Name);

                using (var cmd = table.Connection.CreateCommand())
                {
                    cmd.Transaction = table.Transaction;
                    cmd.CommandText = string.Format("CREATE INDEX {0} ON {1} (id)", idxName, table.Name);
                    cmd.ExecuteNonQuery();
                }

                Processor.AutoCommit();

                Processor.IndexExists(null, table.Name, idxName).ShouldBeTrue();
            }
        }
Beispiel #15
0
        public void IdentityCanInsertMultiple()
        {
            using (var table = new FirebirdTestTable(Processor, null, "bogus int"))
            {
                Processor.Process(new CreateColumnExpression()
                {
                    TableName = table.Name,
                    Column    = { Name = "id", IsIdentity = true, Type = DbType.Int64, IsPrimaryKey = true }
                });

                InsertDataExpression insert = new InsertDataExpression()
                {
                    TableName = table.Name
                };
                Model.ExplicitDataDefinition item = new Model.ExplicitDataDefinition(new DataValue("BOGUS", 0));
                insert.Rows.Add(item);

                //Process 5 times = insert 5 times
                Processor.Process(insert);
                Processor.Process(insert);
                Processor.Process(insert);
                Processor.Process(insert);
                Processor.Process(insert);

                using (DataSet ds = Processor.ReadTableData(String.Empty, table.Name))
                {
                    ds.Tables.Count.ShouldBe(1);
                    ds.Tables[0].Rows.Count.ShouldBe(5);
                    ds.Tables[0].Rows[0]["BOGUS"].ShouldBe(0);
                    ds.Tables[0].Rows[0]["id"].ShouldBe(1);
                    ds.Tables[0].Rows[1]["id"].ShouldBe(2);
                    ds.Tables[0].Rows[2]["id"].ShouldBe(3);
                    ds.Tables[0].Rows[3]["id"].ShouldBe(4);
                    ds.Tables[0].Rows[4]["id"].ShouldBe(5);
                }
            }
        }
Beispiel #16
0
        public void CanAlterSequence()
        {
            using (var table = new FirebirdTestTable(Processor, null, "id int"))
            {
                Processor.Process(new CreateSequenceExpression()
                {
                    Sequence = { Name = "Sequence", StartWith = 6 }
                });

                using (DataSet ds = Processor.Read("SELECT GEN_ID(\"Sequence\", 1) as generated_value FROM RDB$DATABASE"))
                {
                    ds.Tables[0].ShouldNotBeNull();
                    ds.Tables[0].Rows[0].ShouldNotBeNull();
                    ds.Tables[0].Rows[0]["generated_value"].ShouldBe(7);
                }

                Processor.Process(new DeleteSequenceExpression()
                {
                    SequenceName = "Sequence"
                });

                Processor.SequenceExists(String.Empty, table.Name, "Sequence").ShouldBeFalse();
            }
        }
Beispiel #17
0
 public override void CallingTableExistsCanAcceptTableNameWithSingleQuote()
 {
     using (var table = new FirebirdTestTable("\"Test'Table\"", Processor, null, "id int"))
         Processor.TableExists(null, table.Name).ShouldBeTrue();
 }
Beispiel #18
0
 public override void CallingColumnExistsReturnsFalseIfColumnDoesNotExistWithSchema()
 {
     using (var table = new FirebirdTestTable(Processor, "TestSchema", "id int"))
         Processor.ColumnExists("TestSchema", table.Name, "DoesNotExist").ShouldBeFalse();
 }
Beispiel #19
0
 public void CallingTableExistsCanAcceptTableNameWithSingleQuote()
 {
     using (var table = new FirebirdTestTable(null, "TestSingle'Quote", Processor, "id int"))
         Processor.TableExists(null, table.Name).ShouldBeTrue();
 }
Beispiel #20
0
 public void CallingTableExistsCanAcceptSchemaNameWithSingleQuote()
 {
     using (var table = new FirebirdTestTable(Processor, "Test'Schema", "id int"))
         Processor.TableExists("Test'Schema", table.Name).ShouldBeTrue();
 }
Beispiel #21
0
 public void CallingColumnExistsReturnsTrueIfColumnExistsWithSchema()
 {
     using (var table = new FirebirdTestTable(Processor, "TestSchema", "id int"))
         Processor.ColumnExists("TestSchema", table.Name, "ID").ShouldBeTrue();
 }
Beispiel #22
0
 public void CallingColumnExistsCanAcceptSchemaNameWithSingleQuote()
 {
     using (var table = new FirebirdTestTable("Test'Schema", "TestSingle'Quote", Processor, "id int"))
         Processor.ColumnExists("Test'Schema", table.Name, "ID").ShouldBeTrue();
 }
Beispiel #23
0
 public void CallingConstraintExistsCanAcceptSchemaNameWithSingleQuote()
 {
     using (var table = new FirebirdTestTable(Processor, "Test'Schema", "id int", "wibble int CONSTRAINT c1 CHECK(wibble > 0)"))
         Processor.ConstraintExists("Test'Schema", table.Name, "C1").ShouldBeTrue();
 }
Beispiel #24
0
 public override void CallingIndexExistsReturnsFalseIfIndexDoesNotExist()
 {
     using (var table = new FirebirdTestTable(Processor, null, "id int"))
         Processor.IndexExists(null, table.Name, "DoesNotExist").ShouldBeFalse();
 }
Beispiel #25
0
 public void CallingIndexExistsReturnsFalseIfIndexDoesNotExistWithSchema()
 {
     using (var table = new FirebirdTestTable(Processor, "TestSchema", "id int"))
         Processor.IndexExists("TestSchema", table.Name, "DoesNotExist").ShouldBeFalse();
 }
Beispiel #26
0
 public void CallingConstraintExistsReturnsFalseIfConstraintDoesNotExist()
 {
     using (var table = new FirebirdTestTable(Processor, null, "id int"))
         Processor.ConstraintExists(null, table.Name, "DoesNotExist").ShouldBeFalse();
 }
Beispiel #27
0
 public void CallingContraintExistsReturnsTrueIfConstraintExists()
 {
     using (var table = new FirebirdTestTable(Processor, null, "id int", "wibble int CONSTRAINT c1 CHECK(wibble > 0)"))
         Processor.ConstraintExists(null, table.Name, "C1").ShouldBeTrue();
 }
Beispiel #28
0
 public override void CallingTableExistsReturnsTrueIfTableExists()
 {
     using (var table = new FirebirdTestTable(Processor, null, "id int"))
         Processor.TableExists(null, table.Name).ShouldBeTrue();
 }
Beispiel #29
0
 public override void CallingTableExistsReturnsTrueIfTableExistsWithSchema()
 {
     using (var table = new FirebirdTestTable(Processor, "TestSchema", "id int"))
         Processor.TableExists("TestSchema", table.Name).ShouldBeTrue();
 }
Beispiel #30
0
 public void CallingColumnExistsReturnsTrueIfColumnExists()
 {
     using (var table = new FirebirdTestTable(Processor, null, "id int"))
         Processor.ColumnExists(null, table.Name, "ID").ShouldBeTrue();
 }