@@ -244,33 +244,39 @@ class SASRunner{
244244 Write-Host "${ LineCodes . ResultsFetchedCode } "
245245 }
246246
247- [void]GetDatasetRecords([string]$tableName , [int]$start = 0, [int]$limit = 100, [string]$sortCriteria = "") {
247+ [void]GetDatasetRecords([string]$library, [string]$table , [int]$start = 0, [int]$limit = 100, [string]$sortCriteria = "") {
248248 $objRecordSet = New-Object -comobject ADODB.Recordset
249249 $objRecordSet.ActiveConnection = $this.dataConnection # This is needed to set the properties for sas formats.
250250 $objRecordSet.Properties.Item("SAS Formats").Value = "_ALL_"
251251
252- $query = "SELECT * FROM $tableName"
252+ $tableName = $library + "." + $table
253253 if ($sortCriteria -ne "") {
254- $query = $query + " ORDER BY " + $sortCriteria
254+ $epoch = [datetime]::FromFileTimeUtc(0)
255+ $currentUtcTime = (Get-Date).ToUniversalTime()
256+ $ts = [int64]($currentUtcTime - $epoch).TotalSeconds
257+ $tableName = "WORK.temp_$ts"
258+ $this.dataConnection.Execute("CREATE VIEW $tableName AS SELECT * FROM $library.$table ORDER BY $sortCriteria")
255259 }
260+
256261 $objRecordSet.Open(
257- $query ,
258- $this.dataConnection , # Use the active connection
259- 3 , # adOpenStatic
262+ $tableName ,
263+ [System.Reflection.Missing]::Value , # Use the active connection
264+ 2 , # adOpenDynamic
260265 1, # adLockReadOnly
261- 1 # adCmdText
266+ 512 # adCmdTableDirect
262267 )
263268
264269 $records = [List[List[object]]]::new()
265270 $fields = $objRecordSet.Fields.Count
266271
272+ $rsi = [List[List[object]]]::new()
273+
267274 if ($objRecordSet.EOF) {
268275 Write-Host '{"rows": [], "count": 0}'
269276 return
270277 }
271278
272279 $objRecordSet.AbsolutePosition = $start + 1
273-
274280 for ($j = 0; $j -lt $limit -and $objRecordSet.EOF -eq $False; $j++) {
275281 $cell = [List[object]]::new()
276282 for ($i = 0; $i -lt $fields; $i++) {
@@ -292,10 +298,14 @@ class SASRunner{
292298 $result | Add-Member -MemberType NoteProperty -Name "rows" -Value $records
293299 $result | Add-Member -MemberType NoteProperty -Name "count" -Value $count
294300
301+ if ($sortCriteria -ne "") {
302+ $this.dataConnection.Execute("DROP VIEW $tableName")
303+ }
304+
295305 Write-Host $(ConvertTo-Json -Depth 10 -InputObject $result -Compress)
296306 }
297307
298- [void]GetColumns ([string]$libname, [string]$memname) {
308+ [object[]] GetColumnData ([string]$libname, [string]$memname) {
299309 $objRecordSet = New-Object -comobject ADODB.Recordset
300310 $objRecordSet.ActiveConnection = $this.dataConnection
301311 $query = @"
@@ -330,6 +340,12 @@ class SASRunner{
330340 $parsedRows += $parsedRow
331341 }
332342
343+ return $parsedRows
344+ }
345+
346+ [void]GetColumns([string]$libname, [string]$memname) {
347+ $parsedRows = $this.GetColumnData($libname, $memname)
348+
333349 Write-Host $(ConvertTo-Json -Depth 10 -InputObject $parsedRows -Compress)
334350 }
335351
0 commit comments