Contestant

Hi Community,

In this article, we will explore the concepts of Dynamic SQL and Embedded SQL within the context of InterSystems IRIS, provide practical examples, and examine their differences to help you understand how to leverage them in your applications.

InterSystems SQL provides a full set of standard relational features, including the ability to define table schema, execute queries, and define and execute stored procedures. You can execute InterSystems SQL interactively from the Management Portal or programmatically using a SQL shell interface. Embedded SQL enables you to embed SQL statements in your ObjectScript code, while Dynamic SQL enables you to execute dynamic SQL statements from ObjectScript at runtime. While static SQL queries offer predictable performance, dynamic and embedded SQL offer flexibility and integration, respectively.

Dynamic SQL

Dynamic SQL refers to SQL statements that are constructed and executed at runtime, as opposed to static SQL, which is predefined and embedded directly in the application code. Dynamic SQL is particularly useful when the structure of a query is not known in advance or needs to be dynamically adjusted based on user input or application logic.

In InterSystems IRIS, Dynamic SQL is implemented through the %SQL.Statement class, which provides methods for preparing and executing SQL statements dynamically.

Key Benefits of Dynamic SQL

  1. Flexibility: Dynamic SQL allows you to build queries programmatically, making it ideal for applications with complex or changing requirements.
  2. Adaptability: You can modify queries based on runtime conditions, such as user input or application state.
  3. Ad-Hoc Queries: If the application needs to generate custom queries based on user input, Dynamic SQL allows the construction of these queries at runtime.
  4. Complex Joins and Conditions: In scenarios where the number of joins or conditions can change based on data, Dynamic SQL enables the construction of complex queries.


Practical Examples

1- Dynamic Table Creation: Building Database Schemas on the Fly

This example demonstrates how to dynamically create a table at runtime using InterSystems Dynamic SQL, enabling flexible and adaptive database schema management.

ClassMethod CreateDynamicTable(tableName As %String, columns As %String) As %Status
{
    // Construct sql text
    Set sql = "CREATE TABLE " _ tableName _ " (" _ columns _ ")"
    //Create an instance of %SQL.Statement
    Set statement = ##class(%SQL.Statement).%New()
    //Prepare the query
    Set status = statement.%Prepare(sql)
    If $$$ISERR(status) {
        Quit status
    }
    //Execute the query
    Set result = statement.%Execute()
    //Check for errors
    If result.%SQLCODE = 0 {
        Write "Table created successfully!", !
    } Else {
        Write "Error: ", result.%SQLCODE, " ", result.%SQLMSG, !
    }
    Quit $$$OK
}

Invoke Method

USER>do ##class(dc.DESql).CreateDynamicTable("Books","BookID NUMBER NOT NULL,Title VARCHAR(100),Author VARCHAR(300),PublicationYear  NUMBER NULL, AvailableFlag  BIT")

Output

1 2
0 14

I have been trying to get to grips with the new dot Net Gateway used in IRIS as the import of the DLL to construct proxy classes is no longer supported in IRIS I have a third party DLL that when I try to instantiate throws an error complaining about the class not instantiated as it does not support parameterless constructor .I am using this new

0 5
0 20

Hello everyone

I have a question about the maximum number of active license users for CACHÉ.

When I run the command: Do $System.License.ShowCounts()

I get the following return:

1 Current active users
3 Maximum active users
0 CSP users currently active
1 Maximum active CSP users
0 CSP sessions currently in 'grace period'
1 Maximum CSP sessions in 'grace period'

0 3
0 37

I have an old .NET 4.5 project, working with database InterSystems.Cache. The project is deployed on a Windows server. Data is retrieved using the InterSystems.Data.CacheClient.dll library.

But now I'm planning migration of the project to .NET 8 to container with linux centos.

How can I get data from InterSystems.Cache in this case?

As I understand it, InterSystems.Data.CacheClient.dll is only for the .NET framework.

0 2
0 40

Dear Fellow Cache Gurus: I would like to know if there is either any built-in Cache Date/Time function or an easy way to include a timezone abbreviation such as EST, PST, MST, etc... within the Cache Date/Time formats.

I read through the Cache Documentation but could not find anything to achieve this.

So if I do the following command: $ZDateTime($H,1,4,,,4,,,,,"InvalidDate"), then I get an output like this: 02/27/2025 11:10AM

But I am looking for the output to be formatted like this: 02/27/2025 11:10AM EST

0 0
0 11
Contestant

