コード例 #1
0
        public override void VisitIfTableExists(StatementIfTableExists statementIfExists)
        {
            if (statementIfExists.ExprTable.DbSchema == null)
            {
                throw new SqExpressException("Table schema name is mandatory to check the table existence");
            }

            string?databaseName = statementIfExists.ExprTable.DbSchema.Database?.Name;

            var tbl = new InformationSchemaTables(databaseName, Alias.Empty);

            ExprBoolean condition = tbl.TableSchema == this.Options.MapSchema(statementIfExists.ExprTable.DbSchema.Schema.Name)
                                    & tbl.TableName == statementIfExists.ExprTable.TableName.Name;

            var test = SqQueryBuilder.SelectTopOne()
                       .From(tbl)
                       .Where(condition);

            new StatementIf(SqQueryBuilder.Exists(test), statementIfExists.Statements, statementIfExists.ElseStatements).Accept(this);
        }