Whitebeam Object Definition

Site Map
 
Home
 
Application Guide
Reference
  Installation
  Configuration
  XML Markup
  JavaScript Classes
  ROM
  Templates
  Environment
  Dev Process
  Tools
  External Links
  Example libraries
Community
Contact Whitebeam
To-Do
Download
Credits
Licence
Whitebeam Users
 
 
 

Whitebeam Object Definition

Method Description

PgsqlConnection.connect()

Attach to a Postgres database server.

See Also

PgsqlConnection
PgsqlConnection.pconnect

Syntax

boolean = PgsqlConnection.connect(connectParams)

Parameters

The 'PgsqlConnection.connect' method takes 1 parameter:

Name Type/Value Range/Length Description
connectParamsstruct PgsqlConnection.connectionDescsee definition Required. This object contains a set of attributes that describe the required connection

Results

The 'PgsqlConnection.connect' method returns boolean:

Type/Value Range/Length Description
boolean   true if the connection is made, otherwise throws an exception

Remarks

Attach to a Postgres server and open a database

Example

The following simple example reads the contents of an arbitrary SQL table called 'TestTable' and outputs all the columns to the output page.

  <rb:script>
    var pgconn = new PgsqlConnection;
    var pgres;
    if (pgconn.connect({dbname:'mydb', user:'me', password:'mydbpwd', host:localhost'})) {
      // Connected to the database - read in the contents of the table.
      pgres = pgconn.exec('SELECT * FROM TestTable');
    }
  </rb:script>
  <!-- If there are any results then output the table. -->
  <rb:if expr="pgres!=null && pgres.success && pgres.numRows>0">
    <table>
    <rb:repeatfor expr="var r=0;r<pgres.numRows && r<20;r++">
      <rb:script>
        // Get this row
        var row = pgres.fetchRowObject(r);
      <rb:script>
      <rb:if expr="r==0">
        <!-- This is the first row so output row titles -->
        <tr>
          <rb:repeatfor expr="var ch in row">
            <td><?= ch ?></td>
          </rb:repeatfor>
        </tr>
      </rb:if>
      <tr>
        <rb:repeatfor expr="var ch in row">
          <td><?= row[ch] ?></td>
        </rb:repeatfor>
      </tr>
    </rb:repeatfor>
  </table>

At the end of a page generation all connections to Postgres openned with this (connect) method are closed. Note that if the same database is openned very frequently this will be slow. See instead the pconnect method for creating persistent database connections.

A separate Postgres tutorial explains how to use the PgsqlConnection object in Whitebeam

Whitebeam release 1.3.36
(loadtime : 10ms)