-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.ps1
More file actions
82 lines (76 loc) · 2.18 KB
/
Copy pathdatabase.ps1
File metadata and controls
82 lines (76 loc) · 2.18 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
$global:con = New-Object System.Data.OracleClient.OracleConnection($connection_string)
function Push-Database {
param([string]$Query)
try {
$cmd = $con.CreateCommand()
$cmd.CommandText = $Query
return $cmd.ExecuteNonQuery()
}
catch {
Write-Error ("Execution Error : `n{1}" -f $_.Exception.ToString())
}
finally {
}
}
function Push-Database-SqlPlus {
param(
[string]
[parameter(Mandatory = $true)]
$Username,
[SecureString]
[parameter(Mandatory = $true, ParameterSetName = "Password")]
$Password,
[string]
$Tns,
[string]
[parameter(Mandatory = $true)]
$Script,
[string]
[parameter(Mandatory = $true)]
$Outputfile
)
try {
sqlplus $Username/$Password@$Tns "$Script" | Out-File $Outputfile
}
catch {
Write-Error ("Execution Error -sqlplus : `n{1}" -f $_.Exception.ToString())
}
}
function Import-Objects {
param(
[parameter(Mandatory = $true, ParameterSetName = "Path")]
[string]
$Path,
[bool]
[parameter(Mandatory = $true, ParameterSetName = "WithSqlPlus")]
$WithSqlPlus
)
$scripts = Get-ChildItem -Path $Path
try {
if ($WithSqlPlus) {
foreach ($script in $scripts) {
$outputfile = "$outputfile/$script"
Push-Database-SqlPlus -Username $username -Password $password -Tns $data_source -Script $script -Outputfile $outputfile
Write-Output "$script > executed $res"
}
}
else {
$con.Open()
foreach ($script in $scripts) {
$content = Get-Content -Path "$Path/$script"
$content = $content -replace "/", ""
$res = Push-Database -query $content
Write-Output "$script > executed $res"
}
if ($con.State -eq 'Open') {
$con.close()
}
}
}
catch {
Write-Error ("Execution Exception: `n{1}" -f $_.Exception.ToString())
}
finally {
#TODO : logs
}
}