Class SQLiteCodeGenerator
Generates SQLite-specific SQL scripts for database schema and data migrations. This class is designed to provide a SQLite-compatible implementation of the base CodeGenerator functionalities. It facilitates the generation of database schema definitions, constraints, and data migration scripts tailored for SQLite databases.
public class SQLiteCodeGenerator : CodeGenerator, IVisitor, IDisposable
- Inheritance
-
SQLiteCodeGenerator
- Implements
- Inherited Members
Constructors
SQLiteCodeGenerator()
Initializes a new instance of the SQLiteCodeGenerator class.
public SQLiteCodeGenerator()
SQLiteCodeGenerator(TextWriter)
Initializes a new instance of the SQLiteCodeGenerator class with the specified TextWriter for output.
public SQLiteCodeGenerator(TextWriter output)
Parameters
outputTextWriterThe TextWriter to which the generated SQL will be written. Must not be null.
SQLiteCodeGenerator(string)
Initializes a new instance of the SQLiteCodeGenerator class that writes output to a file at the specified path.
public SQLiteCodeGenerator(string path)
Parameters
pathstringThe file path where the generated SQL will be written. 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
RequireInlineConstraints
Gets a value indicating whether this code generator requires foreign key constraints to be included inline within the CREATE TABLE statements, as opposed to being generated as separate ALTER TABLE statements after the tables are created.
protected override bool RequireInlineConstraints { get; }
Property Value
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
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
valueobjectThe 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.
columnTypeColumnTypeThe 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.
GetKeyName(Key)
Gets the name to be used for a key (such as an index or foreign key constraint) in the generated SQL.
protected override string GetKeyName(Key key)
Parameters
keyKeyThe key for which to get the name. This method is called when generating SQL for indexes and foreign key constraints, and it determines how to name these keys in the generated SQL. The default implementation returns the escaped name of the key, but derived classes can override this method to provide different naming conventions or to include additional information in the key name as needed by the target database provider.
Returns
- string
A string representing the name to be used for the key in the generated SQL, 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
itemIDataItemThe 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.
VisitColumn(Column)
Visits a Column object, allowing the visitor to perform operations on the column schema.
public override void VisitColumn(Column column)
Parameters
columnColumnThe Column object to be visited.
VisitForeignKey(ForeignKey)
Visits a ForeignKey object, allowing the visitor to perform operations on the foreign key schema.
public override void VisitForeignKey(ForeignKey foreignKey)
Parameters
foreignKeyForeignKeyThe ForeignKey object to be visited.
VisitPrimaryKey(PrimaryKey)
Visits a PrimaryKey object, allowing the visitor to perform operations on the primary key schema.
public override void VisitPrimaryKey(PrimaryKey primaryKey)
Parameters
primaryKeyPrimaryKeyThe PrimaryKey object to be visited.
WriteDataMigrationPrefix()
Writes any necessary SQL statements or directives that should be included before the data migration (INSERT statements) for the tables.
protected override void WriteDataMigrationPrefix()
WriteDataMigrationSuffix()
Writes any necessary SQL statements or directives that should be included after the data migration (INSERT statements) for the tables.
protected override void WriteDataMigrationSuffix()