Nova postagem

Pesquisar

Artigo
· Abr. 22 5min de leitura

ADO.NET Managed Provider を使用してクラスクエリを実行し、結果セットを取得するサンプル

先日、お客様よりタイトルのご質問をいただき、サンプルコードを作成しました。せっかくですので、こちらでも共有したいと思います。

今回は、データベースの空き容量情報を取得する、%SYS.DatabaseQueryクラスのFreeSpaceクエリを使用したサンプルとします。

C#.Net と VB.Net で作成してみました。


★C#.Net

using System;
using InterSystems.Data.IRISClient;
{
    class Program
    {
        static void Main(string[] args)
        {
            IRISConnection IRISConnect = new IRISConnection();
            IRISConnect.ConnectionString = "Server=localhost;Port=1972;Namespace=USER;User ID=_SYSTEM;Password=SYS";
            IRISConnect.Open();
            String queryString = "select * from %SYS.DatabaseQuery_FreeSpace(?)";  // call %SYS.DatabaseQuery_FreeSpace(?) でもOK
            IRISCommand cmd = new IRISCommand(queryString, IRISConnect);
            IRISParameter p1 = new IRISParameter("Mask", IRISDbType.NVarChar);
            p1.Value = "*";
            cmd.Parameters.Add(p1);
            IRISDataReader Reader = cmd.ExecuteReader();
            while (Reader.Read())
            {
                // Select values : DatabaseName:0, Directory:1, MaxSize:2, Size:3, ExpansionSize:4, Available:5, %Free:6, DiskFreeSpace:7, Status:8, SizeInt:9, AvailableNum:10, DiskFreeSpaceNum:11, ReadOnly:12
                Console.WriteLine(Reader.GetValue(0).ToString() + ", " + Reader.GetValue(3).ToString() + ", " + Reader.GetValue(5).ToString());
            }
            Reader.Close();
            cmd.Dispose();
            IRISConnect.Close(); 
        }
    }
}


★VB.Net

Imports System
Imports InterSystems.Data.IRISClient

Module Program
    Sub Main(args As String())
        Dim conn As New IRISConnection
        conn.ConnectionString = "Server=localhost;Port=1972;Namespace=USER;User ID=_SYSTEM;Password=SYS"
        conn.Open() 
        Dim queryString As String = "select * from %SYS.DatabaseQuery_FreeSpace(?)"   ''call %SYS.DatabaseQuery_FreeSpace(?) でもOK
        Dim cmd As IRISCommand = New IRISCommand(queryString, conn)
        Dim p1 As IRISParameter = New IRISParameter("Mask", "*")
        cmd.Parameters.Add(p1)
        Dim reader As IRISDataReader = cmd.ExecuteReader()
        Do While (reader.Read())
            '' Select values : DatabaseName : 0, Directory:1, MaxSize:2, Size:3, ExpansionSize:4, Available:5, %Free:6, DiskFreeSpace:7, Status:8, SizeInt:9, AvailableNum:10, DiskFreeSpaceNum:11, ReadOnly:12
            Console.WriteLine(reader.GetValue(0).ToString() + ", " + reader.GetValue(3).ToString() + ", " + reader.GetValue(5).ToString())
        Loop 
        reader.Close()
        cmd.Dispose()
        conn.Close()
    End Sub
End Module


※参照の追加手順

Visual Studioの [プロジェクト] > [プロジェクト参照の追加] をクリックします
参照マネージャにて、参照より以下を追加します(.Netのバージョンにあわせて選択してください)
例)C:\InterSystems\IRIS\dev\dotnet\bin\net8.0\InterSystems.Data.IRISClient.dll


なお、ストアドプロシージャ(ストアド)の場合も、同様に実行することが可能です。

ともに、 SqlProc キーワードを指定して、SQL ストアドプロシージャとして呼び出すことができるようにする必要があります。

例(クラスクエリのサンプル):select * from Sample.SP_Sample_By_Name(?)  または  call Sample.SP_Sample_By_Name(?)

Query ByName(name As %String = "") As %SQLQuery(CONTAINID = 1, SELECTMODE = "RUNTIME") [ SqlName = SP_Sample_By_Name, SqlProc ]
{
SELECT ID, Name, DOB, SSN
FROM Sample.Person
WHERE (Name %STARTSWITH :name)
ORDER BY Name
}


例2(ストアドプロシージャのサンプル):call Sample.Stored_Procedure_Test(?,?)

ClassMethod StoredProcTest(name As %String, ByRef response As %String) As %Integer [ SqlName = Stored_Procedure_Test, SqlProc ]
{
    // Set response to the concatenation of name.
    Set response = name _ "||" _ name
    QUIT 29
}

例2 の場合は以下のような C# コードになります(一部省略)

   String queryString = "? = call Sample.Stored_Procedure_Test(?,?)";
   IRISCommand cmd = new IRISCommand(queryString, IRISConnect);
   IRISParameter p1 = new IRISParameter();
   p1.Direction = ParameterDirection.ReturnValue;
   p1.IRISDbType = IRISDbType.Int;
   IRISParameter p2 = new IRISParameter();
   p2.Direction = ParameterDirection.Input;
   p2.Value = "InterSystemsJapan";
   IRISParameter p3 = new IRISParameter();
   p3.Direction = ParameterDirection.Output;
   cmd.Parameters.Add(p1);
   cmd.Parameters.Add(p2);
   cmd.Parameters.Add(p3);
             
   cmd.ExecuteReader();
   Console.WriteLine("Return value = " + p1.Value + ", " + "ByRef response = " + p3.Value);


ご利用の機会がありましたら、ぜひ参考になさってください。

以下のドキュメントもあわせてご覧ください。
ADO.NET Managed Provider の使用法
InterSystems IRIS デモ : ADO.NET を使用した接続

Discussão (0)0
Entre ou crie uma conta para continuar
Resumo
· Abr. 22

Your Invitation to Code Your Way to InterSystems READY 2025

Dear Developer Community member,

We’re excited to invite you to our global developer initiative:

🎯 Code Your Way to InterSystems READY 2025

Task: Upload your side project based on InterSystems IRIS, tell us your story, and you could win a pass to InterSystems READY 2025 and a hotel accommodation!

Duration: April 21 - May 04, 2025

Prizes: hotel accommodation and free passes to the InterSystems READY 2025!

How to enter:

  1. Upload a fun IRIS-based side project to Open Exchange. Be creative - it can be useful, quirky, fun, or just something you’ve always wanted to try.
  2. Record a short inspirational video (up to 5 minutes):
    • Tell us how InterSystems technologies or the Developer Community impacted your project or career.
    • Explain why YOU should get a ticket to the InterSystems READY 2025.
  3. Submit your video and a link to your app via this form.

>> Full details here

Let’s celebrate creativity and community. Show us what you’ve got!

Pergunta
· Abr. 22

Field Validation on INSERT error installing git-source-control

Hi - I'm refreshing my IRIS instance, now upgraded to 2025.1, and ensuring IPM is installed in each namespace, as well as git-source-control, but in my first attempt I get this error. 

