C# Class NMigrations.Sql.GenericSqlProvider

A general SQL generator implementation that implements the aspects that are common to all SQL dialects. Differences in SQL dialects are applied by subclassing GenericSqlProvider and overriding the specific methods.
Inheritance: ISqlProvider
Show file Open project: sklose/NMigrations

Public Methods

Method Description
GenerateSqlCommands ( Database database ) : IEnumerable

Generates the SQL commands for the specified database.

GetDefaultConstraintName ( string tableName, string columnName ) : string

Builds the name for a default constraint.

GetForeignKeyConstraintName ( string tableName, string columnNames, string relatedTableName, string relatedColumnNames ) : string

Builds the name for a foreign key constraint.

GetIndexName ( string tableName, string columnNames ) : string

Builds the name for an index.

GetPrimaryKeyConstraintName ( string tableName, string columnNames ) : string

Builds the name for a primary key constraint.

GetQuerySeparator ( ) : string

Gets the SQL command that separates multiple SQL queries in one SQL script file of each other.

GetUniqueConstraintName ( string tableName, string columnNames ) : string

Builds the name for a unique constraint.

Protected Methods

Method Description
AddDefaultConstraint ( DefaultConstraint defaultConstraint ) : IEnumerable

Enumerates the SQL commands that are necessary to create the specified defaultConstraint.

AddForeignKeyConstraint ( ForeignKeyConstraint fk ) : IEnumerable

Enumerates the SQL commands that are necessary to create the specified foreign key constraint (fk).

AddPrimaryKeyConstraint ( PrimaryKeyConstraint pk ) : IEnumerable

Enumerates the SQL commands that are necessary to create the specified primary key constraint (pk).

AddUniqueConstraint ( UniqueConstraint uniqueConstraint ) : IEnumerable

Enumerates the SQL commands that are necessary to create the specified uniqueConstraint.

AlterTable ( Table table ) : IEnumerable

Enumerates the SQL commands that are necessary to alter the specified table.

BuildAddColumn ( Column column ) : IEnumerable

Builds the SQL commands that adds the specified Column to its table.

BuildAlterColumnProperties ( Column column ) : IEnumerable

Builds the SQL commands that change the specified column's data type.

BuildAutoIncrement ( int seed, int step ) : string

Builds the SQL fragment that describes an auto-increment column.

BuildCreateTableColumn ( Column column ) : string

Builds the SQL fragment that describes a column in a CREATE TABLE statement.

BuildCreateTableConstraints ( Table table ) : IEnumerable

Builds the SQL fragments that follow after the column list in the CREATE TABLE statement (like constraints or indices).

BuildCreateTableForeignKeyConstraint ( ForeignKeyConstraint fk ) : string

Builds the SQL fragment that describes a foreign key constraint within a CREATE TABLE statement.

BuildCreateTablePrimaryKeyConstraint ( PrimaryKeyConstraint pk ) : string

Builds the SQL fragment that describes a primary key constraint within a CREATE TABLE statement.

BuildCreateTableUniqueConstraint ( UniqueConstraint uniqueConstraint ) : string

Builds the SQL fragment that describes a unqiue constraint within a CREATE TABLE statement.

BuildDataType ( SqlTypes type, int length, int scale, int precision ) : string

Builds the String that represents the specified type.

BuildDropColumn ( Column column ) : IEnumerable

Builds the SQL commands that drops the specified column from its table.

BuildDropDefault ( Column column ) : IEnumerable

Builds the SQL commands that drops the default value for the specified column.

BuildRenameColumn ( Column column ) : IEnumerable

Builds the SQL commands that renames the specified column.

CreateIndex ( System.Data.Common.Index index ) : IEnumerable

Enumerates the SQL commands that are necessary to create the specified index.

CreateTable ( Table table ) : IEnumerable

Enumerates the SQL commands that are necessary to create the specified table.

