Informix

 View Only

 dbaccess from Perl won't unload data until I close database

Jump to  Best Answer
Jacob Salomon's profile image
Jacob Salomon posted Fri May 02, 2025 02:12 PM

Greetings Family.

This is for Perl folks only.  Opening a file descriptor on a dbaccess command.

For whatever reason, I am using "| dbaccess <database@server>" as a file descriptor in Perl.  (That's a pipe character preceding the dbaccess command.) I open a $db_fd on that command and issue commands to dbaccess with:

print $db_fd "<The SQL query>"

The first command I send to it is to unload a query to a file. Problem, detected only via the Perl debugger. is that:

  • The .unl file is not created
  • and Data is not unloaded

until I close the file descriptor.  Great motivation to move things along for installing DBI and DBD::Informix; my current scheme is a klutzy workaround because a user awaits a result.

Has anyone else run into this quirk?  Of course, the way I am diddling the data is to with multiple load and unload commands and then capturing the .unl file into a hash. Quite the gluteal pain!  My workaround it to close the file descriptor after the one unload (or load) command to push the command into executing.

Ideas?  or just bite the bullet until I can push the issue through about DBI and DBD modules?

Thanks, all.

-- Jacob S

Andreas Seifert's profile image
Andreas Seifert  Best Answer

Hello Jacob,

I don't know perl, but in C I would say the print buffer has to be flushed. In perl there also seems to be a flush $db_fd->flush(). Closing the file descriptor actually does exactly that.

You can also switch on the automatic flushing of the print buffer with ->autoflush(1|0).

I hope it works the same way in perl.

Best regards

Andreas

Art Kagel's profile image
Art Kagel IBM Champion

Jacob:

I have not tried to do it this way, but have one "dumb thing" to get out of the way: 

Does the <SQL query> have the trailing semi-colon.

and one suggestion:

Try opening the pipe with:

"| dbaccess <database@server> - "  

Note the trailing dash which puts dbaccess into command line mode that might force it to process each command individually rather than waiting for EOF. You are currently running it in menu mode which can take a script as input so maybe it's just waiting for the end of the script to process?

Art

Marcus Haarmann's profile image
Marcus Haarmann IBM Champion

Hi Jacob,

I would recommend using DBD::Informix instead, more elegant of course.

Not sure why you need the pipe if you are producing an unload to a file. (if you need just the exit code, a system call would be sufficient from my perspective.)
Redirect output of the system call if you want to examine any error from the output.

Something like
system ("(echo \"unload to '/tmp/test.unl' delimiter ... select ....\" | dbaccess ${DB}) 2>&1 > /tmp/xxxx.out").

if ( $? -eq 0) {

    .... exit code was 0, do something with the unl

}

If I remember right, a trailing | will allow you to read the output in perl.

open (DB, "echo \"select ...\" | dbaccess ${DBNAME} |");

while <DB> ....

close (DB);

Best,

Marcus

Jacob Salomon's profile image
Jacob Salomon
  1. Art, yes I do have the trailing dash.  I just forgot to put it in the sample code.  When You have to edit your post so s to keep database names confidential, it's easy to forget a detail like that.
  2. Marcus,  If I had DBD::Informix installed, would I be going through these contortions?  We are working on it.  This machine didn't even have C language, let alone esql until late yesterday!

We should have these DBD and DBI modules installed by next week.  Thanks for the suggestions. I can see how Art would have seen the lack of the trailing dash as the cause of the trouble.

Jacob Salomon's profile image
Jacob Salomon

Andreas,

In the debugger, before I did the print (to send the SQL command to the file descriptor), I did $db_fd->autoflush(1). Ans, sure enough, it happened immediately!

I marked your reply as the best answer!

THANKS extremely!

-- Jacob S