Everything else seems to work - but why the error (I'd like to get rid of it) ?

zpm:AULIBRARY>install git-source-control
 
[AULIBRARY|git-source-control]  Initialize START
[AULIBRARY|git-source-control]  Initialize SUCCESS
[AULIBRARY|git-source-control]  Reload START (C:\InterSystems\IRIS\mgr\Temp\VTigyGg\)
[AULIBRARY|git-source-control]  Reload SUCCESS
[git-source-control]    Module object refreshed.
[AULIBRARY|git-source-control]  Validate START
[AULIBRARY|git-source-control]  Validate SUCCESS
[AULIBRARY|git-source-control]  Compile START
[AULIBRARY|git-source-control]  Compile SUCCESS
[AULIBRARY|git-source-control]  Activate START
[AULIBRARY|git-source-control]  Configure START
Adding favorites for all users:
Adding Git favorite...
 
[SQLCODE: <-104>:<Field validation failed in INSERT, or value failed to convert in DisplayToLogical or OdbcToLogical>]
[%msg: <Field '%SYS_Portal.Users.Data' (value '/isc/studio/usertemplates/gitsourcecontr...') failed validation>]
0 Rows Affected
Adding Git Pull favorite...
 
[SQLCODE: <-104>:<Field validation failed in INSERT, or value failed to convert in DisplayToLogical or OdbcToLogical>]
[%msg: <Field '%SYS_Portal.Users.Data' (value '/isc/studio/usertemplates/gitsourcecontr...') failed validation>]
0 Rows Affected
Setting GroupById to %ISCMgtPortal for /isc/studio/usertemplates... 1 Row Affected
Will use git version 2.40.0.windows.1 (already installed and on the PATH).
[AULIBRARY|git-source-control]  Configure SUCCESS
[AULIBRARY|git-source-control]  Activate SUCCESS

thanks - Steve

Discussão (0)1
Entre ou crie uma conta para continuar
Pergunta
· Abr. 21

My AI use case - need help with Ollama and / or Langchain

I am brand new to using AI. I downloaded some medical visit progress notes from my Patient Portal. I extracted text from PDF files. I found a YouTube video that showed how to extract metadata using an OpenAI query / prompt such as this one:

ollama-ai-iris/data/prompts/medical_progress_notes_prompt.txt at main · oliverwilms/ollama-ai-iris
 

I combined @Rodolfo Pscheidt Jr https://github.com/RodolfoPscheidtJr/ollama-ai-iris with some files from @Guillaume Rongier https://openexchange.intersystems.com/package/iris-rag-demo.

I attempted to run

python3 query_data.py
Traceback (most recent call last):
  File "/irisdev/app/query_data.py", line 39, in <module>
    response = query_engine.query(prompt_data)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/irisowner/.local/lib/python3.12/site-packages/llama_index/core/instrumentation/dispatcher.py", line 322, in wrapper
    result = func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/home/irisowner/.local/lib/python3.12/site-packages/llama_index/core/base/base_query_engine.py", line 52, in query
    query_result = self._query(str_or_query_bundle)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/irisowner/.local/lib/python3.12/site-packages/llama_index/core/instrumentation/dispatcher.py", line 322, in wrapper
    result = func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/home/irisowner/.local/lib/python3.12/site-packages/llama_index/core/query_engine/retriever_query_engine.py", line 179, in _query
    response = self._response_synthesizer.synthesize(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/irisowner/.local/lib/python3.12/site-packages/llama_index/core/instrumentation/dispatcher.py", line 322, in wrapper
    result = func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/home/irisowner/.local/lib/python3.12/site-packages/llama_index/core/response_synthesizers/base.py", line 241, in synthesize
    response_str = self.get_response(
                   ^^^^^^^^^^^^^^^^^^
  File "/home/irisowner/.local/lib/python3.12/site-packages/llama_index/core/instrumentation/dispatcher.py", line 322, in wrapper
    result = func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/home/irisowner/.local/lib/python3.12/site-packages/llama_index/core/response_synthesizers/compact_and_refine.py", line 43, in get_response
    return super().get_response(
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/irisowner/.local/lib/python3.12/site-packages/llama_index/core/instrumentation/dispatcher.py", line 322, in wrapper
    result = func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/home/irisowner/.local/lib/python3.12/site-packages/llama_index/core/response_synthesizers/refine.py", line 179, in get_response
    response = self._give_response_single(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/irisowner/.local/lib/python3.12/site-packages/llama_index/core/response_synthesizers/refine.py", line 241, in _give_response_single
    program(
  File "/home/irisowner/.local/lib/python3.12/site-packages/llama_index/core/instrumentation/dispatcher.py", line 322, in wrapper
    result = func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/home/irisowner/.local/lib/python3.12/site-packages/llama_index/core/response_synthesizers/refine.py", line 85, in __call__
    answer = self._llm.predict(
             ^^^^^^^^^^^^^^^^^^
  File "/home/irisowner/.local/lib/python3.12/site-packages/llama_index/core/instrumentation/dispatcher.py", line 322, in wrapper
    result = func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/home/irisowner/.local/lib/python3.12/site-packages/llama_index/core/llms/llm.py", line 605, in predict
    chat_response = self.chat(messages)
                    ^^^^^^^^^^^^^^^^^^^
  File "/home/irisowner/.local/lib/python3.12/site-packages/llama_index/core/instrumentation/dispatcher.py", line 322, in wrapper
    result = func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/home/irisowner/.local/lib/python3.12/site-packages/llama_index/core/llms/callbacks.py", line 173, in wrapped_llm_chat
    f_return_val = f(_self, messages, **kwargs)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/irisowner/.local/lib/python3.12/site-packages/llama_index/llms/ollama/base.py", line 322, in chat
    response = self.client.chat(
               ^^^^^^^^^^^^^^^^^
  File "/home/irisowner/.local/lib/python3.12/site-packages/ollama/_client.py", line 333, in chat
    return self._request(
           ^^^^^^^^^^^^^^
  File "/home/irisowner/.local/lib/python3.12/site-packages/ollama/_client.py", line 178, in _request
    return cls(**self._request_raw(*args, **kwargs).json())
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/irisowner/.local/lib/python3.12/site-packages/ollama/_client.py", line 124, in _request_raw
    raise ConnectionError(CONNECTION_ERROR_MESSAGE) from None
ConnectionError: Failed to connect to Ollama. Please check that Ollama is downloaded, running and accessible. https://ollama.com/download


 

Discussão (0)1
Entre ou crie uma conta para continuar
Anúncio
· Abr. 21

HealthShare Unified Care Record Overview - Virtual May 15-16, 2025 - Registration space available

  • HealthShare Unified Care Record Overview – Virtual May 15-16, 2025
    • The HealthShare Unified Care Record Overview course is a great way for anyone to become familiar with Unified Care Record, but especially those who need to understand its capabilities but not how to configure HealthShare Unified Care Record.
    • This is a non-technical, instructor-led in person training course providing a comprehensive introduction to HealthShare Unified Care Record.
    • This course is for anyone who needs to know about the functionality and architecture of HealthShare Unified Care Record.  (If you need information on configuring and troubleshooting Unified Care Record, consider the HealthShare Unified Care Record Fundamentals class.)
    • No prior knowledge or experience is required for the Overview class and any InterSystems employee may enroll.
  • Self-Register Here
Discussão (0)1
Entre ou crie uma conta para continuar