C# Class DbAccess.SqlServerToSQLite

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.
Mostra file Open project: elerch/Convert-SQL-Server-to-SQLite

Public Methods

Method Description
CancelConversion ( ) : void

Cancels the conversion.

ConvertSqlServerToSQLiteDatabase ( string sqlServerConnString, string sqlitePath, string password, SqlConversionHandler handler, SqlTableSelectionHandler selectionHandler, FailedViewDefinitionHandler viewFailureHandler, 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.

WriteTriggerSchema ( TriggerSchema ts ) : string

Gets a create script for the triggerSchema in sqlite syntax

Private Methods

Method Description
AddSQLiteTable ( SQLiteConnection conn, DbAccess.TableSchema dt ) : void

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

AddSQLiteView ( SQLiteConnection conn, DbAccess.ViewSchema vs, FailedViewDefinitionHandler handler ) : void
AddTableTriggers ( SQLiteConnection conn, DbAccess.TableSchema dt ) : void
AddTriggersForForeignKeys ( string sqlitePath, IEnumerable schema, string password, SqlConversionHandler handler ) : void
AdjustDefaultValue ( string val ) : string

More adjustments for the DEFAULT value clause.

BuildColumnStatement ( DbAccess.ColumnSchema col, DbAccess.TableSchema ts, bool &pkey ) : string

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

BuildCreateIndex ( string tableName, DbAccess.IndexSchema indexSchema ) : string

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

BuildCreateTableQuery ( DbAccess.TableSchema ts ) : string

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

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.

BuildSqlServerTableQuery ( TableSchema ts ) : 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.

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.

ConvertSqlServerDatabaseToSQLiteFile ( string sqlConnString, string sqlitePath, string password, SqlConversionHandler handler, SqlTableSelectionHandler selectionHandler, FailedViewDefinitionHandler viewFailureHandler, 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.

CopySqlServerRowsToSQLiteDB ( string sqlConnString, string sqlitePath, List schema, string password, SqlConversionHandler handler ) : void

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

CreateForeignKeySchema ( SqlConnection conn, TableSchema ts ) : 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 ( string sqlitePath, DatabaseSchema schema, string password, SqlConversionHandler handler, FailedViewDefinitionHandler viewFailureHandler ) : void

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

CreateTableSchema ( SqlConnection conn, string tableName, string tschma ) : 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.

DiscardNational ( string value ) : string

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

FixDefaultValueString ( string colDefault ) : string

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

GetDbTypeOfColumn ( ColumnSchema cs ) : 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).

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

Check if the DEFAULT clause is valid by SQLite standards

ParseBlobAsGuid ( byte blob ) : Guid
ParseStringAsGuid ( string str ) : Guid
ReadSqlServerSchema ( string connString, SqlConversionHandler handler, SqlTableSelectionHandler selectionHandler ) : DatabaseSchema

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

StripParens ( string value ) : string

Strip any parentheses from the string.

ValidateDataType ( string dataType ) : void

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

Method Details

CancelConversion() public static method

Cancels the conversion.
public static CancelConversion ( ) : void
return void

ConvertSqlServerToSQLiteDatabase() public static method

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 static ConvertSqlServerToSQLiteDatabase ( string sqlServerConnString, string sqlitePath, string password, SqlConversionHandler handler, SqlTableSelectionHandler selectionHandler, FailedViewDefinitionHandler viewFailureHandler, bool createTriggers ) : void
sqlServerConnString string The connection string to the SQL Server database.
sqlitePath string The path to the SQLite database file that needs to get created.
password string The password to use or NULL if no password should be used to encrypt the DB
handler SqlConversionHandler A handler delegate for progress notifications.
selectionHandler SqlTableSelectionHandler The selection handler that allows the user to select which /// tables to convert
viewFailureHandler FailedViewDefinitionHandler
createTriggers bool
return void

WriteTriggerSchema() public static method

Gets a create script for the triggerSchema in sqlite syntax
public static WriteTriggerSchema ( TriggerSchema ts ) : string
ts TriggerSchema Trigger to script
return string