On Thu, 16 Aug 2001, Curt Russell Crandall wrote:
>Forgot this in the last reply... it's the code I'm using to examine this
>problem. Basically, it provides a text box for you to enter 1 SQL
>statement. If executed successfully, it prints the results otherwise it
>prints the error. Ignore the Javascript, it's not completed, but it's
>meant to display query result (ONLY) in a separate window... doesn't work
>yet, though. Regardless, it's not related to the problem... we see this
>in all our fcgi scripts.
>As stated previously, $ENV{'INFORMIXDIR'} is always correctly
>printed. However, the only time the $DBI::errstr string prints correctly
>is the first time after the Apache server is restarted.
That makes me suspicious that /usr/informix is not the correct value for
INFORMIXDIR -- doubly so since if it was correct and INFORMIXDIR was not
set, then the defaults should kick in and /usr/informix is the default
location for Informix software.
Was the software built on the same machine as it is being deployed on?
Did you use any special build options or environment variables
(DBD_INFORMIX_RELOCATABLE_INFORMIXDIR springs to mind).
It might be useful to rebuild DBD::Informix so that it debugs the
environment. Use 'make UFLAGS=-DDBD_IX_DEBUG_ENVIRONMENT' to rebuild
dbdimp.o (it doesn't affect any other files). This causes DBD::Informix
to print the environment it gets to stderr both before and after the
attempted connection to the database. This code is in the dbdimp.ec,
function dbd_ix_printenv(), called from dbd_ix_db_login(). That way,
you'll get to see what the DBD::Informix code thinks it gets as an
environment. You might want to fettle the formatting so that it has
HTML markup, or so that it writes to a logfile instead of stderr - edit
the code to fix this.
>After the first time, subsequent executions of this script have
>$DBI::errstr displaying only the error codes and indicating in the
>error_log that there was a failure to locate the SQL error message.
>
>#!/usr/bin/perl
>
>use strict;
>use warnings;
>
>use appbase;
>use CGI::Carp qw(fatalsToBrowser);
>use CGI::Fast qw(:standard -no_debug);
>use DBI;
>use Data::Dumper;
>use POSIX qw(tmpnam);
>
>$CGI::POST_MAX = 1000000;
>$CGI::DISABLE_UPLOADS = 1;
>
>my %app = get_appbase(); ### module that extracts env info from flat file
>$ENV{'INFORMIXSERVER'} = $app{'ifxsvr'}; ### either 'test' or 'prod'
>$ENV{'INFORMIXDIR'} = '/usr/informix';
>
>my $dbh = DBI->connect( $app{'dbconn'}, $app{'dbuser'}, $app{'dbpass'} );
>$dbh->{RaiseError} = 0;
>$dbh->{PrintError} = 1;
>$dbh->{AutoCommit} = 0;
>
>my $q = undef;
>while ($q = CGI::Fast->new())
> {
> my $status = '';
>
> my $random_win_name = tmpnam();
> $random_win_name =~ s/\/tmp\///;
>
> if ($q->param('go'))
> {
> $q->print(
> style_hdg(
> {'title' => "SQL Interface to
>$dbh->{Name}"},
> $status,
> show_action($random_win_name),
> show_result()
> )
> );
> }
> else
> {
> $q->print(
> style_hdg(
> {'title' => "SQL Interface to
>$dbh->{Name}"},
> show_action($random_win_name)
> )
> );
> }
> }
>
>##
>## Exit
>##
>END
> {
> $dbh->disconnect();
> undef($dbh);
> }
>
>exit(0);
>
>
>### Subroutines ###
>
>sub show_action
> {
> my $random_win_name = shift;
>
> my $html = <<EOF;
><SCRIPT LANGUAGE=JavaScript>
>function results_win(name)
> {
> var query = document.sql_form.sql.value;
> window.open("", name, "width=500, height=500, status=yes,
>resizable=yes");
> return true;
> }
></SCRIPT>
>EOF
>
> $html .= $q->start_form({-name=>'sql_form'})
> . p( 'Enter SQL: ',
> font({-face => 'monospace'},
> $q->textarea(-name => 'sql',
> -rows => 20,
> -cols => 60)),
> '<br>Number<br>of Results<br>',
> $q->popup_menu(-name => 'num_results',
>
>-value=>['50','100','150','200','300','ALL'],
> -default=>'ALL'),
> ' ',
> $q->submit(-value => 'Submit Query',
> -name => 'go',
> -onSubmit => "return
>results_win($random_win_name);") )
> . $q->end_form
> . '<hr><br>';
>
> return $html;
> }
>
>
>
>sub show_result
> {
> my $html = '';
> my $sql = $q->param('sql');
>
> $dbh->do('set isolation to dirty read');
> if ($DBI::errstr)
> {
> return p(['Set Isolation Level failed: ', $DBI::errstr]);
> }
>
> my $stmt = $dbh->prepare($sql);
> if ($DBI::errstr)
> {
> return p(["INFORMIXDIR: $ENV{'INFORMIXDIR'} Prepare failed: ",
>$DBI::errstr]);
> }
>
> $stmt->execute();
> if ($DBI::errstr)
> {
> return p(['Execute failed: ', $DBI::errstr]);
> }
>
>
> if ($sql =~ /\s*select/i)
> {
> my @rows = @{$stmt->fetchall_arrayref()};
> if ($DBI::errstr)
> {
> return p(['fetchall->arrayref failed:', $DBI::errstr]);
> }
>
> my $cols = $stmt->{NUM_OF_FIELDS};
> my $rows_affected = $stmt->rows();
>
> $html .= <<EOF;
><table border="1" cellpadding="4" cellspacing="0">
><tr><td colspan="$cols" align="left">
>Result: $rows_affected rows found, $cols columns
></td></tr>
>EOF
>
> $html .= Tr(td({-align => 'center'}, ['ROW',
>@{$stmt->{NAME}}]));
>
> my $stop_at = $q->param('num_results');
> if ($stop_at eq 'ALL') { $stop_at = $rows_affected; }
>
> my $count = 1;
> foreach my $row (@rows)
> {
> $html .= Tr(td([$count,@{$row}]));
> if ($count == int($stop_at)) { last; }
> $count++;
> }
>
> $html .= "</table>\n";
> }
> else
> {
> my $rows_affected = $stmt->rows();
>
> $dbh->commit();
> if ($DBI::errstr)
> {
> return p(['Commit failed: ', $DBI::errstr]);
> }
> $html .= p("$rows_affected rows affected");
> }
>
> return $html;
> }
>
>__END__
>
>
--
Yours,
Jonathan Leffler ([EMAIL PROTECTED]) #include <disclaimer.h>
Guardian of DBD::Informix v1.00.PC1 -- http://www.perl.com/CPAN
"I don't suffer from insanity; I enjoy every minute of it!"