src/Azos/Data/Modeling/RDBMSCompiler.cs
/// <summary>
/// Override to compile a RDBMS Table
/// </summary>
Override to compile a RDBMS Table
Override to compile a RDBMS Table
protected virtual void DoTable(IConfigSectionNode tableNode, Outputs outputs)
            {
                var tname = tableNode.Value;
                if (tname.IsNullOrWhiteSpace())
                {
                     m_CompileErrors.Add(new SchemaCompilationException(tableNode.RootPath, "Table name missing"));
                     return;
                }
                var table = new RDBMSEntity(m_All, tableNode, RDBMSEntityType.Table, tname, tableNode.AttrByName(SHORT_NAME_ATTR).Value);
                TransformEntityName(table);
                var sb = outputs[RDBMSCompiler.TABLES_OUTPUT];
                sb.AppendLine(GetStatementDelimiterScript(RDBMSEntityType.Table, true));
                sb.AppendLine("-- {0}".Args( tableNode.AttrByName(SCRIPT_COMMENT_ATTR).ValueAsString("Table " + table.TransformedName)));
                sb.AppendLine("{0} {1}".Args( TransformKeywordCase("create table"),
                                              GetQuotedIdentifierName(RDBMSEntityType.Table, table.TransformedName) ));
                sb.AppendLine("(");
                var firstItem = true;
                foreach(var node in tableNode.Children)
                {
                    if      (node.IsSameName(COLUMN_SECTION))         { DoColumn(node, table, sb, ref firstItem, outputs); }
                    else if (node.IsSameName(PRIMARY_KEY_SECTION))    { DoReadPrimaryKeySection(node, table); }
                    else if (node.IsSameName(INDEX_SECTION))          { DoReadIndexSection(node, table); }
                    else if (node.IsSameName(SCRIPT_INCLUDE_SECTION)) { IncludeScriptFile(node, outputs); sb.AppendLine(); }
                    else if (node.IsSameName(SCRIPT_TEXT_SECTION))    { IncludeScriptText(node, outputs); sb.AppendLine(); }
                    else
                       m_CompileErrors.Add(new SchemaCompilationException(node.RootPath, "Unrecognized item inside '{0}' table section '{1}'".Args(tname, node.Name)));
                }
                DoPrimaryKeys(table, sb, ref firstItem);
                DoForeignKeys(table, sb, ref firstItem, outputs);
                sb.AppendLine();
                sb.AppendLine(")");
                var comment = tableNode.AttrByName(COMMENT_ATTR).Value;
                if (comment.IsNotNullOrWhiteSpace())
                {
                    sb.AppendLine("    {0} = {1}".Args(TransformKeywordCase("comment"),
                                                       EscapeString(comment) ));
                }
                sb.AppendLine(GetStatementDelimiterScript(RDBMSEntityType.Table, false));
                sb.AppendLine();
                DoTableIndexes(table, outputs);
            }
protected virtual void DoTable ( IConfigSectionNode tableNode , Outputs outputs ) { var tname = tableNode . Value ; if ( tname . IsNullOrWhiteSpace ( ) ) { m_CompileErrors . Add ( new SchemaCompilationException ( tableNode . RootPath , " " ) ) ; return ; } var table = new RDBMSEntity ( m_All , tableNode , RDBMSEntityType . Table , tname , tableNode . AttrByName ( SHORT_NAME_ATTR ) . Value ) ; TransformEntityName ( table ) ; var sb = outputs [ RDBMSCompiler . TABLES_OUTPUT ] ; sb . AppendLine ( GetStatementDelimiterScript ( RDBMSEntityType . Table , true ) ) ; sb . AppendLine ( " " . Args ( tableNode . AttrByName ( SCRIPT_COMMENT_ATTR ) . ValueAsString ( " " + table . TransformedName ) ) ) ; sb . AppendLine ( " " . Args ( TransformKeywordCase ( " " ) , GetQuotedIdentifierName ( RDBMSEntityType . Table , table . TransformedName ) ) ) ; sb . AppendLine ( " " ) ; var firstItem = true ; foreach ( var node in tableNode . Children ) { if ( node . IsSameName ( COLUMN_SECTION ) ) { DoColumn ( node , table , sb , ref firstItem , outputs ) ; } else if ( node . IsSameName ( PRIMARY_KEY_SECTION ) ) { DoReadPrimaryKeySection ( node , table ) ; } else if ( node . IsSameName ( INDEX_SECTION ) ) { DoReadIndexSection ( node , table ) ; } else if ( node . IsSameName ( SCRIPT_INCLUDE_SECTION ) ) { IncludeScriptFile ( node , outputs ) ; sb . AppendLine ( ) ; } else if ( node . IsSameName ( SCRIPT_TEXT_SECTION ) ) { IncludeScriptText ( node , outputs ) ; sb . AppendLine ( ) ; } else m_CompileErrors . Add ( new SchemaCompilationException ( node . RootPath , " " . Args ( tname , node . Name ) ) ) ; } DoPrimaryKeys ( table , sb , ref firstItem ) ; DoForeignKeys ( table , sb , ref firstItem , outputs ) ; sb . AppendLine ( ) ; sb . AppendLine ( " " ) ; var comment = tableNode . AttrByName ( COMMENT_ATTR ) . Value ; if ( comment . IsNotNullOrWhiteSpace ( ) ) { sb . AppendLine ( " " . Args ( TransformKeywordCase ( " " ) , EscapeString ( comment ) ) ) ; } sb . AppendLine ( GetStatementDelimiterScript ( RDBMSEntityType . Table , false ) ) ; sb . AppendLine ( ) ; DoTableIndexes ( table , outputs ) ; }
Override to compile a RDBMS Table
Override to compile a RDBMS Table
tableNode
IConfigSectionNode
outputs
Outputs