Skip to content

Commit

Permalink
Merge pull request #589 from intersystems/v1-lite-terminal-sql
Browse files Browse the repository at this point in the history
fix: move namespace filtering from SQL to ObjectScript for IRIS compat.
  • Loading branch information
isc-tleavitt authored Oct 24, 2024
2 parents 72fb28e + b62b2cd commit d3430fd
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 9 deletions.
15 changes: 15 additions & 0 deletions src/cls/IPM/DataType/RegExString.cls
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,19 @@ ClassMethod IsValid(%val As %CacheString) As %Status [ ServerOnly = 0 ]
return $$$OK
}

ClassMethod FromWildCard(wildcard As %String) As %String
{
Set regex = ""
For i=1:1:$Length(wildcard) {
Set char = $Extract(wildcard, i)
If char = "*" {
Set regex = regex_".*"
} Else {
Set regex = regex_char
}
}
// Is there a way to return an instance of this class instead of %String?
Quit "^(?i)"_regex_"$"
}

}
65 changes: 56 additions & 9 deletions src/cls/IPM/Main.cls
Original file line number Diff line number Diff line change
Expand Up @@ -889,20 +889,27 @@ ClassMethod Namespace(ByRef pCommandInfo) [ Internal ]
/// Get list Namespace, example do ##class(%IPM.Main).GetListNamespace(.ns)
ClassMethod GetListNamespace(Output list, pSearch As %String = "")
{
Kill list
Set list = 0

// Build regex for matching outside of SQL.
// Directly using `where Nsp LIKE ?` causes a bug described in https://github.com/intersystems/ipm/issues/579
Set pSearch = $Zstrip(pSearch, "<>WC")
If pSearch = "" {
Set pSearch = "*"
}
Set regex = ##class(%IPM.DataType.RegExString).FromWildCard(pSearch)

Set width = 0
Set tArgs = 0
Set tQuery = "SELECT Nsp FROM %SYS.Namespace_List()"
If pSearch'="" {
Set tQuery = tQuery _ " WHERE Nsp " _ $Select(pSearch["*": "LIKE", 1: "=") _ " ?"
Set tArgs($Increment(tArgs)) = $Translate($$$UPPER(pSearch), "*", "%")
}
Set tRes = ##class(%SQL.Statement).%ExecDirect(,tQuery, tArgs...)
Set tRes = ##class(%SQL.Statement).%ExecDirect(,tQuery)
$$$ThrowSQLIfError(tRes.%SQLCODE, tRes.%Message)
While tRes.%Next(.tSC) {
$$$ThrowOnError(tSC)
Set nsp = tRes.Nsp
Set list(nsp) = ""
If $Match(nsp, regex) {
Set list(nsp) = ""
}
}
}

Expand Down Expand Up @@ -2221,9 +2228,49 @@ ClassMethod RunDependencyAnalyzer(ByRef pCommandInfo)
Write !
}

Query ActiveNamespaces() As %SQLQuery(ROWSPEC = "ID:%String,Name:%String") [ SqlProc ]
/// Implemented as custom query instead of `select Nsp, Nsp from %SYS.Namespace_List(0,0) WHERE status = 1` because of a DP issue, see https://github.com/intersystems/ipm/issues/579
Query ActiveNamespaces() As %Query(ROWSPEC = "ID:%String,Name:%String") [ SqlProc ]
{
}

ClassMethod ActiveNamespacesExecute(qHandle As %Binary) As %Status
{
Try {
Set tQuery = "SELECT NSP, Status FROM %SYS.Namespace_List(0,0)"
Set rs = ##class(%SQL.Statement).%ExecDirect(, tQuery)
Kill qHandle
While rs.%Next() {
If rs.%Get("Status") {
Set qHandle($INCREMENT(qHandle)) = rs.%Get("NSP")
}
}
Set qHandle = 0
} catch ex {
Return ex.AsStatus()
}
Return $$$OK
}

ClassMethod ActiveNamespacesFetch(qHandle As %Binary, ByRef Row As %List, ByRef AtEnd As %Integer = 0) As %Status [ PlaceAfter = ActiveNamespacesExecute ]
{
Try {
If $Data(qHandle($Increment(qHandle)), nsp) # 2 {
Set Row = $ListBuild(nsp, nsp)
Set AtEnd = 0
} Else {
Set Row = ""
Set AtEnd = 1
}
} catch ex {
Return ex.AsStatus()
}
Return $$$OK
}

ClassMethod ActiveNamespacesClose(qHandle As %Binary) As %Status [ PlaceAfter = ActiveNamespacesFetch ]
{
select Nsp,Nsp from %SYS.Namespace_List(0,0) where Status = 1
Kill qHandle
Return $$$OK
}

ClassMethod ListInstalled(ByRef pCommandInfo) [ Private ]
Expand Down

0 comments on commit d3430fd

Please sign in to comment.