Michael is a
Curious Researcher
Recap 2022
Publications:
1question
3comments
Top Post:
170
people reached
User bio
404 bio not found
Member since Feb 17, 2022
Replies:

This worked for me as well. In my case I was parsing an XML file ANSI encoded without proper header. Once the stream hit a special charachter (in my case "à") it wouldn't recognize it. I presume %XML.XPATH.Document and %XML.TextReader default to UTF-8 in this case, after converting the stream I was able to parse without issues.

set cda2Stream = ##class(%Stream.FileBinary).%New()
$$$ThrowOnError(cda2Stream.LinkToFile(cda2FileName))
// Converting to UTF-8 encoding as the original stream is ANSI encoded without proper header
set convertedStream = ##class(%Stream.GlobalBinary).%New()
while 'cda2Stream.AtEnd {
	$$$ThrowOnError(convertedStream.WriteLine($zconvert(cda2Stream.ReadLine(),"O","UTF8")))
}
// Parsing the converted stream
$$$ThrowOnError(##class(%XML.TextReader).ParseStream(convertedStream,.Textreader))
$$$ThrowOnError(##class(%XML.XPATH.Document).CreateFromStream(convertedStream,.XpathDoc))
set XpathDoc.PrefixMappings = "s urn:hl7-org:v3"

I think XML would be the best way, especially if you want to do it programmatically. This snippet will export your table to the specified folder

ClassMethod ExportTable(table As %String, path As %String)
{
	set class = $replace($replace(table,"_",""),"SQLUser.","User.")
	set sqlQuery = "select $listbuild(%Id,'"_class_"') as oid from "_table
	
	set rset = ##class(%SQL.Statement).%ExecDirect(,sqlQuery)
	while rset.%Next() {
		set elements(rset.%Get("oid"))=""
	}
	
	do ##class(XML.Element).Export(.elements, path_"/"table_".xml", "r")
}

And then you import it on the other instance with:

##class(XML.Element).Load(file,"/overwriteguid/notransaction/changecontrolskipevents")

The advantage of this solution is that it uses %GUIDs as identifiers, as such you can add/edit data on your target system and it won't be overwritten when importing the file. 

An alternative way without having direct access to file system would be use a JDBC client with export functionality. I use DBeaver and you can right click on your query/table -> Execute -> Export from query:

 

Do you initialize your target variable as an instance of an object that has Name property? The following snippet works for me

Class Custom.Test Extends %RegisteredObject
{
Property Name As %String; 

ClassMethod SQL()
{
    set target = ##class(Custom.Test).%New()
    &sql(SELECT 'TestName' INTO :target.Name FROM MainFrame.EmployeeRecord)
    write target.Name
}
}

Also, assuming you are running your test in console, you can issue write $zerror it will tell you which property is missing (could be related to something in the source rather than the target)

Followers:
Following:
Michael has not followed anybody yet.
Global Masters badges: