ObjectScript

Syndicate content 30 

This post is intended to guide you through the new JSON capabilities that we introduced in Caché 2016.1. JSON has emerged to a serialization format used in many places. The web started it, but nowadays it is utilized everywhere. We've got plenty to cover, so let's get started.

Last comment 11 January 2019
+ 32   1 33
6824

views

+ 32

rating

Have some free text fields in your application that you wish you could search efficiently?  Tried using some methods before but found out that they just cannot match the performance needs of your customers?  Do I have one weird trick that will solve all your problems?  Don’t you already know!?  All I do is bring great solutions to your performance pitfalls!

As usual, if you want the TL;DR (too long; didn’t read) version, skip to the end.  Just know you are hurting my feelings.

If you open up your version of Sample.Company in the SAMPLES namespace of a recent (2015.1 or later) Caché/Ensemble/HealthShare version you will see a Mission field that is pseudo-randomly generated text.  Suppose we want to search this text field.  For the purpose of this exercise, I generated about 256,246 companies – feel free to populate some on your own and follow along.  Well you might run the following query

Last comment 5 December 2016
+ 19   1 2
1155

views

+ 19

rating

The topic of for/while loop performance in Caché ObjectScript came up in discussion recently, and I'd like to share some thoughts/best practices with the rest of the community. While this is a basic topic in itself, it's easy to overlook the performance implications of otherwise-reasonable approaches. In short, loops iterating over $ListBuild lists with $ListNext or over a local array with $Order are the fastest options.

As a motivating example, we will consider looping over the pieces of a comma-delimited string.

A natural way to write such a loop, in minimal code, is

Last comment 3 October 2016
+ 18   0 12
4239

views

+ 18

rating


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!

Last comment 3 July 2018
+ 17   1 11
3077

views

+ 17

rating

Cache rendering of an old classic:

 s enc="dQZ4nK1VzU7DMAy+I/EEveTcCWicpt3UU2VABTRA/AhBeYW+As/U7vE4VNhxypJuoAlhS1vixJ//"_
 "06TNsy5p4TppzRKTNqtMXuXQjSSrdEPSEmmtK1uZssp1l0Z3nHJ9fEQroJURlQLHNE35WPYWx7N3"_
 "YpJYkeRe4mQzkEKuGDwjkHTBP+9JW4oUsB+Y2CVj2JuttlkFAbhbfdIuRU/jhvZkryejtNok7UpO"_
 "Moww3JbdcPifW8APosVi4Q9Otwck5LMojmKOojNnDUIXe0XEvnVrdaEeiF95H8BYgXG38o6i0Vpg"_
 "lhSO00TVkN6VelRPaq1q9ehucnizrGopJ5TY+8zHzOBSPih8jjnLQWbyKSYy25Cpe+JXMTdM2dZS"_
 "cbAu3YP42EQw4GOq1a16VjfEtWoCGHJdS5dAjkPoYgRTCsw8DG4MaSAw2G++KfA6So0v9xTJVmHD"_
 "0UjTAeD4TQ7oRr1EMMbXm2N6IyO1AxtDLS2NCBqHiCIYX+9hLxGGtCxk2Me0D8Q5eknNcafW0j47"_
 "SiBNqVcYTSHEM3ASTfwvogDB4qFKc9G+YTzYg4yfqYyfqd2M6O6KqnOh3vgaK1SHIP8403/IitX/"_
 "khVb/JYVkBdCh4/53gmCHyZoh3kApk/BrNdcOsBMDzb/hCPEI+zfA/fnvjTWnn8BUo3vtEE=" 
 s enc=$SYSTEM.Util.Decompress($SYSTEM.Encryption.Base64Decode(enc))
 w enc

Share more ANSI art!

Merry XMas and a Happy New Year!

Last comment 31 December 2016
+ 16   0 9
621

views

+ 16

rating

Greetings, InterSystems community!

I am pleased to announce that the web terminal project, Caché WebTerminal version 4 gets its release! After long period of enhancing this web application from 2013, it came to the version 4, which features major stability and security improvements, intelligent autocomplete and syntax highlighting, convenient SQL mode and a lot of other useful features.

The goal of this article is to spread the knowledge about this project over the InterSystems community.

Last comment 26 February 2019
+ 15   2 8
1674

views

+ 15

rating

