Is it possible to run SQL external commands?

Hi to All,

could Someone respond to this problem?

We are using servoy successfully.

But, on Linux, we made some sql commands, and we run it from shell with ./commad_name.

We’d like to make a form on Servoy in wich to put one label button for each sql command in shell; and start the command with event onAction.
We’d like also to see the output of sql command on Servoy.

Is it possible?

If yes, how?

Many Tanks in advance.

Gianni Pinna

Hi Gianni,

I have 2 questions:

  1. How would you execute the SQL? I.e. with what command.
  2. And what will the SQL return? And where, in a file or as a result of the command in stdout?

Hi, very dear ROCLASI,

tank You very much for Your prompt replay.

1.) I execute the sql with a shell command of name “cm1”.
cm1 is the name of a file with execution permission; it contains a command like this:

psql -U postgres --file /name_of_the file_which_contains_the_SQL_QUERY

When, in Unix shell I type cm1, as output I see the result of the_SQL_QUERY.
As You teach if I want to havo the output in a file, I can type:

cm1 >file
  1. The SQl return the output of the_SQL_QUERY.
    As I told the SQL returns the output or in shell; or if I redirect in >file, in a file.

Tank You very much, ROCLASI.
Gianni Pinna

Hi Gianni,

It seems psql doesn’t return the result in a way that Servoy’s application.executeProgram() function can fetch.
So I suggest you let the output be redirected into a file and then use the File or UserManager plugin to read that file in.

Hope this helps

Hi Robert,
tank You for Your kind promptness.

1.)

It seems psql doesn't return the result in a way that Servoy's application.executeProgram() function can fetch.

What is, Robert, a way in wich Servoy’s application.executeProgram() function can fetch the psql return?

Please let You know, Robert, that I execute the SQL command from Unix server, in a dir that I choose. But I can decide to put the command in everywhere.

2.) ```
So I suggest you let the output be redirected into a file and then use the File or UserManager plugin to read that file in.


Yes I can redirect the output in a file and then use the File or UserManager plugin to read that file in. But my end was to start the com1 form servoy, and so i am not able.

Tank You , Robert.

Gianni Pinna

Hi Gianni,

You execute the script like so:

var _sResultFile = "myResultFile";

// execute the script that puts it's output to a file
application.executeProgram("/path/to/cm1 > " + _sResultFile);

// Now we can read the result file in using the File plugin or the UserManager plugin
.. your code to read the file

Hope this helps

Hi Robert,

it is a pleasure to be instructed from You.

But now suppose that I am working on a terminal with OS Windows 192.168.1.107; and from this terminal I need to send /home/servoy/cm1 on server with OS Linux 192.168.1.11 .

Is it possible?
If yes, whath is the correct sintax of:

application.executeProgram("/path/to/cm1 > " + _sResultFile);

Tanks again and in advance, Kind Robert

Gianni Pinna

Hi Gianni,

If you want a cross-platform solution you can let psql handle the output for you like so:

psql -U postgres -f /name_of_the file_which_contains_the_SQL_QUERY -o /path/to/outputfile

You could even call that straight from Servoy instead of the script.

Hope this helps.

Hi Robert,
I excuse for the delay of my answer: I was in Rome from Sardegna and it was not possible for me.
Tank You very much, Robert for Your perfect work. It is luminous in every time.

Have You a good sunday, Robert.

Gianni Pinna