postgresql c++

From: <ing_enriquebarrios(at)argentina(dot)com>
To: pgsql-es-ayuda(at)postgresql(dot)org
Cc: pedromateoa(at)gmail(dot)com
Subject: postgresql c++
Date: 2006-11-30 15:01:37
Message-ID: 20061130150634.B4D356445F1@ns-2.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

<html>

<P>con este script te podes conectar, esto es básico, vos le agregas el nivel de complejidad que necesitas.</P>
<P>saludos</P>
<P><BR>
#include &lt;stdio.h&gt;<BR>
#include &lt;libpq-fe.h&gt;<BR>
#include &lt;iostream&gt;<BR>
#include &lt;fstream&gt;</P>
<P>static void<BR>
salir(PGconn *psql)<BR>
{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PQfinish(psql);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1);<BR>
}</P>
<P>int<BR>
main()<BR>
{</P>
<P>PGconn *psql;<BR>
PGresult *result;</P>
<P>int&nbsp; nFields;<BR>
int&nbsp; i,j;</P>
<P><BR>
psql = PQconnectdb("hostaddr = '10.20.182.13' port = '5432' dbname = 'apl_calden2' user = 'postgres' password = 'manager' conn<BR>
ect_timeout = '10'");<BR>
</P>
<P>if (PQstatus(psql) != CONNECTION_OK)<BR>
{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fprintf(stderr, "libpq error: PQstatus(psql) != CONNECTION_OK\n\n");<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; salir(psql);<BR>
}</P>
<P>result = PQexec(psql,"select * from empresa;");</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nFields = PQnfields(result);</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (nFields != 0){<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i = 0; i &lt; nFields; i++)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("%-15s", PQfname(result, i));<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("\n\n");</P>
<P><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i = 0; i &lt; PQntuples(result); i++)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (j = 0; j &lt; nFields; j++)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("%-15s", PQgetvalue(result, i, j));<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("\n");<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PQclear(result);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</P>
<P>salir(psql);</P>
<P><BR>
}</P>
</html><BR><br><addr>------------------------------------------------------------------------<br>
<b><a href=http://free.internet.argentina.com/>Conectate a Internet Gratis de Argentina.Com</a></b><br>
</addr>
<br>
<center>
<a href=http://srvads.argentina.com/bs/adclick.php?n=a84973ad target=_blank>
<img src=http://srvads.argentina.com/bs/adview.php?what=zone:8&n=a84973ad border=0 alt=""></a>
</center>

Attachment Content-Type Size
unknown_filename text/html 2.6 KB

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message felix gonzales 2006-11-30 16:18:38 almacenar imagenes y videos
Previous Message Pedro Mateo 2006-11-30 14:32:27 Re: postgres c++