Nova postagem

Pesquisar

Artigo
· Mar. 29, 2022 1min de leitura

プログラムでCSVファイルを1行ずつ読み込む方法

これは、InterSystems FAQサイトの記事です。
 

%SQL.Util.Proceduresクラスの CSV() プロシジャを使用することにより、実現できます。
下記が使用例のコードとなります。(test.csvというファイルが c:\temp にあるという前提)

 Set rowtype="Name VARCHAR(50),UID VARCHAR(50), PHONE VARCHAR(50)"
 Set filename="c:\temp\test.csv"
 Set result=##class(%SQL.Statement).%ExecDirect(,"call %SQL_Util.CSV(,?,?)",.rowtype,filename)
 Set rset =result.%NextResult()
 
 // 全件表示したい場合は、do rset.%Display()
 While rset.%Next() {
     Write "Name:",rset.%GetData(1)," UID:",rset.%GetData(2)," PHONE:",rset.%GetData(3),!
     }

 Set rset="",result=""
 Quit

 

上記を実行することにより結果セットとして各行およびフィールドにアクセスできます。
実行例:

USER>do ^CSV
Name    UID     PHONE
山田,太郎 0001    080-1111-1111
bbb     0003    090-2222-2222
ccc     0009    "050-3333-3333"
ddd     0010    0120-17-1972
4 Rows(s) Affected

 

 %SQL.Util.Proceduresクラスのクラスリファレンスも併せてご確認ください。
クラスリファレンス:%SQL.Util.Procedures.CSV()

3 Comments
Discussão (3)1
Entre ou crie uma conta para continuar
Artigo
· Mar. 27, 2022 2min de leitura

.Net Gateway(オブジェクトゲートウェイ)で外部DLLを使用する方法

これはInterSystems FAQ サイトの記事です。

  • まず予め Visual Studioを使用して、呼び出したい内容のクラスライブラリを作成します。
  • そのプロジェクトをコンパイルし、DLLを作成します。
  • 管理ポータルでオブジェクトゲートウェイを作成します。   システム管理 > 構成 > 接続性 > オブジェクトゲートウェイ ゲートウェイ名 : testGateway サーバ名 / IPアドレス : 127.0.0.1 ポート : 55000 (後はデフォルト)  
  • testGateway を開始します。


※管理ポータルから、もしくはコマンドから開始できます。 

do ##class(%Net.Remote.Service).StartGateway(gateway.Name)
  •   以下のいずれかの方法でDLLを呼び出すプロキシクラスを作成します。

       a. コマンドで作成する場合 

     set dllPath="C:\temp\TestDll.dll
     do ##class(%Net.Remote.Gateway).%ExpressImport(dllPath, 55000, "127.0.0.1")

       b. スタジオで作成する場合


 [ツール] - [アドイン] - [.Net ゲートウェイウィザード] ⑥ 以下のような手順でコードを実行します。

例: 

  Set gateway=##class(%Net.Remote.Gateway).%New()
   set host="localhost"
   set port=55000
   set namespace="USER"
   set timeout=2
   Set classPath=##class(%ListOfDataTypes).%New()
   Set samplePath="C:\temp\TestDll.dll"
   Do classPath.Insert(samplePath)
  Set status=gateway.%Connect(host,port,namespace,timeout,classPath)
   write !,"status: ",status
   set cl=##class(TestDll.MyDllClass).%New(gateway)
   do cl.test(gateway)

 

最後の行の do cl.test(..) は、VisualStudioで作成したクラスライブラリの関数になります。

 

呼び出し引数は、作成したプロキシクラスに従ってください。

Discussão (0)1
Entre ou crie uma conta para continuar
Artigo
· Mar. 24, 2022 3min de leitura

GlobalToJSON-XL-Academic

This package offers a utility to export an XLarge Global into a JSON object file and to show
or import it again. In a previous example, this all was processed in memory. But if this is a
large Global you may either experience <MAXSTRING> or an <STORE>  error
if the generated JSON structure exceeds available memory.
 


Academic refers to the structure created.

  • each node of the Global including the top node is represented as a JSON object
  • {"node":<node name>,"val":<value stored>,"sub":[<JSON array of subscript objects>]}
  • value and subscript are optional but one of them always exists for a valid node
  • the JSON object for the lowest level subscript has only value but no further subscript.

So this is basically a 1:1 image of your global and it's exported to a file (default: gbl.json)
In addition to the export, a show method displays the generated file.
The tricky part is the import from file. It is a customize JSON parser as all others just
operate in memory. this fails with a reasonable-sized Global
(eg. ^oddDEF with ~ 1.7 million nodes takes ~ 78MB JSON file.)

Prerequisites

Make sure you have git and Docker desktop installed.

Installation

Clone/git pull the repo into any local directory

git clone https://github.com/rcemper/GlobalToJSON-XLA.git    

Run the IRIS container with your project:

docker-compose up -d --build

How to Test it

This is the pre-loaded Global ^dc.MultiD for testing.
 

There are 3 methods available

  • ClassMethod export(gref As %String = "^%", file = "gbl.json") As %String file = 0 >>> display to terminal
  • ClassMethod show(file = "gbl.json") As %String
  • ClassMethod import( file = "gbl.json", test = 0) As %String test = 1 >>> load into a PPG

Open IRIS terminal

$ docker-compose exec iris iris session iris

USER>write ##class(dc.GblToJSON.XLA).export("^dc.MultiD")
File gbl.json created

USER>write ##class(dc.GblToJSON.XLA).export("^dc.MultiD",0)
{"node":"^dc.MultiD"
,"val":5
,"sub":[
{"node":1
,"val":"$lb(\"Braam,Ted Q.\",51353)"
,"sub":[
{"node":"mJSON"
,"val":"{}"
}
---  truncated ---

USER>>write ##class(dc.GblToJSON.XLA).show()
{"node":"^dc.MultiD"
,"val":5
,"sub":[
{"node":1
,"val":"$lb(\"Braam,Ted Q.\",51353)"
---  truncated ---  

validated JSON object

Now we want to verify the load function as a test into a PPG

USER>write ##class(dc.GblToJSON.XLA).import(,1)
Global ^||dc.MultiD loaded

USER>zwrite ^||dc.MultiD
^||dc.MultiD=5
^||dc.MultiD(1)=$lb("Braam,Ted Q.",51353)
^||dc.MultiD(1,"mJSON")="{}"
^||dc.MultiD(2)=$lb("Klingman,Uma C.",62459)
^||dc.MultiD(2,2,"Multi","a")=1
^||dc.MultiD(2,2,"Multi","rob",1)="rcc"
^||dc.MultiD(2,2,"Multi","rob",2)=2222
^||dc.MultiD(2,"Multi","a")=1
^||dc.MultiD(2,"Multi","rob",1)="rcc"
^||dc.MultiD(2,"Multi","rob",2)=2222
^||dc.MultiD(2,"mJSON")="{""A"":""ahahah"",""Rob"":""VIP"",""Rob2"":1111,""Rob3"":true}"
^||dc.MultiD(3)=$lb("Goldman,Kenny H.",45831)
^||dc.MultiD(3,"mJSON")="{}"
^||dc.MultiD(4)=$lb("","")
^||dc.MultiD(4,"mJSON")="{""rcc"":122}"
^||dc.MultiD(5)=$lb("","")
^||dc.MultiD(5,"mJSON")="{}"
 
USER>

q.a.d.

Code Quality

CodeQuality

Do not wonder about some strange code constructs.
They were required as CodeQuality neither understands the NEW command, nor the scope of %variables  !   sad

Video

Online Demo Terminal
Online Demo SMP

Previous article in DC

GitHub

1 Comment
Discussão (1)1
Entre ou crie uma conta para continuar
Anúncio
· Mar. 23, 2022

Spend a day in a Future City with Global Masters!

Hi Developers!

Let's take a wild ride through the futuristic cities of tomorrow, and the technological advancements they boast! 📡

We invite you to have a journey to the Future City where you can dream of the future, check your knowledge about our Developer Community, and also imagine what the InterSystems Technology will be like. 

So get your devices ready—gear up that self-driving car 🚀, 3D-print some food 🍿, and collect some bonus points! 💰

  

Discussão (0)1
Entre ou crie uma conta para continuar
Artigo
· Mar. 23, 2022 1min de leitura

ObjectScript言語でイメージファイルをWEBサーバからダウンロードする方法

これは InterSystems FAQ サイトの記事です。
 

以下のコードは、https://www.intersystems.com/assets/intersystems-logo.png をダウンロードし、c:\temp\test.pngとしてファイルを保存する例になります。

以下のコードを動作させるためには、SSLTESTという名前のSSL定義を作成しておく必要があります。

 

ClassMethod download() As %Status
{
    Set sc = $$$OK
    Set httprequest=##class(%Net.HttpRequest).%New()
    set httprequest.Port = 443
    set httprequest.Https = 1
    set httprequest.SSLConfiguration = "SSLTEST"
    Set httprequest.Server="www.intersystems.com"
    Do httprequest.Get("/assets/intersystems-logo.png")
    Set httpresponse=httprequest.HttpResponse
    Set file=##class(%File).%New("c:\temp\test.png")
    Do file.Open("NWUK\BIN\")
    Do file.CopyFrom(httpresponse.Data)
    Do file.Close()
    Return sc
}
Discussão (0)1
Entre ou crie uma conta para continuar