Postgress database Test...

Windows specific questions.
geminis4941
Posts: 59
Joined: Jul 15, 2009 12:41

Postgress database Test...

Postby geminis4941 » Dec 20, 2017 20:42

I tested the postgres database sample that comes with Frebasic 1.0.5 in WINDOWS and found that:

1.- There is no sample about how insert,modify and delete records.
2.- The database is UTF-8 encoding but the sample seems retrieve ASCII data.

Anyone knows how solve this questions?

*The lib DLLS are downladed from last version of postgres and added to system path.
*The include files where in the inc/postgresql.

Code: Select all

''
'' PostgreSQL (www.postgresql.org) example, translated from C by dr0p (dr0p[-at-]perfectbg.com)
''

#include "postgresql/libpq-fe.bi"

'' main
    dim as string conninfo
    dim as PGconn ptr conn
    dim as PGresult ptr res
    dim as integer nFields, i, j
   
   conninfo = "host=xxx dbname=xxxxx user=xxxx password=xxxx encoding=auto"
   
    conn = PQconnectdb(conninfo)
   
    if (PQstatus(conn) <> CONNECTION_OK) then
        print "Connection to database failed: "; *PQerrorMessage(conn)
        PQfinish(conn)
       end 1
    end if
   
   
    res = PQexec(conn, "SELECT * FROM schema.table")
    ? PQresultStatus(res)
    if (PQresultStatus(res) <> PGRES_TUPLES_OK) then
        print "Command failed: "; *PQerrorMessage(conn)
        PQclear(res)
        PQfinish(conn)
        end 1
   end if
   
   nFields = PQnfields(res)-1
   for i = 0 to nFields
      print *PQfname(res, i),
   next
   print
   print
   
   for i = 0 to PQntuples(res)-1
      for j = 0 to nFields
         print *PQgetvalue(res, i, j),
      next
      print
   next
   
    PQclear(res)
   
    PQfinish(conn)
   end 0

Imortis
Posts: 1568
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: Postgress database Test...

Postby Imortis » Dec 20, 2017 21:15

geminis4941 wrote:I tested the postgres database sample that comes with Frebasic 1.0.5 in WINDOWS and found that:

1.- There is no sample about how insert,modify and delete records.
2.- The database is UTF-8 encoding but the sample seems retrieve ASCII data.

Anyone knows how solve this questions?

*The lib DLLS are downladed from last version of postgres and added to system path.
*The include files where in the inc/postgresql.

Code: Select all

''
'' PostgreSQL (www.postgresql.org) example, translated from C by dr0p (dr0p[-at-]perfectbg.com)
''

#include "postgresql/libpq-fe.bi"

'' main
    dim as string conninfo
    dim as PGconn ptr conn
    dim as PGresult ptr res
    dim as integer nFields, i, j
   
   conninfo = "host=xxx dbname=xxxxx user=xxxx password=xxxx encoding=auto"
   
    conn = PQconnectdb(conninfo)
   
    if (PQstatus(conn) <> CONNECTION_OK) then
        print "Connection to database failed: "; *PQerrorMessage(conn)
        PQfinish(conn)
       end 1
    end if
   
   
    res = PQexec(conn, "SELECT * FROM schema.table")
    ? PQresultStatus(res)
    if (PQresultStatus(res) <> PGRES_TUPLES_OK) then
        print "Command failed: "; *PQerrorMessage(conn)
        PQclear(res)
        PQfinish(conn)
        end 1
   end if
   
   nFields = PQnfields(res)-1
   for i = 0 to nFields
      print *PQfname(res, i),
   next
   print
   print
   
   for i = 0 to PQntuples(res)-1
      for j = 0 to nFields
         print *PQgetvalue(res, i, j),
      next
      print
   next
   
    PQclear(res)
   
    PQfinish(conn)
   end 0



I am going to guess that this line:

Code: Select all

res = PQexec(conn, "SELECT * FROM schema.table")


Could be altered to do any SQL statement that postgress supports. That would include INSERT, UPDATE, DROP, etc.
geminis4941
Posts: 59
Joined: Jul 15, 2009 12:41

Re: Postgress database Test...

Postby geminis4941 » Jan 03, 2018 11:23

Imortis , you are right, you can do all that with PQexec, thanks. I was thinking if there is another form of do it ( like msaccess recordsets) , or if someone has used transactions. The encoding theme will be a mistery in the time.

Return to “Windows”

Who is online

Users browsing this forum: No registered users and 1 guest