Coding Guidelines

Syndicate content 11 

Hi! We have received a request to create a new rule on CachéQuality to identify when a developer uses double quotes (" ") within any SQL statement.

We have been asked many times about SQL validation rules, and we would like to open a debate to allow everyone discuss what would you like to be checked on a SQL statement.

Current examples are for basic situations:

  • Using SQL.Statement class:

Set stmt = ##CLASS(%SQL.Statement).%New()
Set query = "Select Val1, Val2 FROM Table WHERE Val1=""SomeCondition"""

  • Using embedded SQL

&SQL(SELECT Val1, Val2
                INTO :val1, :val2
                FROM Table
                WHERE Val1="SomeCondition")

Last answer 1 April 2019 Last comment 28 March 2019
0   0 3
148

views

0

rating

I am new to Intersystems Cache, so please bear with me. We are using HealthShare 2013.1. 

I have a routine to compare databases from separate instances where I want to ignore values that begin with %sqlcq. I thought this would be easy with pattern matching operator '?' but it is proving difficult and it seems to be because of the percent character. 

For example:

set x = "%sqlcq.something.value.foo"

#;does not evaluate as true. 
if x?1P1"sqlcq" {write "valid"}

set y="sqlcq.something.value.bar"

if y?1"sqlcq".E {write "valid"}
valid
if x?1"sqlcq".E {write "valid"}

  

If the variable value does not include the leading percent character, then I can successfully match. If it does include the percent character then it fails. 

I did try the following pattern, x?1P.1"sqlcq".E and I thought this was successful, but it ended up ignoring %SYS.FOO

What am I missing with pattern matching here? 

Thank you

Last answer 21 February 2019 Last comment 18 February 2019
0   0 4
97

views

0

rating

Our development server is set up to automatically keep the .INT code of compiled classes and routines, but the live servers are set to not keep the .INT code.

I know how to set the system to keep this code ($SYSTEM.OBJ.SetQualifiers() ?)  but what are the ramifications of keeping this code on the live servers?  Is it just a space issue?  I always thought it was to keep the code more private.

I am just wondering if there's a good reason to keep, or not to keep, the INT code on live servers, since it comes in quite handy at times when needing to debug or even to see certain lines of code that received errors.

Thanks, Laura

Last answer 6 February 2019 Last comment 8 February 2019
0   0 2
224

views

0

rating

We are trying to get a custom header that I have added to a request to Cache, and I have seen the following in another post, however it doesn't work for us:

You can do it as in any CSP page/class. With %request, which is object of class %CSP.Request

And headers available in property CgiEnvs, where every http header appear with a prefix HTTP_

So, you may try this code.

set ipCountry=%request.GetCgiEnv("HTTP_CF_IPCOUNTRY")

I have verified in Charles (a Mac equivalent to the Windows traffic sniffer 'Fiddler' program) that my client sent the following headers in the request to Cache

Last answer 9 November 2018 Last comment 1 December 2018
0   0 4
158

views

0

rating

Hi All,

Actually, I'm developing few restful API's. I want to create a authentication tokens and display it on my login restful API. If I'm using CSP sessionId, how can I validate the session Id's in another or continues restful API's. else, is there any other approach to handle this task. 

My Primary goal is, I have to integrate 2 different front end applications. One is Zen framework another one is web pages from Python. 

If any lead, it would be appreciated. 

Thanks,

Arun Kumar Durairaj. 

0   0 1
0

answers

0

comments

104

views

0

rating

As a developer, usually I'm concerned about how my code health is, and how the other coders code can affect to my own work.  And I'm quite sure most of us feel very similar.

In our company we use a Static Code Analysis tool to analyze code for different languages to ensure we are writing high quality and easily maintainable code by following a few best practices in terms of code structure and content. And the question was: why should be different for Caché ObjectScript language?

Last comment 1 August 2018
+ 6   4 4
538

views

+ 6

rating

Hi all,

I'm wonder what could be the best way convert the sentence "Switch" C# into Cache code.

int caseSwitch = 1;

switch (caseSwitch)
{
    case 1:
    Console.WriteLine("Case 1");
    break;

    case 2:
    Console.WriteLine("Case 2");
    break;

    default:
    Console.WriteLine("Default case");
    break;

}

My first attempt was:

set caseSwith = 1

if (caseSwith = 1)
{
   w "Case 1"
}
else
{ 
  if (caseSwith = 2) 
  { 
    w "Case 2"
  }
  else
  {
      w "Default case"
  }
}  

Maybe, for complex conditions, it should be the best option, however I've used the $SELECT comman

Last answer 3 July 2018 Last comment 20 July 2018
+ 1   1 7
780

views

+ 1

rating

Hi, Community!

Coding guidelines discussion. Consider you have For with one command in the cycle. Here are the options:

One

For i=1:1:1000 set ^Test(i)=""

Two

For i=1:1:1000 {

 set ^Test(i)=""

}

Same for the "If":

if a set b=a

or

if a {

 set b=a

}

Your choice? Or maybe even other options? 

Last comment 27 April 2018
0   1 14
858

views

0

rating

Documentation here lists the kinds of members a class definition may contain. In summary:

  • Parameters
  • Methods
  • Properties
  • Class queries
  • XData blocks
  • Projections
  • (and some that are relevant only for persistent classes):
    • Storage definitions
    • Indices
    • Foreign keys
    • SQL triggers

Later in the same document, a section headed "Class Member Names" contains this warning:

So I'm interested to hear how other DC members handle this.

  1. Do you comply (or at least attempt to comply) with this?
  2. If so, do you use any tools or naming conventions to assist you?
  3. Have you ever encountered "unexpected results" that were caused by a failure to comply?
Last answer 13 February 2018 Last comment 13 February 2018
+ 1   0 5
196

views

+ 1

rating

I am trying to write an application that will take some information on the database make a call to the Google API distance matrix and get the information to use with rest of the application without using the ensemble part of the development is this possible and how can I do my communication with the  API from a cache class thanks in  advance

Last answer 30 January 2018 Last comment 31 January 2018
0   0 4
422

views

0

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
4254

views

+ 18

rating

Hi!

Here is small "How to" again.

Suppose you need to share something with source code. How can we manage it on DC?

Sharing code snippets

1. Add normal post (not Code Package).

2. Paste your code in the post and format it with highlighting as it is described here.

3. If you see that your COS code is highlighted wrong it means that autodetect missed with language. Open the post's HTML ("disable rich-text" button below the Editor) and put class=COS parameter into the code tag.

Example

Last comment 11 June 2016
+ 3   0 1
248

views

+ 3

rating