Permalink
Browse files

fixes for initializing tables to netezza

  • Loading branch information...
1 parent d1dfd87 commit 3680ee30d79cdfa5f26448f01ac383206cdfd43a @ssandler ssandler committed Feb 15, 2013
Showing with 14 additions and 7 deletions.
  1. +8 −4 scripts/AddTable-ToCT.ps1
  2. +6 −3 scripts/Initialize-DB.ps1
View
@@ -204,6 +204,9 @@ if ($slavetype -eq "Netezza") {
$typename = $column.DataType.Name
$moddatatype = [TeslaSQL.DataType]::MapDataType("MSSQL", "Netezza", $typename)
if ($typename -ne $moddatatype) {
+ if ($modifiertable.ContainsKey($column.Name) -and [RegEx]::IsMatch($moddatatype, ".*\(\d+\)$")) {
+ $moddatatype = [RegEx]::Replace($moddatatype, "\d+", $modifiertable[$column.Name].ToString());
+ }
$col = (Map-ReservedWordNetezza $column.Name) + " " + $moddatatype
if ($column.Nullable) {
$col += " NULL"
@@ -220,15 +223,15 @@ if ($slavetype -eq "Netezza") {
$typename += "(" + $modifiertable[$column.Name].ToString() + ")"
} else {
$typename += "("
- if (($col.DataType.MaximumLength -gt $netezzastringlength) -or ($col.DataType.MaximumLength -lt 1)) {
+ if (($column.DataType.MaximumLength -gt $netezzastringlength) -or ($column.DataType.MaximumLength -lt 1)) {
$typename += $netezzastringlength.ToString()
} else {
- $typename += $col.DataType.MaximumLength.ToString()
+ $typename += $column.DataType.MaximumLength.ToString()
}
$typename += ")"
}
} elseif ($shortenednumerictypes -Contains($column.DataType.SqlDataType)) {
- $typename += "(" + $col.DataType.NumericPrecision.ToString() + "," + $col.DataType.NumericScale.ToString() + ")"
+ $typename += "(" + $column.DataType.NumericPrecision.ToString() + "," + $column.DataType.NumericScale.ToString() + ")"
}
$col = (Map-ReservedWordNetezza $column.Name) + " " + $typename
if ($column.Nullable) {
@@ -426,7 +429,8 @@ if ($slavetype -eq "MSSQL") {
invoke-sqlcmd2 -serverinstance $master -database ("CT_" + $masterdb) -query $query
$query = [string]::Format("CREATE VIEW [CTVWINIT_{0}]
AS {1}", $table, $bcpselect)
- $bcpselect = "SELECT * FROM [CTVWINIT_" + $table + "]"
+ invoke-sqlcmd2 -serverinstance $master -database ("CT_" + $masterdb) -query $query
+ $bcpselect = "SELECT * FROM " + ("CT_" + $masterdb) + "..[CTVWINIT_" + $table + "]"
}
bcp.exe "$bcpselect" queryout $bcppath -c -S $master -T -t "|" -r\n
if (!$?) {
@@ -293,6 +293,9 @@ Function Get-Modifiers([System.Xml.XmlNodeList]$modifiers) {
}
$columnmodifiers += [string]$modifier.OuterXML
}
+ if ($columnmodifiers -ne $null) {
+ $columnmodifiers += "</root>"
+ }
return $columnmodifiers
}
@@ -630,8 +633,8 @@ foreach ($tableconf in $tables.SelectNodes("table")) {
"password" = $slavepassword;
"slavecolumnlist" = $slavecolumnlist;
"mastercolumnlist" = $mastercolumnlist;
- "slavecolumnmodifiers" = $slavecolumnmodifiers;
- "mastercolumnmodifiers" = $mastercolumnmodifiers;
+ "slavecolumnmodifiers" = $slavemodifiers;
+ "mastercolumnmodifiers" = $mastermodifiers;
"netezzastringlength" = $netezzastringlength;
"mappingsfile" = $mappingsfile;
"sshuser" = $netezzauser;
@@ -649,7 +652,7 @@ foreach ($tableconf in $tables.SelectNodes("table")) {
#initialize tables in parallel with a configurable throttle
$tablestoinitialize | Foreach-Object {
- Write-Host ("Calling .\AddTable-ToCT for table " + $_.table)
+ Write-Host ("Calling .\AddTable-ToCT for table " + $_.table)
#switch to directory containing the script. required because this is inside a runspace which
#doesn't inherit the environment of the parent scope.
cd $_.directory

0 comments on commit 3680ee3

Please sign in to comment.