Class DB2CodeGenerator

Namespace
DbExport.Providers.DB2
Assembly
DbExport.Api.dll

A specialized implementation of the CodeGenerator class for generating DB2-specific database schema and code representations. This class is responsible for transforming database schema information into DB2-compliant SQL code or other DB2-related output.

public class DB2CodeGenerator : CodeGenerator, IVisitor, IDisposable
Inheritance
DB2CodeGenerator
Implements
Inherited Members

Constructors

DB2CodeGenerator()

Initializes a new instance of the CodeGenerator class that writes output to the console.

public DB2CodeGenerator()

DB2CodeGenerator(TextWriter)

Initializes a new instance of the CodeGenerator class with the specified TextWriter for output.

public DB2CodeGenerator(TextWriter output)

Parameters

output TextWriter

The TextWriter to which the generated SQL will be written. Must not be null.

DB2CodeGenerator(string)

Initializes a new instance of the CodeGenerator class that writes output to a file at the specified path.

public DB2CodeGenerator(string path)

Parameters

path string

The file path where the generated SQL will be written. The file will be created if it does not exist, or appended to if it does. Must not be null or empty.

Properties

ProviderName

Gets the name of the database provider for which this code generator is designed to generate SQL scripts.

public override string ProviderName { get; }

Property Value

string

SupportsDbCreation

Gets a value indicating whether this code generator supports generating a CREATE DATABASE statement as part of the export process.

protected override bool SupportsDbCreation { get; }

Property Value

bool

Methods

Format(object, ColumnType)

Formats a value for inclusion in a SQL statement, taking into account the value's type and the corresponding column type.

protected override string Format(object value, ColumnType columnType)

Parameters

value object

The value to be formatted for inclusion in a SQL statement. This could be a default value for a column, a value being inserted into a table, or any other value that needs to be represented as a literal in the generated SQL. The method will determine how to format this value based on its type and the specified column type, ensuring that it is correctly represented in the SQL syntax for the target database provider.

columnType ColumnType

The column type that corresponds to the value being formatted. This information is used to determine how to format the value, such as whether to quote it, how to format dates and times, how to represent binary data, etc., according to the conventions of the target database provider.

Returns

string

A string representing the formatted value, ready to be included as a literal in a SQL statement, formatted according to the conventions of the target database provider.

GetTypeName(IDataItem)

Gets the SQL type name for the given data item, which could be a column or a user-defined data type.

protected override string GetTypeName(IDataItem item)

Parameters

item IDataItem

The data item for which to determine the SQL type name. This could be a column or a user-defined data type. The method will use the properties of the data item, such as ColumnType, Size, Precision, and Scale, to determine the appropriate SQL type name, potentially using provider-specific type mappings and formatting rules.

Returns

string

A string representing the SQL type name for the data item, formatted according to the conventions of the target database provider.

WriteIdentitySpecification(Column)

Writes the identity specification for the specified column.

protected override void WriteIdentitySpecification(Column column)

Parameters

column Column

The column for which the identity specification is being written.