Limyandi Vicotrico · Jan 13, 2021

SQL Export Data with %SQL.ExportMgr

Hi Everyone,


I am trying the Export and Import application as per this link referred here: ExImData


I have the following sample class I am trying to import:

Class Persistent.PersonBackup Extends %Persistent
{ Property Name As %String; Storage Default
<Data name="PersonBackupDefaultData">
<Value name="1">
<Value name="2">
} }

And the below is the SQL Representation:


When I try to Export this data using the %SQL.ExportMgr with the following code (as per example in the referred link)

/// do setupExportImport^uTask12440("Export","PERSISTENT","PERSONBACKUP")
 If Wizard = "Export" 
  set mgr = ##class(%SQL.Export.Mgr).%New()
 Else Set mgr = ##class(%SQL.Import.Mgr).%New() }
 Set mobj = ##class(%SQL.Manager.API).%New()
 Set ok = mobj.CheckIdentifier(.SchemaName)
 Set ok = mobj.CheckIdentifier(.TableName)
 Set classname = mobj.FindClassName(SchemaName_"."_TableName)
 Set mgr.FileName = "c:\intersystems\cachepro\mgr\user\data.txt"
 Set mgr.TableName = SchemaName_"."_TableName
 Set mgr.ClassName = classname
 Set mgr.Delimiter = $c(9) // tab
 Set mgr.StringQuote = "" // double quotes
 Set mgr.DateFormat = 1 // MM/DD/{YY}YY
 Set mgr.TimeFormat = 1 // hh:mm:ss
 Set mgr.TimeStampFormat = 1 // ODBC format (Import only)
 Set mgr.NoCheck = 1 // disable validation (Import only)
 Set mgr.HasHeaders = 1 // import file contains column headers
 Do mgr.ColumnNames.Insert("Name") // insert a column name
 Do mgr.ColumnTypes.Insert("String") // insert a column datatype
 if (Wizard="Export") do Export
  Set result = mgr.GenerateExportRoutine()
  If result '= 1 Write !,"Error generating export routine: ",result Quit
  Set sta = mgr.OpenExport()
  If $$$ISERR(sta) {
    Set ErrMsg = "Unable to open export file"
  Else {
    Set sta = mgr.GetExportSize(.size)
    If size = 0 {
  Else {
    Set tSC = $$$OK
    Do {
      Set tSC = mgr.ExportRows(.rows,.done)
      Set total = total + rows
      If $$$ISERR(tSC) Quit
    While done = 0
    If $$$ISOK(tSC) {
      Set tmsg = "Completed at "_$ZDATETIME($HOROLOG)
    Else {
      Set tmsg ="Error occurred during export."
    Set statusmsg = "Exported: "_total_" rows"
    Write !,tmsg,!,statusmsg
    Do mgr.CloseExport()
  Do mgr.DeleteExportRoutine()

I keep getting the following error:


I have no idea what is causing this error as this code is generated in the function:


Any input is highly appreciated.

Product version: Caché 2017.1
2 0 3 84
Log in or sign up to continue


your code is : 

 Set classname mobj.FindClassName(SchemaName_"."_TableName)

 Set mgr.TableName SchemaName_"."_TableName
 Set mgr.ClassName classname

The class  to Export:  Class Persistent.PersonBackup Extends %Persistent

BUT you call it:

do setupExportImport^uTask12440("Export","PERSISTENT","PERSONBACKUP")

Try instead:

do setupExportImport^uTask12440("Export","Persistent","PersonBackup")

So the generator can find your class

Thanks for the answer. I generally tried this but it did not work too. I changed it back to the proper name but still getting the same error.

You might also need to add:
Set mgr.IQN=SchemaName_"."_$Translate(TableName,".",$c(2))