pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Pg and Perl!!
3+ messages / 3 participants
[nested] [flat]

* Pg and Perl!!
@ 1999-04-28 21:51  Ilhuicatzi Cortes J. Henry <ic94006@solar6.ingenieria.uatx.mx>
  0 siblings, 2 replies; 3+ messages in thread

From: Ilhuicatzi Cortes J. Henry @ 1999-04-28 21:51 UTC (permalink / raw)
  To: pgsql-interfaces


Hi:

   im using Pg to make CGI's beetwen Postgres and perl, where can i find
examples about Pg. I have tried to make any CGI's and doesn't work fine.

  Does someone have any examples about CGI?

Atte.
Henry Ilhuicatzi Cortes
Universidad Autonoma de Tlaxcala
Mexico.
  




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: [INTERFACES] Pg and Perl!!
@ 1999-04-29 05:42  Constantin Teodorescu <teo@flex.ro>
  parent: Ilhuicatzi Cortes J. Henry <ic94006@solar6.ingenieria.uatx.mx>
  1 sibling, 0 replies; 3+ messages in thread

From: Constantin Teodorescu @ 1999-04-29 05:42 UTC (permalink / raw)
  To: Ilhuicatzi Cortes J. Henry <ic94006@solar6.ingenieria.uatx.mx>; pgsql-interfaces

"Ilhuicatzi Cortes J. Henry" wrote:
> 
> Hi:
> 
>    im using Pg to make CGI's beetwen Postgres and perl, where can i find
> examples about Pg. I have tried to make any CGI's and doesn't work fine.
> 
>   Does someone have any examples about CGI?

Sorry , they are in romaniana language !

#!/usr/bin/perl

# Decomentati urmatoarea linie daca lucrati cu Postgres
use Pg;

   $datele = <STDIN>;
   @pairs = split(/&/, $datele);
   foreach $pair (@pairs) {
      ($name, $value) = split(/=/, $pair);
      # restore blank
      $value =~ tr/+/ /;
      # restore special char
      $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
      # store them into associative array %VAR
      chomp $value; $value =~ s/\r//;
      $VAR{$name} = $value ;
   }

#  preluam cimpurile transmise in variabile
   $database   = $VAR{'db'};
   $data       = $VAR{'data'};
   $dolar        = $VAR{'dolar'};
   $oldata=$data;

   ($zi,$luna,$an)=split(/\./,$data);
   if ( $an < 100) { $an += 1900;} $data=$luna.'-'.$zi.'-'.$an;

# Acest rind este obligatoriu pentru inceput de HTML raspuns
print "Content-type:text/html\n\n";

print <<EOM;
<HTML>
<HEAD>
<TITLE>Adaugare curs dolar</TITLE>
</HEAD>
<BODY>
<H1>Curs dolar</H1>

<br>
S-a solicitat actualizarea cursului dolarului
pentru data de <b>$oldata</b> la valoarea de <b>$dolar
Lei/USD</b><br><br>
EOM

$con=PQsetdb('',5432,'','',$database);

$res=PQexec($con,"select * from valuta where data='$data'");
$errmsg=PQerrorMessage($con);
if($errmsg ne '') {
   print "EROARE : ",$errmsg;
   print "</body></html>\n";
   PQclear($res);
   PQfinish($con);
   exit 1;
}
if(PQntuples($res) > 0) {
   print "<B>Informatia valutara pentru data $oldata era introdusa
!!!</b><br>";
   print "Cursul valutar pentru aceasta zi era
",PQgetvalue($res,0,1),"<br>";
   print "Modificam cu noul curs : ",$dolar,"<br><br>\n";
   $sqlcmd="update valuta set dolar=$dolar where data='$data'";
} else {
   $sqlcmd="insert into valuta (data,dolar) values ('$data',$dolar)";
}
PQclear($res);
$res=PQexec($con,$sqlcmd);
$errmsg = PQerrorMessage($con);
if ( $errmsg ne '' ) {
     print '<font color="#FF0000">';
     print "<b>EROARE : ",$errmsg,"</b></font><br>";
     print "SQL=$sqlcmd<br>";
} else {
     print "Baza de date a fost actualizata cu succes.";
}

PQclear($res);
PQfinish($con);         

-- 
Constantin Teodorescu
FLEX Consulting Braila, ROMANIA



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: [INTERFACES] Pg and Perl!!
@ 1999-04-29 10:49  D'Arcy J.M. Cain <darcy@druid.net>
  parent: Ilhuicatzi Cortes J. Henry <ic94006@solar6.ingenieria.uatx.mx>
  1 sibling, 0 replies; 3+ messages in thread

From: "D'Arcy" "J.M." Cain @ 1999-04-29 10:49 UTC (permalink / raw)
  To: ic94006@solar6.ingenieria.uatx.mx; +Cc: pgsql-interfaces

Thus spake Ilhuicatzi Cortes J. Henry
>    im using Pg to make CGI's beetwen Postgres and perl, where can i find
> examples about Pg. I have tried to make any CGI's and doesn't work fine.
> 
>   Does someone have any examples about CGI?

It's Python, not perl but it may give you some ideas.  I have a page of
motorcycle rides at http://www.druid.net/rides/ that I maintain in a
simple PostgreSQL database.  The page has a link at the bottom that
shows the actual Python source that manages the page.

If your pages fail altogether, you may just be missing the first line that
gives the content type.  Note in the source how the first print statement
displays the string "content-type: text/html" followed by one totally blank
line.  Without that your page won't work.

Note, IE users may have to click on the link then view source.  Some
versions of IE mistakenly try to parse the html in the text file that
they get handed.

-- 
D'Arcy J.M. Cain <darcy@{druid|vex}.net>   |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 424 2871     (DoD#0082)    (eNTP)   |  what's for dinner.



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~1999-04-29 10:49 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-04-28 21:51 Pg and Perl!! Ilhuicatzi Cortes J. Henry <ic94006@solar6.ingenieria.uatx.mx>
1999-04-29 05:42 ` Constantin Teodorescu <teo@flex.ro>
1999-04-29 10:49 ` D'Arcy J.M. Cain <darcy@druid.net>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox