C# Class SQLiteConversionEngine.Converters.BaseConverter

This class is resposible to take a single SQL Server database and convert it to an SQLite database file.
The class knows how to convert table and index structures only.
Afficher le fichier Open project: johnmbaughman/SQLiteConverter

Protected Properties

Свойство Type Description
_cancelled bool
_defaultValueRx System.Text.RegularExpressions.Regex
_isActive bool
_keyRx System.Text.RegularExpressions.Regex

Méthodes publiques

Méthode Description
CancelConversion ( ) : void

Cancels the conversion.

ConvertToDatabase ( SqlConnection sqlConnection, SQLiteConnection sqliteConnection, SqlConversionHandler sqlConversionHandler, SqlTableSelectionHandler sqlTableSelectionHandler, FailedViewDefinitionHandler failedViewDefinitionHandler, bool createTriggers ) : void

This method takes as input the connection to an SQL Server database and creates a corresponding SQLite database file with a schema derived from the SQL Server database.

The method continues asynchronously in the background and the caller returned immediatly.

ConvertToDatabase ( string sqlServerConnectionString, SQLiteConnection sqliteConnection, SqlConversionHandler sqlConversionHandler, SqlTableSelectionHandler sqlTableSelectionHandler, FailedViewDefinitionHandler failedViewDefinitionHandler, bool createTriggers ) : void

This method takes as input the connection string to an SQL Server database and creates a corresponding SQLite database file with a schema derived from the SQL Server database.

The method continues asynchronously in the background and the caller returned immediatly.

ConvertToDatabase ( string sqlServerConnectionString, string sqliteConnectionString, SqlConversionHandler sqlConversionHandler, SqlTableSelectionHandler sqlTableSelectionHandler, FailedViewDefinitionHandler failedViewDefinitionHandler, bool createTriggers ) : void

This method takes as input the connection string to an SQL Server database and creates a corresponding SQLite database file with a schema derived from the SQL Server database.

The method continues asynchronously in the background and the caller returned immediatly.

InitializeSQLiteConnection ( string sqliteConnectionString ) : SQLiteConnection
InitializeSQLiteDatabase ( SQLiteConnection sqliteConnection, List PragmaCommands ) : void
InitializeSqlServerConnection ( string sqlServerConnectionString ) : SqlConnection
InitializeSqlServerDatabase ( SqlConnection sqlConnection ) : void

Méthodes protégées

Méthode Description
AddTriggersForForeignKeys ( SQLiteConnection sqliteConnection, IEnumerable schema, SqlConversionHandler handler ) : void
AddTriggersForForeignKeys ( string sqlitePath, IEnumerable schema, string password, SqlConversionHandler handler ) : void
AdjustDefaultValue ( string val ) : string

More adjustments for the DEFAULT value clause.

BuildIndexSchema ( string indexName, string desc, string keys ) : IndexSchema

Builds an index schema object from the specified components (Read from SQL Server).

BuildSQLiteInsert ( TableSchema ts ) : SQLiteCommand

Creates a command object needed to insert values into a specific SQLite table.

BuildSQLiteUpdate ( TableSchema ts ) : SQLiteCommand

Creates a command object needed to insert values into a specific SQLite table.

BuildSourceTableQuery ( TableSchema tableSchema ) : string

Builds a SELECT query for a specific table. Needed in the process of copying rows from the SQL Server database to the SQLite database.

BuildSqlServerInsert ( TableSchema ts ) : SqlCommand

Creates a command object needed to insert values into a specific SQLite table.

CastValueForColumn ( object val, ColumnSchema columnSchema ) : object

Used in order to adjust the value received from SQL Servr for the SQLite database.

CheckCancelled ( ) : void

Convenience method for checking if the conversion progress needs to be cancelled.

ConvertSourceDatabaseToDestination ( SqlConnection sqlConnection, SQLiteConnection sqliteConnection, SqlConversionHandler sqlConversionHandler, SqlTableSelectionHandler sqlTableSelectionHandler, FailedViewDefinitionHandler failedViewDefinitionHandler, bool createTriggers ) : void

Do the entire process of first reading the SQL Server schema, creating a corresponding SQLite schema, and copying all rows from the SQL Server database to the SQLite database.

CopySourceDatabaseRowsToDestination ( SqlConnection sqlConnection, SQLiteConnection sqliteConnection, List schema, SqlConversionHandler handler ) : void

Copies table rows from the SQL Server database to the SQLite database.

CreateForeignKeySchema ( IDbConnection sourceConnection, TableSchema tableSchema ) : void

Add foreign key schema object from the specified components (Read from SQL Server).

CreateSQLiteConnectionString ( string sqlitePath, string password ) : string

Creates SQLite connection string from the specified DB file path.

CreateSQLiteDatabase ( SQLiteConnection sqliteConnection, DatabaseSchema schema, SqlConversionHandler handler, FailedViewDefinitionHandler viewFailureHandler ) : void

Creates the SQLite database.

CreateSQLiteDatabase ( string sqlitePath, DatabaseSchema schema, string password, SqlConversionHandler handler, FailedViewDefinitionHandler viewFailureHandler ) : void

Creates the SQLite database from the schema read from the SQL Server.

CreateSqlServerConnectionString ( string sqlitePath, string password ) : string

Creates SQLite connection string from the specified DB file path.

CreateSqlServerDatabase ( SQLiteConnection sqliteConnection, DatabaseSchema schema, SqlConversionHandler handler, FailedViewDefinitionHandler viewFailureHandler ) : void

Creates the SQLite database.

CreateSqlServerDatabase ( string sqlitePath, DatabaseSchema schema, string password, SqlConversionHandler handler, FailedViewDefinitionHandler viewFailureHandler ) : void

Creates the SQLite database from the schema read from the SQL Server.

CreateTableSchema ( IDbConnection sourceConnection, string tableName, string tableSchemaName ) : TableSchema

Creates a TableSchema object using the specified SQL Server connection and the name of the table for which we need to create the schema.

FixDefaultValueString ( string colDefault ) : string

Does some necessary adjustments to a value string that appears in a column DEFAULT clause.

GetDbTypeOfColumn ( ColumnSchema columnSchema ) : DbType

Matches SQL Server types to general DB types

GetNormalizedName ( string str, List names ) : string

Used in order to avoid breaking naming rules (e.g., when a table has a name in SQL Server that cannot be used as a basis for a matching index name in SQLite).

ParseBlobAsGuid ( byte blob ) : System.Guid
ParseStringAsGuid ( string str ) : System.Guid
ReadSourceSchema ( SqlConnection sqlConnection, SqlConversionHandler sqlConversionHandler, SqlTableSelectionHandler sqlTableSelectionHandler ) : DatabaseSchema

Reads the entire SQL Server DB schema using the specified connection string.

ValidateDataType ( string dataType ) : void

Small validation method to make sure we don't miss anything without getting an exception.

WriteTriggerSchema ( TriggerSchema ts ) : string

Gets a create script for the triggerSchema in SQLite syntax

Private Methods

Méthode Description
AddSQLiteTable ( SQLiteConnection conn, TableSchema dt ) : void

Creates the CREATE TABLE DDL for SQLite and a specific table.

AddSQLiteView ( SQLiteConnection conn, ViewSchema vs, FailedViewDefinitionHandler handler ) : void
AddTableTriggers ( SQLiteConnection conn, TableSchema dt ) : void
BuildColumnStatement ( ColumnSchema col, TableSchema ts, bool &pkey ) : string

Used when creating the CREATE TABLE DDL. Creates a single row for the specified column.

BuildCreateIndex ( string tableName, IndexSchema indexSchema ) : string

Creates a CREATE INDEX DDL for the specified table and index schema.

BuildCreateTableQuery ( TableSchema ts ) : string

returns the CREATE TABLE DDL for creating the SQLite table from the specified table schema object.

DiscardNational ( string value ) : string

Discards the national prefix if exists (e.g., N'sometext') which is not supported in SQLite.

IsSingleQuoted ( string value ) : bool
IsValidDefaultValue ( string value ) : bool

Check if the DEFAULT clause is valid by SQLite standards

StripParens ( string value ) : string

Strip any parentheses from the string.

Method Details

AddTriggersForForeignKeys() protected static méthode

protected static AddTriggersForForeignKeys ( SQLiteConnection sqliteConnection, IEnumerable schema, SqlConversionHandler handler ) : void
sqliteConnection System.Data.SQLite.SQLiteConnection
schema IEnumerable
handler SqlConversionHandler
Résultat void

AddTriggersForForeignKeys() protected static méthode

protected static AddTriggersForForeignKeys ( string sqlitePath, IEnumerable schema, string password, SqlConversionHandler handler ) : void
sqlitePath string
schema IEnumerable
password string
handler SqlConversionHandler
Résultat void

AdjustDefaultValue() protected static méthode

More adjustments for the DEFAULT value clause.
protected static AdjustDefaultValue ( string val ) : string
val string The value to adjust
Résultat string

BuildIndexSchema() protected static méthode

Builds an index schema object from the specified components (Read from SQL Server).
protected static BuildIndexSchema ( string indexName, string desc, string keys ) : IndexSchema
indexName string The name of the index
desc string The description of the index
keys string Key columns that are part of the index.
Résultat SQLiteConversionEngine.ConversionData.IndexSchema

BuildSQLiteInsert() protected static méthode

Creates a command object needed to insert values into a specific SQLite table.
protected static BuildSQLiteInsert ( TableSchema ts ) : SQLiteCommand
ts SQLiteConversionEngine.ConversionData.TableSchema The table schema object for the table.
Résultat System.Data.SQLite.SQLiteCommand

BuildSQLiteUpdate() protected static méthode

Creates a command object needed to insert values into a specific SQLite table.
protected static BuildSQLiteUpdate ( TableSchema ts ) : SQLiteCommand
ts SQLiteConversionEngine.ConversionData.TableSchema The table schema object for the table.
Résultat System.Data.SQLite.SQLiteCommand

BuildSourceTableQuery() protected abstract méthode

Builds a SELECT query for a specific table. Needed in the process of copying rows from the SQL Server database to the SQLite database.
protected abstract BuildSourceTableQuery ( TableSchema tableSchema ) : string
tableSchema SQLiteConversionEngine.ConversionData.TableSchema
Résultat string

BuildSqlServerInsert() protected static méthode

Creates a command object needed to insert values into a specific SQLite table.
protected static BuildSqlServerInsert ( TableSchema ts ) : SqlCommand
ts SQLiteConversionEngine.ConversionData.TableSchema The table schema object for the table.
Résultat System.Data.SqlClient.SqlCommand

CancelConversion() public méthode

Cancels the conversion.
public CancelConversion ( ) : void
Résultat void

CastValueForColumn() protected static méthode

Used in order to adjust the value received from SQL Servr for the SQLite database.
protected static CastValueForColumn ( object val, ColumnSchema columnSchema ) : object
val object The value object
columnSchema ColumnSchema The corresponding column schema
Résultat object

CheckCancelled() protected static méthode

Convenience method for checking if the conversion progress needs to be cancelled.
protected static CheckCancelled ( ) : void
Résultat void

ConvertSourceDatabaseToDestination() protected abstract méthode

Do the entire process of first reading the SQL Server schema, creating a corresponding SQLite schema, and copying all rows from the SQL Server database to the SQLite database.
protected abstract ConvertSourceDatabaseToDestination ( SqlConnection sqlConnection, SQLiteConnection sqliteConnection, SqlConversionHandler sqlConversionHandler, SqlTableSelectionHandler sqlTableSelectionHandler, FailedViewDefinitionHandler failedViewDefinitionHandler, bool createTriggers ) : void
sqlConnection System.Data.SqlClient.SqlConnection The SQL connection.
sqliteConnection System.Data.SQLite.SQLiteConnection The SQLite connection.
sqlConversionHandler SqlConversionHandler The SQL conversion handler.
sqlTableSelectionHandler SqlTableSelectionHandler The SQL table selection handler.
failedViewDefinitionHandler FailedViewDefinitionHandler The failed view definition handler.
createTriggers bool if set to true [create triggers].
Résultat void

ConvertToDatabase() public abstract méthode

This method takes as input the connection to an SQL Server database and creates a corresponding SQLite database file with a schema derived from the SQL Server database.
The method continues asynchronously in the background and the caller returned immediatly.
public abstract ConvertToDatabase ( SqlConnection sqlConnection, SQLiteConnection sqliteConnection, SqlConversionHandler sqlConversionHandler, SqlTableSelectionHandler sqlTableSelectionHandler, FailedViewDefinitionHandler failedViewDefinitionHandler, bool createTriggers ) : void
sqlConnection System.Data.SqlClient.SqlConnection The SQL connection.
sqliteConnection System.Data.SQLite.SQLiteConnection The SQLite connection.
sqlConversionHandler SqlConversionHandler The SQL conversion handler.
sqlTableSelectionHandler SqlTableSelectionHandler The SQL table selection handler.
failedViewDefinitionHandler FailedViewDefinitionHandler The failed view definition handler.
createTriggers bool if set to true [create triggers].
Résultat void

ConvertToDatabase() public abstract méthode

This method takes as input the connection string to an SQL Server database and creates a corresponding SQLite database file with a schema derived from the SQL Server database.
The method continues asynchronously in the background and the caller returned immediatly.
public abstract ConvertToDatabase ( string sqlServerConnectionString, SQLiteConnection sqliteConnection, SqlConversionHandler sqlConversionHandler, SqlTableSelectionHandler sqlTableSelectionHandler, FailedViewDefinitionHandler failedViewDefinitionHandler, bool createTriggers ) : void
sqlServerConnectionString string The connection string to the SQL Server database.
sqliteConnection System.Data.SQLite.SQLiteConnection The path to the SQLite database file that needs to get created.
sqlConversionHandler SqlConversionHandler The SQL conversion handler.
sqlTableSelectionHandler SqlTableSelectionHandler The SQL table selection handler.
failedViewDefinitionHandler FailedViewDefinitionHandler The failed view definition handler.
createTriggers bool if set to true [create triggers].
Résultat void

ConvertToDatabase() public abstract méthode

This method takes as input the connection string to an SQL Server database and creates a corresponding SQLite database file with a schema derived from the SQL Server database.
The method continues asynchronously in the background and the caller returned immediatly.
public abstract ConvertToDatabase ( string sqlServerConnectionString, string sqliteConnectionString, SqlConversionHandler sqlConversionHandler, SqlTableSelectionHandler sqlTableSelectionHandler, FailedViewDefinitionHandler failedViewDefinitionHandler, bool createTriggers ) : void
sqlServerConnectionString string The connection string to the SQL Server database.
sqliteConnectionString string The connection string to the SQLite database.
sqlConversionHandler SqlConversionHandler The SQL conversion handler.
sqlTableSelectionHandler SqlTableSelectionHandler
failedViewDefinitionHandler FailedViewDefinitionHandler The failed view definition handler.
createTriggers bool if set to true [create triggers].
Résultat void

CopySourceDatabaseRowsToDestination() protected abstract méthode

Copies table rows from the SQL Server database to the SQLite database.
protected abstract CopySourceDatabaseRowsToDestination ( SqlConnection sqlConnection, SQLiteConnection sqliteConnection, List schema, SqlConversionHandler handler ) : void
sqlConnection System.Data.SqlClient.SqlConnection The SQL connection.
sqliteConnection System.Data.SQLite.SQLiteConnection The SQLite connection.
schema List The schema of the SQL Server database.
handler SqlConversionHandler A handler to handle progress notifications.
Résultat void

CreateForeignKeySchema() protected abstract méthode

Add foreign key schema object from the specified components (Read from SQL Server).
protected abstract CreateForeignKeySchema ( IDbConnection sourceConnection, TableSchema tableSchema ) : void
sourceConnection IDbConnection
tableSchema SQLiteConversionEngine.ConversionData.TableSchema
Résultat void

CreateSQLiteConnectionString() protected static méthode

Creates SQLite connection string from the specified DB file path.
protected static CreateSQLiteConnectionString ( string sqlitePath, string password ) : string
sqlitePath string The path to the SQLite database file.
password string
Résultat string

CreateSQLiteDatabase() protected static méthode

Creates the SQLite database.
protected static CreateSQLiteDatabase ( SQLiteConnection sqliteConnection, DatabaseSchema schema, SqlConversionHandler handler, FailedViewDefinitionHandler viewFailureHandler ) : void
sqliteConnection System.Data.SQLite.SQLiteConnection The SQLite connection.
schema DatabaseSchema The schema.
handler SqlConversionHandler The handler.
viewFailureHandler FailedViewDefinitionHandler The view failure handler.
Résultat void

CreateSQLiteDatabase() protected static méthode

Creates the SQLite database from the schema read from the SQL Server.
protected static CreateSQLiteDatabase ( string sqlitePath, DatabaseSchema schema, string password, SqlConversionHandler handler, FailedViewDefinitionHandler viewFailureHandler ) : void
sqlitePath string The path to the generated DB file.
schema DatabaseSchema The schema of the SQL server database.
password string The password to use for encrypting the DB or null if non is needed.
handler SqlConversionHandler A handle for progress notifications.
viewFailureHandler FailedViewDefinitionHandler
Résultat void

CreateSqlServerConnectionString() protected static méthode

Creates SQLite connection string from the specified DB file path.
protected static CreateSqlServerConnectionString ( string sqlitePath, string password ) : string
sqlitePath string The path to the SQLite database file.
password string
Résultat string

CreateSqlServerDatabase() protected static méthode

Creates the SQLite database.
protected static CreateSqlServerDatabase ( SQLiteConnection sqliteConnection, DatabaseSchema schema, SqlConversionHandler handler, FailedViewDefinitionHandler viewFailureHandler ) : void
sqliteConnection System.Data.SQLite.SQLiteConnection The SQLite connection.
schema DatabaseSchema The schema.
handler SqlConversionHandler The handler.
viewFailureHandler FailedViewDefinitionHandler The view failure handler.
Résultat void

CreateSqlServerDatabase() protected static méthode

Creates the SQLite database from the schema read from the SQL Server.
protected static CreateSqlServerDatabase ( string sqlitePath, DatabaseSchema schema, string password, SqlConversionHandler handler, FailedViewDefinitionHandler viewFailureHandler ) : void
sqlitePath string The path to the generated DB file.
schema DatabaseSchema The schema of the SQL server database.
password string The password to use for encrypting the DB or null if non is needed.
handler SqlConversionHandler A handle for progress notifications.
viewFailureHandler FailedViewDefinitionHandler
Résultat void

CreateTableSchema() protected abstract méthode

Creates a TableSchema object using the specified SQL Server connection and the name of the table for which we need to create the schema.
protected abstract CreateTableSchema ( IDbConnection sourceConnection, string tableName, string tableSchemaName ) : TableSchema
sourceConnection IDbConnection
tableName string The name of the table for which we wants to create the table schema.
tableSchemaName string
Résultat SQLiteConversionEngine.ConversionData.TableSchema

FixDefaultValueString() protected static méthode

Does some necessary adjustments to a value string that appears in a column DEFAULT clause.
protected static FixDefaultValueString ( string colDefault ) : string
colDefault string The original default value string (as read from SQL Server).
Résultat string

GetDbTypeOfColumn() protected static méthode

Matches SQL Server types to general DB types
protected static GetDbTypeOfColumn ( ColumnSchema columnSchema ) : DbType
columnSchema ColumnSchema The column schema to use for the match
Résultat DbType

GetNormalizedName() protected static méthode

Used in order to avoid breaking naming rules (e.g., when a table has a name in SQL Server that cannot be used as a basis for a matching index name in SQLite).
protected static GetNormalizedName ( string str, List names ) : string
str string The name to change if necessary
names List Used to avoid duplicate names
Résultat string

InitializeSQLiteConnection() public méthode

public InitializeSQLiteConnection ( string sqliteConnectionString ) : SQLiteConnection
sqliteConnectionString string
Résultat System.Data.SQLite.SQLiteConnection

InitializeSQLiteDatabase() public méthode

public InitializeSQLiteDatabase ( SQLiteConnection sqliteConnection, List PragmaCommands ) : void
sqliteConnection System.Data.SQLite.SQLiteConnection
PragmaCommands List
Résultat void

InitializeSqlServerConnection() public méthode

public InitializeSqlServerConnection ( string sqlServerConnectionString ) : SqlConnection
sqlServerConnectionString string
Résultat System.Data.SqlClient.SqlConnection

InitializeSqlServerDatabase() public méthode

public InitializeSqlServerDatabase ( SqlConnection sqlConnection ) : void
sqlConnection System.Data.SqlClient.SqlConnection
Résultat void

ParseBlobAsGuid() protected static méthode

protected static ParseBlobAsGuid ( byte blob ) : System.Guid
blob byte
Résultat System.Guid

ParseStringAsGuid() protected static méthode

protected static ParseStringAsGuid ( string str ) : System.Guid
str string
Résultat System.Guid

ReadSourceSchema() protected abstract méthode

Reads the entire SQL Server DB schema using the specified connection string.
protected abstract ReadSourceSchema ( SqlConnection sqlConnection, SqlConversionHandler sqlConversionHandler, SqlTableSelectionHandler sqlTableSelectionHandler ) : DatabaseSchema
sqlConnection System.Data.SqlClient.SqlConnection The SQL connection.
sqlConversionHandler SqlConversionHandler The SQL conversion handler.
sqlTableSelectionHandler SqlTableSelectionHandler The SQL table selection handler.
Résultat DatabaseSchema

ValidateDataType() protected static méthode

Small validation method to make sure we don't miss anything without getting an exception.
protected static ValidateDataType ( string dataType ) : void
dataType string The datatype to validate.
Résultat void

WriteTriggerSchema() protected static méthode

Gets a create script for the triggerSchema in SQLite syntax
protected static WriteTriggerSchema ( TriggerSchema ts ) : string
ts TriggerSchema Trigger to script
Résultat string

Property Details

_cancelled protected_oe static_oe property

protected static bool _cancelled
Résultat bool

_defaultValueRx protected_oe static_oe property

protected static Regex,System.Text.RegularExpressions _defaultValueRx
Résultat System.Text.RegularExpressions.Regex

_isActive protected_oe static_oe property

protected static bool _isActive
Résultat bool

_keyRx protected_oe static_oe property

protected static Regex,System.Text.RegularExpressions _keyRx
Résultat System.Text.RegularExpressions.Regex