DropConstraint ( Constraint constraint ) : IEnumerable

Enumerates the SQL commands that are necessary to drop the specified constraint.

DropDefaultConstraint ( DefaultConstraint defaultConstraint ) : IEnumerable

Enumerates the SQL commands that are necessary to drop the specified defaultConstraint.

DropForeignKeyConstraint ( ForeignKeyConstraint fk ) : IEnumerable

Enumerates the SQL commands that are necessary to drop the specified foreign key constraint (fk).

DropIndex ( System.Data.Common.Index index ) : IEnumerable

Enumerates the SQL commands that are necessary to drop the specified index.

DropPrimaryKeyConstraint ( PrimaryKeyConstraint pk ) : IEnumerable

Enumerates the SQL commands that are necessary to drop the specified primary key constraint (pk).

DropTable ( Table table ) : IEnumerable

Enumerates the SQL commands that are necessary to drop the specified table.

DropUniqueConstraint ( UniqueConstraint uniqueConstraint ) : IEnumerable

Enumerates the SQL commands that are necessary to drop the specified uniqueConstraint.

EscapeColumnName ( string columnName ) : string

Escapes the specified columnName.

EscapeColumnNames ( string columnNames ) : string[]

Applies the EscapeColumnName method to an array of column names.

EscapeConstraintName ( string constraintName ) : string

Escapes the specified constraintName.

EscapeString ( string value ) : string

Escapes the specified string value that it can be surrounded by StringQuotes and used in a SQL query.

EscapeTableName ( string tableName ) : string

Escapes the specified tableName

ExecuteSqlStatement ( SqlStatement sql ) : IEnumerable

Enumerates the SQL commands that are necessary to execute the specified sql statement.

FormatValue ( object value ) : string

Formats the specified value according the described data type that it can be used in a SQL statement.

Insert ( Insert insert ) : IEnumerable

Generates the SQL statements that inserts the row described by the specified insert object into the database.

Update ( Update update ) : IEnumerable

Generates the SQL statements that updates rows described by the specified update object.

Method Details

AddDefaultConstraint() protected method

Enumerates the SQL commands that are necessary to create the specified defaultConstraint.
protected AddDefaultConstraint ( DefaultConstraint defaultConstraint ) : IEnumerable
defaultConstraint DefaultConstraint The default constraint.
return IEnumerable

AddForeignKeyConstraint() protected method

Enumerates the SQL commands that are necessary to create the specified foreign key constraint (fk).
protected AddForeignKeyConstraint ( ForeignKeyConstraint fk ) : IEnumerable
fk ForeignKeyConstraint The foreign key constraint.
return IEnumerable

AddPrimaryKeyConstraint() protected method

Enumerates the SQL commands that are necessary to create the specified primary key constraint (pk).
protected AddPrimaryKeyConstraint ( PrimaryKeyConstraint pk ) : IEnumerable
pk PrimaryKeyConstraint The primary key constraint.
return IEnumerable

AddUniqueConstraint() protected method

Enumerates the SQL commands that are necessary to create the specified uniqueConstraint.
protected AddUniqueConstraint ( UniqueConstraint uniqueConstraint ) : IEnumerable
uniqueConstraint UniqueConstraint The unique constraint.
return IEnumerable

AlterTable() protected method

Enumerates the SQL commands that are necessary to alter the specified table.
protected AlterTable ( Table table ) : IEnumerable
table Table The table to alter.
return IEnumerable

BuildAddColumn() protected method

Builds the SQL commands that adds the specified Column to its table.
protected BuildAddColumn ( Column column ) : IEnumerable
column Column The column.
return IEnumerable

BuildAlterColumnProperties() protected method

Builds the SQL commands that change the specified column's data type.
protected BuildAlterColumnProperties ( Column column ) : IEnumerable
column Column The column.
return IEnumerable

BuildAutoIncrement() protected abstract method

