Exemple #1
0
        public void AppendForeignKeyConstraintFromReference(AST.Table.AstTableNode table, string refNameOverride, string refName, AST.Table.AstTableNode refTable)
        {
            TemplatePlatformEmitter tpe = new TemplatePlatformEmitter("ForeignKeyConstraintTemplate");

            tpe.Map("TableName", table.SchemaQualifiedName);

            string constraintName;

            if (!String.IsNullOrEmpty(refNameOverride))
            {
                constraintName = String.Format(CultureInfo.InvariantCulture, "[{0}]", refNameOverride);
            }
            else
            {
                constraintName = String.Format(
                    CultureInfo.InvariantCulture,
                    "[FK_{0}_{1}_{2}_{3}]",
                    table.Name,
                    refName,
                    refTable.Name,
                    refTable.PreferredKey.Columns[0].Column.Name);
            }

            if (constraintName.Length >= 128)
            {
                constraintName = String.Format(CultureInfo.InvariantCulture, "[{0}]", constraintName.Substring(0, 127));
            }

            tpe.Map("ConstraintName", constraintName);
            tpe.Map("Column", refName);
            tpe.Map("ForeignKeyTable", refTable.SchemaQualifiedName);
            tpe.Map("ForeignKeyColumn", refTable.PreferredKey.Columns[0].Column.Name);
            _foreignKeyBuilder.Append(tpe.Emit());
            _foreignKeyBuilder.Append("\n\n");
        }
Exemple #2
0
        public void AppendForeignKeyConstraintFromReference(AST.Table.AstTableNode table, string refNameOverride, string refName, AST.Table.AstTableNode refTable)
        {
            TemplatePlatformEmitter tpe = new TemplatePlatformEmitter("ForeignKeyConstraintTemplate");
            tpe.Map("TableName", table.SchemaQualifiedName);

            string constraintName;
            if (!String.IsNullOrEmpty(refNameOverride))
            {
                constraintName = String.Format(CultureInfo.InvariantCulture, "[{0}]", refNameOverride);
            }
            else
            {
                constraintName = String.Format(
                    CultureInfo.InvariantCulture,
                    "[FK_{0}_{1}_{2}_{3}]",
                    table.Name,
                    refName,
                    refTable.Name,
                    refTable.PreferredKey.Columns[0].Column.Name);
            }

            if (constraintName.Length >= 128)
            {
                constraintName = String.Format(CultureInfo.InvariantCulture,"[{0}]",constraintName.Substring(0, 127));
            }

            tpe.Map("ConstraintName", constraintName);
            tpe.Map("Column", refName);
            tpe.Map("ForeignKeyTable", refTable.SchemaQualifiedName);
            tpe.Map("ForeignKeyColumn", refTable.PreferredKey.Columns[0].Column.Name);
            _foreignKeyBuilder.Append(tpe.Emit());
            _foreignKeyBuilder.Append("\n\n");
        }
Exemple #3
0
 public string Emit()
 {
     var tpe = new TemplatePlatformEmitter("StoredProc");
     tpe.Map("Name", _name);
     tpe.Map("Columns", _columnsBuilder.ToString());
     tpe.Map("Body", _body);
     return tpe.Emit();
 }
Exemple #4
0
        public string Emit()
        {
            var tpe = new TemplatePlatformEmitter("StoredProc");

            tpe.Map("Name", _name);
            tpe.Map("Columns", _columnsBuilder.ToString());
            tpe.Map("Body", _body);
            return(tpe.Emit());
        }
        public void CompleteRow()
        {
            // TODO: Add validation logic here
            _defaultValueEmitter.Map("Table", _table.SchemaQualifiedName);
            _defaultValueEmitter.Map("Columns", FlattenStringList(_columnNames));
            _defaultValueEmitter.Map("Values", FlattenStringList(_defaultValues));

            _defaultValueBuilder.AppendLine(_defaultValueEmitter.Emit());
            _columnNames.Clear();
            _defaultValues.Clear();
        }
Exemple #6
0
        public string Emit()
        {
            var tableBuilder = new StringBuilder();
            var tpe = new TemplatePlatformEmitter("CreateTable");
            tpe.Map("Name", _name);
            tpe.Map("CompressionType", _compressionType);
            tpe.Map("Columns", ColumnsEmitter.ColumnsDdl);
            tpe.Map("Constraints", ConstraintsEmitter.CKConstraints);

            tableBuilder.AppendLine(tpe.Emit());
            tableBuilder.AppendLine(ConstraintsEmitter.ForeignConstraints);
            tableBuilder.AppendLine(_constraintEmitter.Indexes);

            return tableBuilder.ToString();
        }
Exemple #7
0
        public string Emit()
        {
            var tableBuilder = new StringBuilder();
            var tpe          = new TemplatePlatformEmitter("CreateTable");

            tpe.Map("Name", _name);
            tpe.Map("CompressionType", _compressionType);
            tpe.Map("Columns", ColumnsEmitter.ColumnsDdl);
            tpe.Map("Constraints", ConstraintsEmitter.CKConstraints);

            tableBuilder.AppendLine(tpe.Emit());
            tableBuilder.AppendLine(ConstraintsEmitter.ForeignConstraints);
            tableBuilder.AppendLine(_constraintEmitter.Indexes);

            return(tableBuilder.ToString());
        }
Exemple #8
0
        public static string EmitUpdateStatement(AstTableNode astTableNode, IEnumerable<TableColumnValueMapping> assignments, IEnumerable<TableColumnValueMapping> conditions)
        {
            var updateTemplate = new TemplatePlatformEmitter("SimpleUpdate");
            updateTemplate.Map("Table", astTableNode.SchemaQualifiedName);
            var assignmentStrings = new List<string>();
            foreach (var assignmentPair in assignments)
            {
                assignmentStrings.Add(String.Format(CultureInfo.InvariantCulture, "{0} {1} {2}", assignmentPair.ColumnName, assignmentPair.OperatorString, assignmentPair.ColumnValue));
            }

            updateTemplate.Map("ColumnValuePairs", FlattenStringList(assignmentStrings));

            var whereTemplate = new TemplatePlatformEmitter("SimpleWhere");
            var whereStrings = new List<string>();
            foreach (var wherePair in conditions)
            {
                whereStrings.Add(String.Format(CultureInfo.InvariantCulture, "{0} {1} {2}", wherePair.ColumnName, wherePair.OperatorString, wherePair.ColumnValue));
            }

            whereTemplate.Map("ColumnValuePairs", FlattenStringList(whereStrings, " AND "));

            return String.Format(CultureInfo.InvariantCulture, "{0} {1}", updateTemplate.Emit(), whereTemplate.Emit());
        }
Exemple #9
0
 public static string EmitSelectAllStatement(AstTableNode astTableNode, IEnumerable<string> columnNames)
 {
     var selectTemplate = new TemplatePlatformEmitter("SimpleSelect");
     selectTemplate.Map("Table", astTableNode.SchemaQualifiedName);
     selectTemplate.Map("Columns", FlattenStringList(columnNames));
     return selectTemplate.Emit();
 }