Class Queries in InterSystems Caché is a useful tool that separates SQL queries from Caché Object Script code. Basically, it works like this: suppose that you want to use the same SQL query with different arguments in several different places.In this case you can avoid code duplication by declaring the query body as a class query and then calling this query by name. This approach is also convenient for custom queries, in which the task of obtaining the next row is defined by a developer. Sounds interesting? Then read on!

Last comment 9 December 2016
+ 14   0 9
3697

views

+ 14

rating

In this article we are going to compare $Increment and $Sequence functions.

First of all, a note for readers who have never heard of $Increment. $Increment is a Caché ObjectScript function which performs an atomic operation to increment its argument by 1 and return the resulting value. You can only pass a global or local variable node as a parameter to $Increment, not an arbitrary expression. $Increment is heavily used when assigning sequential IDs. In such cases parameter of $Increment is usually a global node. $Increment guarantees that each process using it gets a unique ID

Last comment 19 August 2016
+ 14   0 8
742

views

+ 14

rating

Importance and Collection of Exact Version Information ($zv / $zversion)
 
The explanation of:
- why collecting $zv is important (The WHY),
- what the components of $zv mean (The WHAT),
- and how to collect $zv (The HOW). 
(The Ultimate $zv Guide to the ISC Galaxy in large, friendly letters)
Last comment 15 November 2016
+ 13   0 7
739

views

+ 13

rating

Caché offers a number of methods for going through a collection and doing something with its elements. The easiest method uses a while-loop and lets you fulfill the task in an imperative manner. The developer needs to take care of the iterator, jumping to the next element and checking if the loop is within the collection.


 But is it really what a developer should be concerned with?! A developer should be working on solving the problem at hand – quickly and producing code of the highest quality. It would be great to be able to just take a collection and apply a function to it that will perform the necessary operations on each element. No need to perform boundary checks, no need to create an iterator, no need to manually call a function for each element. This approach is called declarative programming

Last comment 4 July 2017
+ 13   0 3
1263

views

+ 13

rating

1.About this article

Just like Caché pattern matching, Regular Expressions can be used in Caché to identify patterns in text data – only with a much higher expressive power. This article provides a brief introduction into Regular Expressions and what you can do with it in Caché. The information provided herein is based on various sources, most notably the book “Mastering Regular Expressions” by Jeffrey Friedl and of course the Caché online documentation. The article is not intended to discuss all the possibilities and details of regular expressions. Please refer to the information sources listed in chapter 5 if you would like to learn more. If you prefer to read off-line you can also download the PDF version of this article.

Last comment 11 January 2018
+ 11   1 7
1914

views

+ 11

rating

Introduction

The common requirement in many applications is logging of data changes in a database - which data has changed, who changed them and when (audit logging). There are many articles about this question and there are different approaches on how to do that in Caché.

I'm sharing a mechanism that can help you implement your framework to track and record data changes. This mechanism creates a trigger through an "objectgenarator" method once your persistent class inherits from the "Audit Abstract Class" (Sample.AuditBase). Since your persistent class inherits Sample.AuditBase, when you compile your persistent class the trigger for auditing changes will be generated automatically.


Audit Class  

This is the class where the changes will be recorded

Last comment 5 October 2017
+ 11   0 4
937

views

+ 11

rating

ObjectScript has at least three ways of handling errors (status codes, exceptions, SQLCODE, etc.). Most of the system code uses statuses but exceptions are easier to handle for a number of reasons. Working with legacy code you spend some time translating between the different techniques. I use these snippets a lot for reference. Hopefully they're useful to others as well.

Last comment 29 March 2019
+ 11   7 3
136

views

+ 11

rating

This post is the direct result of working with an InterSystems customer who came to me with the following problem:

SELECT COUNT(*) FROM MyCustomTable

Takes 0.005 seconds, total 2300 rows.  However:

SELECT * FROM MyCustomTable

Took minutes.  The reason for this is subtle and interesting enough for me to write a post about.  This post is lengthy, but if you scroll to the bottom I'll write a quick summary, so if you've gotten this far and think you've already read enough, scroll to the end to get the main point.  Check for the sentence in bold.


There is consideration to take when creating your classes when it comes to storage.  As many of you know, all data in Caché is stored in Globals.  

<Digression> 

If you don't know this then I think this post is going to be a bit much.  I recommend checking out this excellent tutorial in our docs

