SQL in ejscript

Hello,

Yet another question about scripting in customer service. Is it possible to execute plain sql in ejscript? Like making own select-queries or calling stored procedures?

 

RE: SQL in ejscript

Hi, one way is to use StatLib and StatResult, something like this:

String sqlQuery = "select id,title from ticket where status = 1";

StatLib sl;
StatResult sr;

sl.setSql(sqlQuery);
sl.execute(sr);

while(!sr.eof())
{
  printLine(sr.getField(0) + ": " + sr.getField(1));

  sr.next();
}

Note that this is not anbled in the Online environment.

Hope this helps

Av: Simen Mostuen Iversen 3. jul 2019

RE: SQL in ejscript

You also have a method called "executeSQLQuery(String sql)", but with this you do not get any result back.

This one is not available for Online either. In Online, there is no way to execute sql statements directly against the database.

Important: if you use any of the above for an Onsite installation, be careful if you include any user input at all, so you do not create a sql injection. 

Av: Stian Andre Olsen 3. jul 2019

RE: SQL in ejscript

Thanks both for your answers! Our customer have a Onsite installation so I'll try these out.

Av: Mikko Tillikainen 3. jul 2019