-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet_Firebird_Schema.ps1
More file actions
145 lines (121 loc) · 4.42 KB
/
Get_Firebird_Schema.ps1
File metadata and controls
145 lines (121 loc) · 4.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<#
.SYNOPSIS
Analysiert die Datentypen einer Firebird-Tabelle im Detail.
.DESCRIPTION
Verbindet sich mit einer angegebenen Firebird-Datenbankdatei und gibt für eine
spezifische Tabelle die exakten .NET Datentypen zurück, wie sie der Treiber sieht.
Dies ist hilfreich zum Debuggen von Mapping-Problemen.
.PARAMETER TableName
Der Name der zu analysierenden Tabelle (z.B. BARTIKEL).
.EXAMPLE
.\Get_Firebird_Schema.ps1 -TableName "BAUF"
.LINK
https://github.com/gitnol/PSFirebirdToMSSQL
#>
#Requires -Version 7.0
param(
[Parameter(Mandatory = $true)]
[string]$TableName
)
# -----------------------------------------------------------------------------
# 0. MODUL IMPORTIEREN
# -----------------------------------------------------------------------------
$ModulePath = Join-Path $PSScriptRoot "SQLSyncCommon.psm1"
if (-not (Test-Path $ModulePath)) {
Write-Error "KRITISCH: SQLSyncCommon.psm1 nicht gefunden in $PSScriptRoot"
exit 1
}
Import-Module $ModulePath -Force
# -----------------------------------------------------------------------------
# 1. KONFIGURATION LADEN
# -----------------------------------------------------------------------------
$ScriptDir = $PSScriptRoot
$ConfigPath = Join-Path $ScriptDir "config.json"
if (-not (Test-Path $ConfigPath)) {
Write-Error "config.json fehlt!"
exit 1
}
try {
$Config = Get-SQLSyncConfig -ConfigPath $ConfigPath
}
catch {
Write-Error "Fehler beim Laden der Konfiguration: $($_.Exception.Message)"
exit 2
}
# -----------------------------------------------------------------------------
# 2. CREDENTIALS AUFLÖSEN
# -----------------------------------------------------------------------------
try {
$FbCreds = Resolve-FirebirdCredentials -Config $Config.RawConfig
}
catch {
Write-Error $_.Exception.Message
exit 5
}
# -----------------------------------------------------------------------------
# 3. TREIBER LADEN
# -----------------------------------------------------------------------------
try {
$ResolvedDllPath = Initialize-FirebirdDriver -DllPath $Config.DllPath -ScriptDir $ScriptDir
}
catch {
Write-Error $_.Exception.Message
exit 3
}
# -----------------------------------------------------------------------------
# 4. ANALYSE STARTEN
# -----------------------------------------------------------------------------
$ConnectionString = New-FirebirdConnectionString `
-Server $Config.FBServer `
-Database $Config.FBDatabase `
-Username $FbCreds.Username `
-Password $FbCreds.Password `
-Port $Config.FBPort `
-Charset $Config.FBCharset
Write-Host "Verbinde zu: $($Config.FBServer) : $($Config.FBDatabase)" -ForegroundColor Cyan
Write-Host "Analysiere Tabelle: $TableName" -ForegroundColor Yellow
$FbConn = $null
try {
$FbConn = New-Object FirebirdSql.Data.FirebirdClient.FbConnection($ConnectionString)
$FbConn.Open()
$FbCmdSchema = $FbConn.CreateCommand()
$FbCmdSchema.CommandText = "SELECT FIRST 1 * FROM ""$TableName"""
# ExecuteReader mit SchemaOnly lädt KEINE Daten, nur Metadaten (sehr schnell)
$ReaderSchema = $FbCmdSchema.ExecuteReader([System.Data.CommandBehavior]::SchemaOnly)
$SchemaTable = $ReaderSchema.GetSchemaTable()
$ReaderSchema.Close()
# -------------------------------------------------------------------------
# AUSGABE AUFBEREITEN
# -------------------------------------------------------------------------
$Result = @()
foreach ($Row in $SchemaTable) {
$ColName = $Row.ColumnName
$DotNetType = $Row.DataType
$Size = $Row.ColumnSize
$AllowDBNull = $Row.AllowDBNull
# SQL Server Typ-Vorschlag
$ProposedSqlType = ConvertTo-SqlServerType -DotNetTypeName $DotNetType.Name -Size $Size
$Result += [PSCustomObject]@{
Column = $ColName
".NET Type" = $DotNetType.Name
"Full Type" = $DotNetType.FullName
"Size" = $Size
"Nullable" = $AllowDBNull
"Vorschlag SQL" = $ProposedSqlType
}
}
# Ausgabe als formatierte Tabelle
$Result | Format-Table -AutoSize
Write-Host "Analyse abgeschlossen." -ForegroundColor Green
}
catch {
Write-Error "Fehler bei der Analyse: $($_.Exception.Message)"
exit 4
}
finally {
# WICHTIG: Connection immer aufräumen
if ($FbConn) {
try { $FbConn.Close() } catch { }
try { $FbConn.Dispose() } catch { }
}
}