GithubHelp home page GithubHelp logo

jmneto / saphana2sql Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 15 KB

This tool uses a set of rules defined in the "rules file" to perform text replacements to translate database scripts to SQL Server syntax. It allows for simple regular text replacements and complex parameter transposition.

License: MIT License

C# 100.00%

saphana2sql's Introduction

SAPHANA2SQL

Tool to assist with the process of converting SAP HANA database scripts to Microsoft SQL Server syntax scripts

This tool uses a set of rules defined in the "rules file" to perform text replacements to translate database scripts to SQL Server syntax. It allows for simple regular text replacements and complex parameter transposition if required.

The "rules file" contains the rules, one rule per line, the text to be replaced on the left of the separator char '#', and the new replacement text is on the right of the separator char '#'.

Although the rules in this example apply to SAP HANA to SQL Server syntax translation, these rules can be modified to make any required syntax translation independent of the source or target database server.

Regular text replacement rule:

text to replace#new text

Text replacement plus parameter transposition:

To transpose parameters, use the syntax {0}. In the example below, {0} and {1} are the parameters to be transposed from the original text to the new replacement text.

In this example if the original script file contains: Text to Replace "parameter1" "parameter2", it wwill be translated to: new text "parameter2" "parameter1".

Text to replace "{0}" "{1}"#new text "{1}" "{0}"

Extensibility

You can add your own rules as required for your scenario.

Sample rules file

UNLOAD PRIORITY 5  AUTO MERGE#
;#
CS_FIXED#
CS_INT#
COLUMN#
CS_FLOAT#
CS_DAYDATE#
CS_SECONDTIME#
CS_DOUBLE#
CS_LONGDATE#
DOUBLE#FLOAT
LONGDATE#DATETIME2(7)
BLOB MEMORY THRESHOLD 1000#varbinary(max)
CURRENTDATE#GetDate()
NVARCHAR(5000)#NVARCHAR(MAX)
ROW#
CS_STRING#
NCLOB MEMORY THRESHOLD 1000#varbinary(max)
STRING#
%COMMENT ON TABLE "{0}"."{1}" is '{2}'#EXEC sys.sp_addextendedproperty @name=N'{1}',@value=N'{2}',@level0type=N'SCHEMA',@level0name=N'{0}',@level1type=N'TABLE',@level1name=N'{1}'
%COMMENT ON  "{0}"."{1}"."{2}" is '{3}'#EXEC sys.sp_addextendedproperty @name=N'{2}',@value=N'{3}',@level0type=N'SCHEMA',@level0name=N'{0}',@level1type=N'TABLE',@level1name=N'{1}',@level2type=N'COLUMN',@level2name=N'{2}'

The sample rules file above would convert a script like below from SAP HANA syntax to a SQL Server compatible syntax:

Original SAP HANA script file:

CREATE COLUMN TABLE "MYSCHEMA"."MYTABLE" ("CLIENT" NVARCHAR(3) DEFAULT '000' NOT NULL , "JOB" NVARCHAR(4) DEFAULT '' NOT NULL , PRIMARY KEY ("CLIENT", "JOB")) UNLOAD PRIORITY 5  AUTO MERGE ;
COMMENT ON TABLE "MYSCHEMA"."MYTABLE" is 'Occupations';
COMMENT ON COLUMN "MYSCHEMA"."MYTABLE"."CLIENT" is 'Client';
COMMENT ON COLUMN "MYSCHEMA"."MYTABLE"."JOB" is 'Occupation/group'

Converted to SQL Server Script File:

CREATE  TABLE "MYSCHEMA"."MYTABLE" ("CLIENT" NVARCHAR(3) DEFAULT '000' NOT NULL , "JOB" NVARCHAR(4) DEFAULT '' NOT NULL , PRIMARY KEY ("CLIENT", "JOB"))  
GO
EXEC sys.sp_addextendedproperty @name=N'MYTABLE',@value=N'Occupations',@level0type=N'SCHEMA',@level0name=N'MYSCHEMA',@level1type=N'TABLE',@level1name=N'MYTABLE'
GO
EXEC sys.sp_addextendedproperty @name=N'CLIENT',@value=N'Client',@level0type=N'SCHEMA',@level0name=N'MYSCHEMA',@level1type=N'TABLE',@level1name=N'MYTABLE',@level2type=N'COLUMN',@level2name=N'CLIENT'
GO
EXEC sys.sp_addextendedproperty @name=N'JOB',@value=N'Occupation/group',@level0type=N'SCHEMA',@level0name=N'MYSCHEMA',@level1type=N'TABLE',@level1name=N'MYTABLE',@level2type=N'COLUMN',@level2name=N'JOB'
GO

Usage

SAPHANA2SQL -sourcefolder .\SAPHANA2SQL\Data --rules .\SAPHANA2SQL\Data\rules --outputfile .\SAPHANA2SQL\Data\output.txt

 --sourcefolder    Required. Path to root of folder with script files to translate
 --rules           Required. Path to text replacement-rules csv file
 --outputfile      Required. Path to output file
 --help            Display this help screen.

Example

SAPHANA2SQL
Source Folder .\SAPHANA2SQL\Data
Rules File .SAPHANA2SQL\Data\rules
Output File .\SAPHANA2SQL\Data\output.txt

Processing Files
.................................................................................................

Writing output to .\SAPHANA2SQL\Data\output.txt

Done.

OS Support

Windows and Linux

saphana2sql's People

Contributors

jmneto avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.