NAME ^

Pg.pir - OO interface to libpq

SYNOPSIS ^

  .local pmc pg, con, res
  pg = getclass 'Pg'
  con = pg.'connectdb'('dbname = db')
  res = con.'exec'('SELECT * from tab')
  n = res.'ntuples'()
  m = res.'nfields'()
  ...
  val = res.'getvalue'(i, j)

ABSTRACT ^

The Pg library provides an OO interface to libpq functions - the C interface to PostgreSQL.

See "Chapter 28. libpq - C Library" for details or the tests in t/library/pg.t.

AUTHOR ^

Leopold "leo" Toetsch <lt(at)toetsch.at>

DESCRIPTION ^

Pg.pir is a thin wrapper around postgres.pir - the NCI functions of the libpq library. It's roughly divided into 3 parts, represented by 'Pg', 'Pg;Conn', and 'Pg;Result' classes.

Connection Construction ^

con = Pg::connectdb('var=val var=val ...')

A class method that returns a new connection object.

Connection Methods ^

__init(con)

Object initializer. Takes a PGconn structure.

c = res.'PGconn'()

Return the raw PGconn structure. You probably don't need this function except for calling PQ* code directly.

$I0 = con.'status'()

Return the connection status.

con.'finish'()

Finish the connection. The connection attribute is set to .undef thereafter and inaccessible then.

res = con.'exec'(str)

Execute the SQL command and return a Pg;Result object.

res = con.'execParams'(str, val, ...)

Execute the SQL command and return a Pg;Result object. All values are considered being text - there's no provision to use binary data.

res = con.'prepare'(name, query, nparams)

Prepare a query for execution with execPrepared

res = con.'execPrepared'(name, val, ...)

Execute a prepared query.

$P0 = con.'setNoticeReceiver'(cb, arg)

Install a notice receiver callback. The callback will be called as

  .sub 'notice'
    .param pmc arg
    .param pmc res

Result Methods ^

__init(res)

Object initializer. Takes a PGresult structure.

__finalize()

Object finalizer. Calls self.'clear'().

r = res.'PGresult'()

Return the raw PGresult structure. You probably don't need this function except for calling PQ* code directly.

$I0 = res.'resultStatus'()

Return the status of the result.

res.'clear'()

Clear the result structure. You don't have to explicitely call this method. If a result object is no longer alive, the GC will call __finalize(), which wil clear the object.

$I0 = res.'ntuples'()

Return the amount of tuples in the result.

$I0 = res.'nfields'()

Return the amount of fields in the result.

$S0 = res.'fname'(c)

Return the name of the c-th field in the result.

$I0 = res.'fnumber'(col_name)

Return the number of the field or -1.

v = res.'getvalue'(r, c)

Return result value from row r and column c.

$I0 = res.'getisnull'(r, c)

Return true if the result value at (r,c) is NULL.


parrot