protected void AppendTable(StatementCreateTable statementCreateTable) { var table = statementCreateTable.Table; this.Builder.Append("CREATE "); this.AppendTempKeyword(table.FullName); this.Builder.Append("TABLE "); statementCreateTable.Table.FullName.Accept(this.ExprBuilder, null); this.Builder.Append('('); ColumnAnalysis analysis = ColumnAnalysis.Build(); for (int i = 0; i < table.Columns.Count; i++) { if (i != 0) { this.Builder.Append(','); } var column = table.Columns[i]; analysis.Analyze(column); this.AppendColumn(column: column); } this.AppendPkConstraints(table, analysis); this.AppendFkConstraints(table, analysis); this.AppendIndexesInside(table); this.Builder.Append(')'); this.Builder.Append(';'); this.AppendIndexesOutside(table); }
private void AppendPkConstraints(TableBase table, ColumnAnalysis analysis) { if (analysis.Pk.Count < 1) { return; } this.Builder.Append(",CONSTRAINT "); this.AppendName(this.BuildPkName(table.FullName)); this.Builder.Append(" PRIMARY KEY "); this.ExprBuilder.AcceptListComaSeparatedPar('(', analysis.Pk, ')', null); }
private void AppendFkConstraints(TableBase table, ColumnAnalysis analysis) { foreach (var analysisFk in analysis.Fks) { var foreignTable = analysisFk.Key; var pairList = analysisFk.Value; this.Builder.Append(",CONSTRAINT "); this.AppendName(this.BuildFkName(table.FullName, foreignTable)); this.Builder.Append(" FOREIGN KEY "); this.ExprBuilder.AcceptListComaSeparatedPar('(', pairList.SelectToReadOnlyList(i => i.Internal), ')', null); this.Builder.Append(" REFERENCES "); foreignTable.Accept(this.ExprBuilder, null); this.ExprBuilder.AcceptListComaSeparatedPar('(', pairList.SelectToReadOnlyList(i => i.External), ')', null); } }