Eduard Lebedyuk · May 12, 2017 go to post

To get query text you can query %Dictionary.QueryDefinition. For example:

SELECT *
FROM %Dictionary.QueryDefinition
WHERE Parent = class

Would return all queries for a class.

As for getting only columns, here's some ideas:

  • If the query was executed somewhen and cached, there would be a generated class, holding metadata among other things
  • There are generated methods QueyNameGetInfo and QueryNameGetODBCInfo - they return metainformation about query columns
  • Execute the query and iterate over metadata

What do you want to achieve?

Why is executing a query not possible?

Eduard Lebedyuk · May 12, 2017 go to post

Fast and easy way:

1. Set temporary global:

Set ^temp($zparent, $job) = current status

2. From a parent, iterate over ^temp and display current status.

Other ideas.

1. Try to switch devices before calling $System.Event.Signal($zparent)

2. Can you provide a simple code sample where $System.Event.Signal($zparent) doesn't signals the parent if a device is open?

Eduard Lebedyuk · May 12, 2017 go to post

Call this method to output as HTML the values of all the objects associated with this page. This can be called from anywhere in your page as a debugging aid.

set %response.ContentType = "html"
do ##class(%CSP.Utils).DisplayAllObjects()
Eduard Lebedyuk · May 8, 2017 go to post
  //Set req.Location = "repos/" _ Owner _ "/" _ Repository _ "/contents"

This should resolve into

/repos/vadsamm/sam/contents

And request should go for:

https://api.github.com/repos/vadsamm/sam/contents

I'd uncomment original location line and check call arguments.

Eduard Lebedyuk · May 4, 2017 go to post

Have you tried providing user credentials with %All access?

If you're getting this error for user with %All, and it's a dev box, add %All to /forms application.

Eduard Lebedyuk · May 4, 2017 go to post

Adding this to your REST broker may help:

/// Dispatch a REST request according to URL and Method
ClassMethod DispatchRequest(pUrl As %String, pMethod As %String, pForwarded As %Boolean = 0) As %Status
{
    set pUrl = $zcvt(pUrl, "l")
    quit ##super(pUrl, pMethod, pForwarded)
}
Eduard Lebedyuk · Apr 29, 2017 go to post

50 shouldn't be a problem for URL.  URL length problems starts in thousands. This looks suspiciously like String MAXLEN problem.

Eduard Lebedyuk · Apr 27, 2017 go to post

OnPostHTTP() doesn't get hit, I have tried it first thing. The sample is in the question.

Eduard Lebedyuk · Apr 27, 2017 go to post

My current efforts so far:

Class Test.REST Extends %CSP.REST
{

XData UrlMap [ XMLNamespace = "http://www.intersystems.com/urlmap" ]
{
<Routes>

<Route Url="/:classname" Method="GET" Call="TEST" Cors="true"/>

</Routes>
}

ClassMethod TEST(name) As %Status
{
    set ^CacheTemp.DBG($i(^CacheTemp.DBG)) = "TEST"
    set ^DBG($i(^DBG)) = "TEST"
    //w 1/0
    quit $$$OK
}

/// Issue an '500' error and give some indication as to what occurred
ClassMethod Http500(pE As %Exception.AbstractException) As %Status
{
    set %zzzsc = pE.AsStatus()
    set ^CacheTemp.DBG($i(^CacheTemp.DBG)) = "Http500"
    set ^DBG($i(^DBG)) = "Http500"
    quit ##super(pE)
}

/// Dispatch a REST request according to URL and Method
ClassMethod DispatchRequest(pUrl As %String, pMethod As %String, pForwarded As %Boolean = 0) As %Status
{
    #dim %zzzsc As %Status = $$$OK
    kill ^CacheTemp.DBG,  ^DBG
    
    tstart
    set ^CacheTemp.DBG($i(^CacheTemp.DBG)) = "BeforeDispatch"
    set ^DBG($i(^DBG)) = "BeforeDispatch"
    
    set sc = ##super(pUrl, pMethod, pForwarded)
    
    set ^CacheTemp.DBG($i(^CacheTemp.DBG)) = "AfterDispatch"
    set ^DBG($i(^DBG)) = "AfterDispatch"
    
    if ($$$ISERR(sc) || $$$ISERR(%zzzsc)) {
        set ^CacheTemp.DBG($i(^CacheTemp.DBG)) = "trollback"
        trollback
    } else {
        set ^CacheTemp.DBG($i(^CacheTemp.DBG)) = "tcommit"
        tcommit
    }
    quit sc
}

It works,  but I'm searching for a better solution.

Rollbacked transaction:

>zw ^CacheTemp.DBG, ^DBG
^CacheTemp.DBG=5
^CacheTemp.DBG(1)="BeforeDispatch"
^CacheTemp.DBG(2)="TEST"
^CacheTemp.DBG(3)="Http500"
^CacheTemp.DBG(4)="AfterDispatch"
^CacheTemp.DBG(5)="trollback"

 Commited transaction:

>zw ^CacheTemp.DBG,  ^DBG
^CacheTemp.DBG=4
^CacheTemp.DBG(1)="BeforeDispatch"
^CacheTemp.DBG(2)="TEST"
^CacheTemp.DBG(3)="AfterDispatch"
^CacheTemp.DBG(4)="tcommit"
^DBG=3
^DBG(1)="BeforeDispatch"
^DBG(2)="TEST"
^DBG(3)="AfterDispatch"
Eduard Lebedyuk · Apr 26, 2017 go to post

It calls IsFileSame method from %UnitTest.TestCase class, which has a following  signature:

ClassMethod IsFileSame(file1, file2, ByRef diff) As %Boolean

Diff would contain differences between files. You can check that.

Eduard Lebedyuk · Apr 24, 2017 go to post

As Fabio said

Set class parameter HandleCorsRequest = 1 in your rest service class.

To enable CORS support.

Eduard Lebedyuk · Apr 24, 2017 go to post

There is no such method, but you can copy any number of characters between streams.

What do you want to get by deleting stream lines?

Eduard Lebedyuk · Apr 21, 2017 go to post

Check Ens.ProductionMonitorService business service - it provides a monitor service for the production status.

Eduard Lebedyuk · Apr 20, 2017 go to post

documented way of translation table setting.

Can you please link me to the documentation?

Eduard Lebedyuk · Apr 20, 2017 go to post

Use DATEADD function to add/remove dates, and NOW to get current date:

SELECT DATEADD('d', -1, NOW())

Returns yesterday date:

2017-04-19 20:11:00 
Eduard Lebedyuk · Apr 20, 2017 go to post

Do you want to serve arbitrary files?

I think you can use stream server for that:

/// Return physical file contents
/// name - full path to file
ClassMethod serve(name) As %Status
{
    #dim sc As %Status = $$$OK
    #dim %response As %CSP.Response
    //kill %request.Data
    set %request.Data("STREAMOID",1)= ##class(%CSP.StreamServer).Encrypt(##class(%CSP.StreamServer).GetOidForFile(name))
    if ##class(%CSP.StreamServer).OnPreHTTP() {
        set %response.Headers("Content-Disposition")="attachment; filename*=UTF-8''" _ ##class(%CSP.Page).EscapeURL(##class(%File).GetFilename(name), "UTF8")
        set sc = ##class(%CSP.StreamServer).OnPage()
    }

    quit sc
}

Also parameter cannot be assigned.

Eduard Lebedyuk · Apr 20, 2017 go to post

Please clarify the following points:

  • How does the code breaks? What error do you receive? At what point?
  • Can you show a sample row?
Eduard Lebedyuk · Apr 20, 2017 go to post

Files in OS by themselves do not have Content-Type attribute (streams, in web context can have Content-Type attribute). However, knowing file extension Caché has FileClassify utility method that can determine content type. Here's the wrapper I usually use:

/// Determine file mime type
/// name - full path to file
ClassMethod getFileType(name) As %String
{
    set ext = $zcvt($p(name, ".", *), "U")
    do ##class(%CSP.StreamServer).FileClassify(ext, .type , .bin, .charset)
    set ext = "/" _ ext _ "/"
    if ext = "/RTF/" {
        set type = "application/rtf"
    }
    
    return type
}

Or you can additional types into:

 set ^%SYS("CSP","MimeFileClassify", ext) = $lb(type, bin, charset)
Eduard Lebedyuk · Apr 20, 2017 go to post

It's better to use stream wrappers instead of open/use directly.

I'm not sure what's the correct way to set codepage with open command.

Eduard Lebedyuk · Apr 20, 2017 go to post

Extra curly brace is there by design.

Seems like strings starting from {, are json-parsed.

Eduard Lebedyuk · Apr 20, 2017 go to post

That's, I think is an unrelated issue. This SQL:

SELECT JSON_OBJECT('id': '{{}')

Also throws the same error:

[SQLCODE: <-400>:<Fatal error occurred>]
[%msg: <Unexpected error occurred in JSON_OBJECT() function execution of <JSON_OBJECT>.%FromJSON({{}).Parsing error :: Line 1 Offset 2>]

Seems like some data escaping is required.

Very simple escaping (this query executes successfully):

SELECT JSON_OBJECT('id': ' '||'{{}')
Eduard Lebedyuk · Apr 20, 2017 go to post

Use translate table:

ClassMethod create(file) As %Status
{
    set stream = ##class(%Stream.FileCharacter).%New()
    set stream.TranslateTable = "CP874"
    set sc = stream.LinkToFile(file)
    quit:$$$ISERR(sc) sc
    
    do stream.WriteLine("Hello")

    quit stream.%Save()
}