private void AddTablePrimaryIndex(PrimaryKeyOperation operation) { if (operation == null) { return; } AddTableIndex(operation.Table, operation.Columns, true); }
/// <summary> /// Generate column definition. Returns <c>true</c> if the column was the primary key. /// </summary> private bool Generate(ColumnModel column, IndentedTextWriter tw, PrimaryKeyOperation primaryKeyOp) { var isIdPk = false; tw.Write(column.Name); tw.Write(" "); var isPrimaryKey = false; if (primaryKeyOp != null) { isPrimaryKey = primaryKeyOp.Columns.Contains(column.Name); } if (isPrimaryKey) { if ((column.Type == PrimitiveTypeKind.Int16) || (column.Type == PrimitiveTypeKind.Int32)) { tw.Write(" INTEGER "); } else { tw.Write(BuildColumnType(column)); } if (column.IsIdentity) { tw.Write(" PRIMARY KEY AUTOINCREMENT "); isIdPk = true; } } else { tw.Write(BuildColumnType(column)); if ((column.IsNullable != null) && !column.IsNullable.Value) { tw.Write(" NOT NULL"); } if (column.DefaultValue != null) { tw.Write(" DEFAULT "); tw.Write(Generate((dynamic)column.DefaultValue)); } else if (!string.IsNullOrWhiteSpace(column.DefaultValueSql)) { tw.Write(" DEFAULT "); tw.Write(column.DefaultValueSql); } } return(isIdPk); }
private void Generate(PrimaryKeyOperation addPrimaryKeyOperation) { Contract.Requires(addPrimaryKeyOperation != null); using (var writer = Writer()) { writer.Write("ALTER TABLE "); writer.Write(Name(addPrimaryKeyOperation.Table)); writer.Write(" ADD CONSTRAINT "); writer.Write(Quote(addPrimaryKeyOperation.Name)); writer.Write(" PRIMARY KEY ("); writer.Write(addPrimaryKeyOperation.Columns.Select(Quote).Join()); writer.Write(")"); Statement(writer); } }
private void Generate(ColumnModel cmDadosColuna, IndentedTextWriter textWriter, PrimaryKeyOperation opePrimaryKey) { textWriter.Write(cmDadosColuna.Name); textWriter.Write(" "); bool lblnEhPrimaryKey = false; if (opePrimaryKey != null) { lblnEhPrimaryKey = opePrimaryKey.Columns.Contains(cmDadosColuna.Name); } if (lblnEhPrimaryKey) { if ((cmDadosColuna.Type == PrimitiveTypeKind.Int16) || (cmDadosColuna.Type == PrimitiveTypeKind.Int32)) { textWriter.Write(" INTEGER "); } else { textWriter.Write(ConstruirTipoColuna(cmDadosColuna)); } if (cmDadosColuna.IsIdentity) { textWriter.Write(" PRIMARY KEY AUTOINCREMENT "); pblnGerouPrimaryKey = true; } } else { textWriter.Write(ConstruirTipoColuna(cmDadosColuna)); if ((cmDadosColuna.IsNullable != null) && !cmDadosColuna.IsNullable.Value) { textWriter.Write(" NOT NULL"); } if (cmDadosColuna.DefaultValue != null) { textWriter.Write(" DEFAULT "); textWriter.Write(Generate((dynamic)cmDadosColuna.DefaultValue)); } else if (!string.IsNullOrWhiteSpace(cmDadosColuna.DefaultValueSql)) { textWriter.Write(" DEFAULT "); textWriter.Write(cmDadosColuna.DefaultValueSql); } } }
/// <summary> /// Generate column definition. Returns <c>true</c> if the column was the primary key. /// </summary> private bool Generate(ColumnModel column, IndentedTextWriter tw, PrimaryKeyOperation primaryKeyOp) { bool isIdPk = false; tw.Write(Format.ReservedWord(column.Name)); tw.Write(" "); bool isPrimaryKey = false; if (primaryKeyOp != null) { isPrimaryKey = primaryKeyOp.Columns.Contains(column.Name); } if (isPrimaryKey) { if ((column.Type == PrimitiveTypeKind.Int16) || (column.Type == PrimitiveTypeKind.Int32)) { tw.Write("INTEGER"); } else { tw.Write(Format.BuildColumnType(_providerManifest, column)); } if (column.IsIdentity || column.Annotations.ContainsKey("Autoincrement")) { tw.Write(" PRIMARY KEY"); isIdPk = true; if (column.Annotations.ContainsKey("Autoincrement")) { tw.Write(" AUTOINCREMENT"); } } } else { tw.Write(Format.BuildColumnType(_providerManifest, column)); if ((column.IsNullable != null) && !column.IsNullable.Value) { tw.Write(" NOT NULL"); } if (column.DefaultValue != null) { tw.Write(" DEFAULT "); tw.Write(Generate((dynamic)column.DefaultValue)); } else if (!string.IsNullOrWhiteSpace(column.DefaultValueSql)) { tw.Write(" DEFAULT "); tw.Write("(" + column.DefaultValueSql + ")"); } AnnotationValues uniqueAnnotation; if (column.Annotations.TryGetValue("Unique", out uniqueAnnotation)) { tw.Write(" UNIQUE" + Format.UniqueConflictText(uniqueAnnotation)); } AnnotationValues collateAnnotation; if (column.Annotations.TryGetValue("Collate", out collateAnnotation)) { tw.Write(Format.CollateFunctionText(collateAnnotation)); } } return(isIdPk); }
private void Generate(PrimaryKeyOperation primaryKeyOperation) { throw new NotImplementedException(); }