SQL Conversion |

Providing SQLs for Conversion Converting/Migrating SQLs Connecting to databases Fetching MetaData Datatype mapping
### Providing SQLs for Conversion The SQL statements to be converted can be provided to the tool in two ways: You can directly type the SQL statements in "Type SQL" text area. Multiple SQLs must be semicolon separated (Or) You can load the SQLs from a file Type in the list of SQL statements to be converted into a file. Each SQL should be separated by a semicolon. One SQL can be given in multiple lines too. Invoke the Open SQL menu under the File menu (or) select Open tool bar icon. A File dialog will come up from which you can choose your file. All the SQL from the file will be loaded in "Type SQL" text area. ### Converting/Migrating SQLs Select the corresponding SQL statement that has to be converted and choose any one of the following ways: Invoke Convert menu and choose the appropriate database menu item (Or) Invoke Convert tool bar icon (This will convert the SQL to the default target database selected) (Or) Right click on Type SQL text area and select Convert menu and choose the appropriate database menu item The query will automatically be converted to the chosen database syntax and the converted SQLs will be displayed on the Converted SQL text area. You can also press F5 functional key as a short cut for conversion. For converting multiple SQL statements in one shot, select all the statements and use the same option described above. ### Connecting to databases : Console uses JDBC drivers to connect the various supported databases. The JDBC drivers for the databases Oracle, SQL Server, Sybase and MySQL are bundled with the product. For the other databases the user has to load the JDBC drivers provided by the database vendor. To connect to the databases access the "Database connection settings" dialog shown below from the menu "Settings -> Database connections" . The "Database connection settings" lists all the existing connections under the "List of database connections". The connection details for a particular connection name are listed under "Connection details" . It also has the following options to manage the database connections : To create a new connection click on the Add button, this will open the "Add database settings" dialog. Follow the below steps to create a new connection : Provide a connection name through which this database connection can be identified. Select the database from the "Database type" combo box. Provide the host name, port number, database name, user name and password to connect to the database. Click on the "Test" button to test connecting to the database. Once the above details are provided click on the "Save" button to save the settings. The saved settings will be stored in the "List of database connections" in the "Database connection settings" dialog. To edit an existing connection and to modify its connections details click on the "Edit" button. This will open the "Edit database settings" dialog. The "Edit database settings" dialog lists all the connection details for the connection name which is being edited. You can edit the given settings and save the changes to the connection name. All further databse connections using this connection name will refer to the modified "Connection settings". To delete the existing connection name click on the "Delete" button in the "Database connection settings" dialog. This will remove the connection name and its associated "Connection settings" from the "List of database connections". When connecting to a database for which the JDBC driver is not bundled, the JDBC driver has to be loaded to the Console. This can be done by clicking on the "Browse" button provided against the "JDBC Driver libraries" as shown in the below image. ### Fetching MetaData To ensure accuracy of conversion of SQL statements from one database dialect to another, it is strongly recommended to fetch the metadata information from the source database before proceeding with the conversion. Here source database refers to the database whose tables are used in the queries which are to be migrated. Metadata is the information about the table (or schema) present in the source database on which SQLs would have been written. Follow the below given steps to Fetch Metadata of a source database. Click on "Fetch Metadata" tool bar icon to invoke "Fetch Metadata" dialog Select an existing connection or create a new connection name using the "Add connection" button. Provide the user name and the password to connect to the database. Click on the "Filter" button to invoke "Metadata Filter criteria" dialog. If settings are not specified the default value "*" will be used to fetch the metadata. The default value fetches metadata of all the tables across all the schema (databases). The "Metadata Filter criteria" dialog consists of the following parameters. Catalog Name: This parameter option must match the catalog name from which the meta data is to be retrieved. The default option is given as "*" which means catalog name is not used to narrow the search for the metadata information. Schema Name: This parameter option must match the schema name from which the metadata is to be retrieved. The default option is given as "*" which means schema name is not used to narrow the search for the metadata information. Table Name Pattern: This parameter refers to the pattern to which the table names should match, whose metadata information are to be retrieved. For example, If the table name paattern is given as EMP%, then meta-data information is retrieved only for the tables whose names start with the pattern EMP. Column Name Pattern: This parameter refers to the pattern to which the column names should match, whose metadata information are to be retrieved, exist. For example If Column Name Pattern is given as NAME%, then meta-data information is retrieved only for those columns whose names start with the pattern NAME. After providing the above parameters click "OK" button. This will close the "Metadata Filter criteria" dialog and take you back to the "Fetch Metadata" dialog. Now click on the "Fetch" button to fetch the metadata. ### An Example to illustrate the use of metadata: Let us assume our source database is oracle where we have a table "members" with following columns.
COLUMN NAME | DATATYPE | NULL?
NAME | VARCHAR2(20) | NOT NULL
ID | NUMBER(4) | NOT NULL
BIRTHDATE | DATE | NOT NULL
ADDRESS | VARCHAR2(20) | NOT NULL
Now , We want to convert the following query. SELECT BIRTHDATE + 2 FROM MEMBERS .When we convert the above query without fetching the metadata related to this table.The details regarding the datatype of the BIRTHDATE column will not be available. Without having the datatype of the column, BIRTHDATE will be treated as a number and the conversion will be as follows: Converted query in DB2 with out Metadata: SELECT; BIRTHDATE + 2 FROM MEMBERS This is an incorrect way of converting the query. Now, Let us look at the conversion for the same query after the required metadata has been fetched from the source database source oracle database. Converted query in DB2 with Metatadata: SELECT BIRTHDATE + ( 2 ) DAYS FROM MEMBERS In DB2 , adding a value to a date datatype is done in a different manner. Without knowing the column datatype in the source database, Console cannot guarantee the accurate conversion of SQL Queries. In order to avoid such errors and to perform more accurate conversions it is recommended to fetch the metadata from the source database whose SQL queries are to be migrated. ### Datatype mapping To configure the desired data type mapping to be used for conversion of SQLs from one database to another overriding the default data type mapping provided by the SwisSQL Console. SwisSQL Console provides two types of data type mapping configuration: Global datatype mapping: In global datatype mapping the source data type will be overriden by the corresponding target data type across all the tables in all the subsequent conversions. Mapping at the Table column level, can be used to specify the target datatype for a particular table column. During conversion when the specified column name is encountered (with that specifed table), then the original data type is overriden by the corresponding target datatype specified by the user. How to implement the datatype mapping: A configuration file DatatypeMapping.conf is provided in the "SwisSQL/Console5.5/conf" directory. Edit this file and specify the datatype mapping entries as follows : Global datatype mapping: The global datatype mapping can be given as follows, source_datatype = target_datatype. See the below example entries : BLOB = BLOB(100M) CLOB = CLOB(2G) Table specific datatype mapping: The table specific datatype mapping can be given as follows, table_name.column_name = target_datatype. See the below example entries : TABLE1.COLUMN1 = BLOB(2G) TABLE1.COLUMN2 = BLOB(1G) TABLE2.COLUMN2 = CLOB

© 2011 ZOHO Corporation