Is it possible to run SQL external commands?

Questions and answers regarding general SQL and backend databases

Is it possible to run SQL external commands?

Postby cuoredisardegna » Wed Mar 12, 2014 8:48 pm

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
cuoredisardegna
 
Posts: 68
Joined: Mon May 07, 2012 5:34 am

Re: Is it possible to run SQL external commands?

Postby ROCLASI » Wed Mar 12, 2014 9:00 pm

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?
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: Is it possible to run SQL external commands?

Postby cuoredisardegna » Thu Mar 13, 2014 1:29 pm

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:

Code: Select all
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:

Code: Select all
cm1 >file



2. 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
cuoredisardegna
 
Posts: 68
Joined: Mon May 07, 2012 5:34 am

Re: Is it possible to run SQL external commands?

Postby ROCLASI » Thu Mar 13, 2014 3:46 pm

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
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: Is it possible to run SQL external commands?

Postby cuoredisardegna » Thu Mar 13, 2014 5:46 pm

Hi Robert,
tank You for Your kind promptness.

1.)
Code: Select all
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.)
Code: Select all
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
cuoredisardegna
 
Posts: 68
Joined: Mon May 07, 2012 5:34 am

Re: Is it possible to run SQL external commands?

Postby ROCLASI » Thu Mar 13, 2014 6:53 pm

Hi Gianni,

You execute the script like so:
Code: Select all
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
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: Is it possible to run SQL external commands?

Postby cuoredisardegna » Thu Mar 13, 2014 11:13 pm

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
cuoredisardegna
 
Posts: 68
Joined: Mon May 07, 2012 5:34 am

Re: Is it possible to run SQL external commands?

Postby ROCLASI » Fri Mar 14, 2014 12:19 am

Hi Gianni,

If you want a cross-platform solution you can let psql handle the output for you like so:
Code: Select all
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.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: Is it possible to run SQL external commands?

Postby cuoredisardegna » Sun Mar 16, 2014 10:02 am

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
cuoredisardegna
 
Posts: 68
Joined: Mon May 07, 2012 5:34 am


Return to SQL Databases

Who is online

Users browsing this forum: No registered users and 6 guests

cron