Motivation

I started programming back in 2015, when I was doing my bachelor's in computer science. I didn't know about ObjectScript until I started my new job four months ago. Objectscript isn't actually a young programming language. Compared to C++, Java and Python, the community isn't as active, but we're keen to make this place more vibrant, aren't we?

5 5
2 89

So, you checked your server and saw that IRISTEMP is growing too much. There's no need to panic. Let’s investigate the issue before your storage runs out.

Step 1: Confirm the IRISTEMP Growth Issue

Before assuming IRISTEMP is the problem, let’s check its actual size.

Check the Free Space

Run the following command in the IRIS terminal:

%SYS>do ^%FREECNT

When prompted, enter:

3 3
0 75

Hello,

So i want to use the INSERT OR UPDATE command so i can update a COUNTER for a given name:

INSERT OR UPDATE myTable
SET name='Omer', counter = counter + 1;


as you can see with the above code - if the row is non-existent then we get an error because COUNTER is NULL!
I tried the following to fix this but all have failed:

3 26
0 237

Hello community members!

I am trying to connect to Caché database from Azure data factory using ODBC connection. The aim is to read data from Caché and write it in Azure blob storage using copy activity. The ODBC connection is successful and i can see the Caché tables, but i'm facing an error while reading the table contents.

I'm getting the below error :

0 5
0 384


Hello!

This article is a small overview of a tool that helps to understand classes and their structure inside the InterSystems products: from IRIS to Caché, Ensemble, HealthShare.

In short, it visualizes a class or an entire package, shows the relations between classes and provides all the possible information to developers and team leads without making them go to Studio and examine the code there.

If you are learning InterSystems products, reviewing projects a lot or just interested in something new in InterSystems Technology solutions — you are more than welcome to read the overview of ObjectScript Class Explorer!

23 38
4 5.9K

Hi Community,

I have a problem I am hoping someone can help with - I have created a front-end with HTML/CSS/JS in a CSP page in Iris Studio. I am trying to use objectscript on the back end to connect to a SQL Server Database (with valid credentials), and execute a stored procedure.

I have a fileList variable that is a stored as a comma separated string through a user input textBoxContainer. This is to be used as a parameter in the stored procedure called @Docs

0 1
0 31

Hi, this post was initially written for Caché. In June 2023, I finally updated it for IRIS. If you are revisiting the post since then, the only real change is substituting Caché for IRIS! I also updated the links for IRIS documentation and fixed a few typos and grammatical errors. Enjoy :)

23 29
8 11.4K

We're looking for an experienced developer to join our team and help with the project on a part-time basis (20-30 hours a week). Required experience includes InterSystems Cache, PHP, and API. We're ready to start immediately if you're available. Fluency in English and the ability to work in the US time zone is preferred.

About Us:
Redline Coders, an IT consulting firm in California.

Position Details:
- Remote
- 20-30 hours a week
- Duration: 1-2 months

1 5
0 314

Hey everyone,
Might be a stupid question, but i was trying to set the ContentLength of the %response object in my website.
In different places (like the onPreHttp / onPostHttp etc) but none seems to work.

The reason behind it is to send a more accurate representation of the actual data I send, instead of having the overhead of the broker that adds more characters , I want the exact length of the response accounting only for the data that I actually returned.

0 2
0 32
Contestant

I have a scenario where I send a GET request to a broker and receive a FHIR response. When I attempted to use the built-in InterSystems functions to convert this FHIR response into SDA, the transformation failed—likely because it is not a standard FHIR request.

How should I handle this situation? Is there a recommended approach to processing FHIR responses in this context?

0 3
0 41

My usecase is sorting and removing duplicates and getting count from a file that has json messages as a individual rows.

I am currently planning to use pandas for this purpose as its really fast. Below are the steps i am following

1) call a python function (called function) from IRIS classmethod(calling function)

2) the call python function will read the json file in a dataframe

3) perform sorting, dup removal, count in the dataframe

4) convert the dataframe into iris stream

5) return back the stream to iris calling function class method

0 6
0 77

At the moment we're creating multiple BPLs are using a router (or another BPL) to direct to these based on a unique key modulo the amount of BPLs available, e.g. if we have 3 BPLs created.

Message key = 1 mod 3 + 1 -> BPL02
Message key = 2 mod 3 + 1 -> BPL03
Message key = 3 mod 3 + 1 -> BPL01

FIFO only matters in that each messages for each key is processed in order.

1 7
0 80