Skip to content

Commit d433917

Browse files
committed
Added support for ms sql instances
In Ms Sql Server, instances are handled, for eample whe using sqlexpres or when using replication. Here I am adding support so the scripts output the instance property and they can run witout manually editing the outputed files.
1 parent 7392a7a commit d433917

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

sqlserver2pgsql.pl

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
my $objects;
2929

3030
# These are global variables, from configuration file or command line arguments
31-
our ($sd, $sh, $sp, $su, $sw, $pd, $ph, $pp, $pu, $pw); # Connection args
31+
our ($sd, $sh, $si, $sp, $su, $sw, $pd, $ph, $pp, $pu, $pw); # Connection args
3232
our $conf_file;
3333
our $filename; # Filename passed as arg
3434
our $case_insensitive; # Passed as arg: was SQL Server installation case insensitive ? PostgreSQL can't ignore accents anyway
@@ -59,7 +59,7 @@
5959
my @view_list; # array to keep view ordering from sql server's dump (a view may depend on another view)
6060

6161
# Opens the configuration file
62-
# Sets $sd $sh $sp $su $sw $pd $ph $pp $pu $pw when they are not set in the command line already
62+
# Sets $sd $sh $si $sp $su $sw $pd $ph $pp $pu $pw when they are not set in the command line already
6363
# Also gets kettle parameters...
6464
sub parse_conf_file
6565
{
@@ -68,6 +68,7 @@ sub parse_conf_file
6868
# This is also used as the list of accepted parameters in the configuration file
6969
my %parameters = ('sql server database' => 'sd',
7070
'sql server host' => 'sh',
71+
'sql server host instance' => 'si',
7172
'sql server port' => 'sp',
7273
'sql server username' => 'su',
7374
'sql server password' => 'sw',
@@ -174,7 +175,7 @@ sub add_cast
174175
'smalldatetime' => 'timestamp',
175176
'time' => 'time',
176177
'timestamp' => 'timestamp',
177-
'datetimeoffset' => 'timestamp with time zone',
178+
'datetimeoffset' => 'timestamp with time zone',
178179
'image' => 'bytea',
179180
'binary' => 'bytea',
180181
'varbinary' => 'bytea',
@@ -617,11 +618,17 @@ sub generate_kettle
617618
my $pgtable=format_identifier($table);
618619
my $pgschema=format_identifier($targetschema);
619620

621+
my $sqlinstancename = '';
622+
if (length $si) {
623+
$sqlinstancename = $si;
624+
}
625+
620626
# Substitute every connection placeholder with the real value. We do this for both templates
621627
$newtemplate =~ s/__sqlserver_database__/$sd/g;
622628
$newtemplate =~ s/__sqlserver_database__/$sd/g;
623629
$newtemplate =~ s/__sqlserver_host__/$sh/g;
624630
$newtemplate =~ s/__sqlserver_port__/$sp/g;
631+
$newtemplate =~ s/__sqlserver_instance__/$sqlinstancename/g;
625632
$newtemplate =~ s/__sqlserver_username__/$su/g;
626633
$newtemplate =~ s/__sqlserver_password__/$sw/g;
627634
$newtemplate =~ s/__postgres_database__/$pd/g;
@@ -643,6 +650,7 @@ sub generate_kettle
643650
$newincrementaltemplate =~ s/__sqlserver_username__/$su/g;
644651
$newincrementaltemplate =~ s/__sqlserver_password__/$sw/g;
645652
$newincrementaltemplate =~ s/__postgres_database__/$pd/g;
653+
$newincrementaltemplate =~ s/__sqlserver_instance__/$sqlinstancename/g;
646654
$newincrementaltemplate =~ s/__postgres_host__/$ph/g;
647655
$newincrementaltemplate =~ s/__postgres_port__/$pp/g;
648656
$newincrementaltemplate =~ s/__postgres_username__/$pu/g;
@@ -2314,6 +2322,7 @@ sub resolve_name_conflicts
23142322
"conf=s" => \$conf_file,
23152323
"sd=s" => \$sd,
23162324
"sh=s" => \$sh,
2325+
"si=s" => \$si,
23172326
"sp=s" => \$sp,
23182327
"su=s" => \$su,
23192328
"sw=s" => \$sw,
@@ -2494,6 +2503,7 @@ BEGIN
24942503
<data_tablespace/>
24952504
<index_tablespace/>
24962505
<attributes>
2506+
<attribute><code>EXTRA_OPTION_MSSQL.instance</code><attribute>__sqlserver_instance__</attribute></attribute>
24972507
<attribute><code>FORCE_IDENTIFIERS_TO_LOWERCASE</code><attribute>N</attribute></attribute>
24982508
<attribute><code>FORCE_IDENTIFIERS_TO_UPPERCASE</code><attribute>N</attribute></attribute>
24992509
<attribute><code>IS_CLUSTERED</code><attribute>N</attribute></attribute>
@@ -2769,6 +2779,7 @@ BEGIN
27692779
<data_tablespace/>
27702780
<index_tablespace/>
27712781
<attributes>
2782+
<attribute><code>EXTRA_OPTION_MSSQL.instance</code><attribute>__sqlserver_instance__</attribute></attribute>
27722783
<attribute><code>FORCE_IDENTIFIERS_TO_LOWERCASE</code><attribute>N</attribute></attribute>
27732784
<attribute><code>FORCE_IDENTIFIERS_TO_UPPERCASE</code><attribute>N</attribute></attribute>
27742785
<attribute><code>IS_CLUSTERED</code><attribute>N</attribute></attribute>
@@ -3244,6 +3255,7 @@ BEGIN
32443255
<data_tablespace/>
32453256
<index_tablespace/>
32463257
<attributes>
3258+
<attribute><code>EXTRA_OPTION_MSSQL.instance</code><attribute>__sqlserver_instance__</attribute></attribute>
32473259
<attribute><code>FORCE_IDENTIFIERS_TO_LOWERCASE</code><attribute>N</attribute></attribute>
32483260
<attribute><code>FORCE_IDENTIFIERS_TO_UPPERCASE</code><attribute>N</attribute></attribute>
32493261
<attribute><code>IS_CLUSTERED</code><attribute>N</attribute></attribute>
@@ -3670,6 +3682,7 @@ BEGIN
36703682
<data_tablespace/>
36713683
<index_tablespace/>
36723684
<attributes>
3685+
<attribute><code>EXTRA_OPTION_MSSQL.instance</code><attribute>__sqlserver_instance__</attribute></attribute>
36733686
<attribute><code>FORCE_IDENTIFIERS_TO_LOWERCASE</code><attribute>N</attribute></attribute>
36743687
<attribute><code>FORCE_IDENTIFIERS_TO_UPPERCASE</code><attribute>N</attribute></attribute>
36753688
<attribute><code>IS_CLUSTERED</code><attribute>N</attribute></attribute>

0 commit comments

Comments
 (0)