Builds the SQL fragment that describes an auto-increment column.
protected abstract BuildAutoIncrement ( int seed, int step ) : string
seed int The initial value.
step int The increment step.
return string

BuildCreateTableColumn() protected method

Builds the SQL fragment that describes a column in a CREATE TABLE statement.
protected BuildCreateTableColumn ( Column column ) : string
column Column The column.
return string

BuildCreateTableConstraints() protected method

Builds the SQL fragments that follow after the column list in the CREATE TABLE statement (like constraints or indices).
protected BuildCreateTableConstraints ( Table table ) : IEnumerable
table Table The table.
return IEnumerable

BuildCreateTableForeignKeyConstraint() protected method

Builds the SQL fragment that describes a foreign key constraint within a CREATE TABLE statement.
protected BuildCreateTableForeignKeyConstraint ( ForeignKeyConstraint fk ) : string
fk ForeignKeyConstraint The foreign key constraint.
return string

BuildCreateTablePrimaryKeyConstraint() protected method

Builds the SQL fragment that describes a primary key constraint within a CREATE TABLE statement.
protected BuildCreateTablePrimaryKeyConstraint ( PrimaryKeyConstraint pk ) : string
pk PrimaryKeyConstraint The primary key constraint.
return string

BuildCreateTableUniqueConstraint() protected method

Builds the SQL fragment that describes a unqiue constraint within a CREATE TABLE statement.
protected BuildCreateTableUniqueConstraint ( UniqueConstraint uniqueConstraint ) : string
uniqueConstraint UniqueConstraint The unique constraint.
return string

BuildDataType() protected abstract method

Builds the String that represents the specified type.
protected abstract BuildDataType ( SqlTypes type, int length, int scale, int precision ) : string
type SqlTypes The type.
length int The length.
scale int The scale.
precision int The precision.
return string

BuildDropColumn() protected method

Builds the SQL commands that drops the specified column from its table.
protected BuildDropColumn ( Column column ) : IEnumerable
column Column The column.
return IEnumerable

BuildDropDefault() protected method

Builds the SQL commands that drops the default value for the specified column.
protected BuildDropDefault ( Column column ) : IEnumerable
column Column The column.
return IEnumerable

BuildRenameColumn() protected method

Builds the SQL commands that renames the specified column.
protected BuildRenameColumn ( Column column ) : IEnumerable
column Column The column.
return IEnumerable

CreateIndex() protected method

Enumerates the SQL commands that are necessary to create the specified index.
protected CreateIndex ( System.Data.Common.Index index ) : IEnumerable
index System.Data.Common.Index The index to create.
return IEnumerable

CreateTable() protected method

Enumerates the SQL commands that are necessary to create the specified table.
protected CreateTable ( Table table ) : IEnumerable
table Table The table to create.
return IEnumerable

DropConstraint() protected method

Enumerates the SQL commands that are necessary to drop the specified constraint.
protected DropConstraint ( Constraint constraint ) : IEnumerable
constraint Constraint The constraint to drop.
return IEnumerable

DropDefaultConstraint() protected method

Enumerates the SQL commands that are necessary to drop the specified defaultConstraint.
protected DropDefaultConstraint ( DefaultConstraint defaultConstraint ) : IEnumerable
defaultConstraint DefaultConstraint The default constraint.
return IEnumerable

DropForeignKeyConstraint() protected method

Enumerates the SQL commands that are necessary to drop the specified foreign key constraint (fk).
protected DropForeignKeyConstraint ( ForeignKeyConstraint fk ) : IEnumerable
fk ForeignKeyConstraint The foreign key constraint.
return IEnumerable

DropIndex() protected method

Enumerates the SQL commands that are necessary to drop the specified index.
protected DropIndex ( System.Data.Common.Index index ) : IEnumerable
index System.Data.Common.Index The index to drop.
return IEnumerable

DropPrimaryKeyConstraint() protected method

