Skip to content

Commit e58ae3b

Browse files
committed
using proper query delimiter for each rdbms
1 parent 0f1a374 commit e58ae3b

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

functions/Invoke-DBOQuery.ps1

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,14 @@ function Invoke-DBOQuery {
217217
}
218218
$queryText = $fileObjects | Get-Content -Raw
219219
}
220+
$delimiter = switch ($Type) {
221+
SqlServer { 'GO' }
222+
PostgreSQL { 'semicolon (;)' }
223+
Oracle { 'semicolon (;)' }
224+
MySQL { 'semicolon (;)' }
225+
}
220226
if ($Interactive) {
221-
Write-PSFMessage -Level Host -Message "Running in interactive mode. Finish the query with a semicolon to execute it immediately. \q, exit, or quit to exit."
227+
Write-PSFMessage -Level Host -Message "Running in interactive mode. Finish the query with a $delimiter to execute it immediately. \q, exit, or quit to exit."
222228
}
223229

224230
#Replace tokens in the sql code if any
@@ -235,16 +241,19 @@ function Invoke-DBOQuery {
235241
$queryList = $inputLine = ''
236242
$interactiveQuery = @()
237243
# read until user finishes with a ;
238-
while (-not $inputLine -or $inputLine.substring($inputLine.Length - 1, 1) -ne ';') {
244+
while ($true) {
239245
$inputLine = Read-Host
240246
# exit on \q
241247
if ($inputLine -in '\q', 'exit', 'quit') {
242248
$dataConnection.Dispose()
243249
return
244250
}
245251
$interactiveQuery += $inputLine
252+
$fullQuery = ($interactiveQuery -join "`n").Trim()
253+
$queryList = $dbUpConnection.SplitScriptIntoCommands($fullQuery)
254+
if ($queryList[0] -and $queryList[0] -ne $fullQuery) { break }
246255
}
247-
$queryList = $interactiveQuery -join "`n"
256+
$queryList = $queryList[0]
248257
}
249258
$ds = [System.Data.DataSet]::new()
250259
$qCount = 0
@@ -254,6 +263,7 @@ function Invoke-DBOQuery {
254263
# split commands using DbUp parser
255264
foreach ($splitQuery in $dbUpConnection.SplitScriptIntoCommands($queryItem)) {
256265
try {
266+
Write-PSFMessage -Level Verbose -Message "Executing sub-query $splitQuery"
257267
# only Sql Server supports messaging right now
258268
if ($Type -eq 'SqlServer') {
259269
# Add message events

0 commit comments

Comments
 (0)