Last comment 1 November 2016
+ 10   0 11
954

views

+ 10

rating

After many sleepless nights it's a pleasure to announce the newer, better, moderner ObjectScript compiler which implemented pretty much everything you ever wanted to have in modern ObjectScript:

  • Design objective of this new compiler is to parse reasonable subset of current ObjectScript syntax which will look readable for stranger, and not scare them with 1 letter syntax. The good start for compiler was the old-good COS Guidelines from here https://github.com/intersystems-ru/cos-guidelines
  • For reasons we mentioned above we do not parse 1 letter syntax. It's declared evil;
  • We do not handle dotted syntax for the same reason - modern syntax with {} is proper replacement for dotted syntax blocks;

But we not only parse the modern ObjectScript syntax, we have implemented finally the long-standing request which we always dreamed about. Closures!

Last comment 11 days ago
+ 8   3 4
243

views

+ 8

rating

Order is a necessity for everyone, but not everyone understands it in the same way
(Fausto Cercignani)

Disclaimer: This article uses Russian language and Cyrillic alphabet as examples, but is relevant for anyone who uses Caché in a non-English locale.
Please note that this article refers mostly to NLS collations, which are different than SQL collations. SQL collations (such as SQLUPPER, SQLSTRING, EXACT which means no collation, TRUNCATE, etc.) are actual functions that are explicitly applied to some values, and whose results are sometimes explicitly stored in the global subscripts. When stored in subscripts, these values would naturally follow the NLS collation in effect (“SQL and NLS Collations”).

Last comment 10 June 2016
+ 9   0 0
1554

views

+ 9

rating

Have you ever thought what could be a reason why some development environment (database, language) would eventually become popular? What part of this popularity could be explain as language quality? What by new and idioms approaches introduced by early language adopters? What is due to healthy ecosystem collaboration? What is due to some marketing genius

Last comment 17 January 2017
+ 9   0 1
659

views

+ 9

rating

It is with great pleasure that the CIUSSS de l'Estrie - CHUS is sharing the mocking framework it developed and presented at the InterSystems Summit 2017.  I will update this post with more detailed instructions in the next few weeks but I wanted to share the code and presentation quickly : 

https://gitlab.com/ciussse-drit-srd-public/Mocking-Framework

I hope you'll find this useful for your unit testing. We are using this extensively for the last 2 years and it really works well! The repo is public, feel free to submit enhancements!

Do not forget to enable the %UnitTest in your SMP. Instructions are online at http://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=...

Kind regards

André-Claude Gendron

Last comment 12 October 2017
+ 9   0 7
687

views

+ 9

rating

Hi Community,

This post is to introduce one of my first project in COS, I created when started to learn the language and until today I'm keeping improve it.

The CosFaker(here on Github) is a pure COS library for generating fake data.

cosFaker vs Populate Utils

So why use cosFaker if caché has the populate data utility?

Ok the populate utility has great things, like the SSN Generator for example, but what to do when you have a field with a long description of a product? How to check if that table will list the emails or if that calculated property will count the days of the last user interaction.

For me cosFaker is a populate utils with steroids! You can use together with the Populate, to generate %Stream or long strings, or random Dates.

e.g

Last comment 8 February 2019
+ 8   1 0
539

views

+ 8

rating

In this article I would like to tell you about macros in InterSystems Caché. A macro is a symbolic name that is replaced with a set of instructions during compilation. A macro can “unfold” in various instruction sets each time it is called, depending on the parameters passed to it and activated scenarios. This can be both static code and the result of ObjectScript execution. Let's take a look at how you can use them in your application.

Last comment 24 July 2017
+ 8   0 5
1032

views

+ 8

rating

This article will describe and include an example of how to embed an external PDF file into an HL7 segment, specifically ADT_A01:2.3.1 OBX().  This can be useful when attempting to insert pictures or other external data into an HL7 message.  In this example, the name of the PDF file to be embedded is provided in the incoming HL7 message in OBX(1):ObservationValue field.


The basic stipulations for this example are as follows:

  1. Accept a PDF file
  2. Accept an HL7 message
  3. Using the name of the PDF file, embed the PDF data into the HL7 message
  4. Output the message to file

 

 

Last comment 23 August 2017
+ 8   1 1
3436

views

+ 8

rating

This is a translation of the following article. Thanks @Evgeny Shvarov  for the help in translation.

