PERSIST 文

情報を XML に変換できるようにするために、OpenESQL には PERSIST 文が追加されており、これによりカーソル SELECT 文で定義された情報を XML ファイルとして保存できます。構文は次のとおりです。

PERSIST cursor_name TO xml_destination

ここで、xml_destination には、一重または二重の引用符で囲んだ、識別子、ホスト変数、またはリテラルが当てはまります。またカーソルの SCROLLOPTION を static に設定する必要があります。次に例を示します。

 01  hv  pic x(50).
procedure-division.

*> set whenever clause to handle sql errors
exec sql whenever sqlerror goto sql-error end-exec
exec sql whenever sqlwarning perform sql-warning end-exec

*> connect to data source
exec sql connect to "data source"  end-exec

*> declare static cursor with column info you want to save to xml file
exec sql
declare c static cursor for 
select * from emp
end-exec

*> open cursor
exec sql open c end-exec 

*> save data to xml file using double quoted literal
exec sql 
persist c to "c:\XML Files\xmltest1.xml" 
end-exec 

*> save data to xml file using single quoted literal
exec sql 
persist c to 'c:\XML Files\xmltest2.xml'
end-exec

*> save data to xml file using a host variable
move "c:\XML Files\xmltest3.xml" to hv 
exec sql
persist c to :hv 
end-exec 

*> close the cursor
exec sql close c end-exec

*> disconnect from datasource
exec sql disconnect current end-exec

goback.
注:

Data Direct Connect ODBC ドライバを使用する場合は、バージョン 3.70 以降を使用する必要があります。