Enumerates the SQL commands that are necessary to drop the specified primary key constraint (pk).
protected DropPrimaryKeyConstraint ( PrimaryKeyConstraint pk ) : IEnumerable
pk PrimaryKeyConstraint The primary key constraint.
return IEnumerable

DropTable() protected method

Enumerates the SQL commands that are necessary to drop the specified table.
protected DropTable ( Table table ) : IEnumerable
table Table The table to drop.
return IEnumerable

DropUniqueConstraint() protected method

Enumerates the SQL commands that are necessary to drop the specified uniqueConstraint.
protected DropUniqueConstraint ( UniqueConstraint uniqueConstraint ) : IEnumerable
uniqueConstraint UniqueConstraint The unique constraint.
return IEnumerable

EscapeColumnName() protected abstract method

Escapes the specified columnName.
protected abstract EscapeColumnName ( string columnName ) : string
columnName string Name of the column.
return string

EscapeColumnNames() protected method

Applies the EscapeColumnName method to an array of column names.
protected EscapeColumnNames ( string columnNames ) : string[]
columnNames string The column names.
return string[]

EscapeConstraintName() protected abstract method

Escapes the specified constraintName.
protected abstract EscapeConstraintName ( string constraintName ) : string
constraintName string Name of the constraint.
return string

EscapeString() protected method

Escapes the specified string value that it can be surrounded by StringQuotes and used in a SQL query.
protected EscapeString ( string value ) : string
value string The string value to escape.
return string

EscapeTableName() protected abstract method

Escapes the specified tableName
protected abstract EscapeTableName ( string tableName ) : string
tableName string Name of the table.
return string

ExecuteSqlStatement() protected method

Enumerates the SQL commands that are necessary to execute the specified sql statement.
protected ExecuteSqlStatement ( SqlStatement sql ) : IEnumerable
sql SqlStatement The SQL statement.
return IEnumerable

FormatValue() protected method

Formats the specified value according the described data type that it can be used in a SQL statement.
protected FormatValue ( object value ) : string
value object The value.
return string

GenerateSqlCommands() public method

Generates the SQL commands for the specified database.
public GenerateSqlCommands ( Database database ) : IEnumerable
database Database The database.
return IEnumerable

GetDefaultConstraintName() public method

Builds the name for a default constraint.
public GetDefaultConstraintName ( string tableName, string columnName ) : string
tableName string Name of the table.
columnName string The column name.
return string

GetForeignKeyConstraintName() public method

Builds the name for a foreign key constraint.
public GetForeignKeyConstraintName ( string tableName, string columnNames, string relatedTableName, string relatedColumnNames ) : string
tableName string Name of the table.
columnNames string The column names.
relatedTableName string Name of the related table.
relatedColumnNames string The related column names.
return string

GetIndexName() public method

Builds the name for an index.
public GetIndexName ( string tableName, string columnNames ) : string
tableName string Name of the table.
columnNames string The column names.
return string

GetPrimaryKeyConstraintName() public method

Builds the name for a primary key constraint.
public GetPrimaryKeyConstraintName ( string tableName, string columnNames ) : string
tableName string Name of the table.
columnNames string The column names.
return string

GetQuerySeparator() public abstract method

Gets the SQL command that separates multiple SQL queries in one SQL script file of each other.
public abstract GetQuerySeparator ( ) : string
return string

GetUniqueConstraintName() public method

Builds the name for a unique constraint.
public GetUniqueConstraintName ( string tableName, string columnNames ) : string
tableName string Name of the table.
columnNames string The column names.
return string

Insert() protected method

Generates the SQL statements that inserts the row described by the specified insert object into the database.
protected Insert ( Insert insert ) : IEnumerable
insert Insert The insert containing the row to insert.
return IEnumerable

Update() protected method

Generates the SQL statements that updates rows described by the specified update object.
protected Update ( Update update ) : IEnumerable
update Update The update command.
return IEnumerable