Let's assume that you wrote a program that shows "Hello World!", for example:

  write "Hello, World!"

The program works and everyone is happy.

With time, however, your program becomes more complex, gets more features and you eventually need to show the same string in different languages. Moreover you don't know the number and names of these languages.

The spoiler below contains a description of how the task of multi-language localization is solved in Caché.

Last comment 20 May 2017
+ 8   0 1
323

views

+ 8

rating

 

Cache tricks

Several years ago, long before Developer Community Portal was launched, I published a series of Caché tricks at one of Czech web sites. In this article, I’m posting translated version of one of them.

Capturing output of someone else’s methods or routines

Suppose you, or someone else created a useful method or routine, that was producing some computation that you’d like to benefit from, but the routine was writing output to process principal device.

You would like to use the data, but you need it not written to a device, but assigned to a variable. And, for any reason, you can’t modify the code. What can you do?

Last comment 26 July 2016
+ 8   0 4
1354

views

+ 8

rating

So I know it's been a while, and I hate to let my adoring fans down... just not enough to actually start writing again.  But the wait is over and I'm back!  Now bask in my beautiful ginger words!

For this series, I am going to look at some common problems we see in the WRC and discuss some common solutions.  Of course, even if you find a solution here, you are always welcome to call in and expression you gratitude, or just hear my voice!

This week's common problem: "My query returns no data."

Now, supposedly you've checked that your query SHOULD return data.  That is, if you do a "SELECT * FROM MyTable" and don't get back any data, I don't expect that your more complicated query with JOINs, a WHERE clause, and a GROUP BY will either.  So, if you've determined that the data lives in your table what else could be going wrong?

 

1) You're in the wrong namespace.

Last comment 16 January 2017
+ 7   0 2
271

views

+ 7

rating

Some weeks ago, I was reading a book by Stephen Hawking and Leonard Mlodinow, The Grand Design. At a certain point, trying to define why do we exist? , why do we use the models we use in physics?, ...those kind of things you know... they pointed at the Game of Life example invented by the mathematician John Coward in 1970... Basically he wanted to show that a system with really basic fundamental laws (Physics) could evolve and "live" to become a more complex system (Chemistry) in which "something" (humans) could work out its own model and complex rules to explain its reality… the rules for this deterministic model that he exposed were so basic that I thought it could be funny to implement them in ObjectScript when I had some spare time... there are others implementations in JavaScript and other languages... but not in ObjectScript... and that had to be corrected!!… so here you are!

Last comment 25 December 2018
+ 7   2 4
289

views

+ 7

rating

Some time ago I got a WRC case transferred where a customer asks for the availability of a raw DEFLATE compression/decompression function built-in Caché.

When we talk about DEFLATE we need to talk about Zlib as well, since Zlib is the de-facto standard free compression/decompression library developed in the mid-90s.

Zlib works on particular DEFLATE compression/decompression algorithm and the idea of encapsulation within a wrapper (gzip, zlib, etc.).
https://en.wikipedia.org/wiki/Zlib


In Caché Object Script (COS) we already have GZIP support available in using /GZIP=1 on file- or tcp-devices or our Streamclasses for use with gzip files.
http://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GOBJ_propstream_gzip

Last comment 31 January 2018
+ 7   0 3
569

views

+ 7

rating

Here's a fun test to see how well you know ObjectScript.

What will each of the following statements output?

write 5 * 10 + 1

write 1 + 5 * 10

write 1 + 0 / 10

write 0 && 0 = 0

write 0 = 0 && 0

write 1 && 1 = 1

write 1 = 1 && 1

write 2 && 2 = 2

write 2 = 2 && 2

write "1 APPLE" + "2 BANANAS"

write "-1" + "1-2"

write +"+-+-+-5"

write "1D7P"-1

write "1E6F"-1

write 0 = "FOO"

write 0 = +"FOO"

write 0 = ''"FOO"

write "10X" - " 5" - "5"

write "10-5"

write +"10-5"

write @"10-5"

write 5_"1"-1

write "5"-1_"1"

write 10 + 10 > 21 + 1

Scroll down to see how many you got right...

   \/

   \/

   \/

   \/

   \/

   \/

   \/

   \/

   \/

   \/

   \/

   \

Last comment 4 December 2018
+ 6   2 8
777

views

+ 6

rating