Previous Next Table of Contents

3. SQLkit_PG functions.

3.1 open_pg()

Connect to a PostgreSQL database. This function must be called before any other SQLkit_PG function.

PARAMETERS     : one required, the name of the database.

RETURN VALUE   : integer : zero means success,  negative  
                 one (-1) indicates an error. Tail PG_ERROR_LOG
                 for the specific error message.

EXAMPLE  :   

LOCAL nRetVal := open_pg( "abc" )

3.2 close_pg()

Disconnect from a PostgreSQL database.

PARAMETERS     : none.

RETURN VALUE   : integer : zero means success,  negative  
                 one (-1) indicates an error. Tail PG_ERROR_LOG
                 for the specific error message.
EXAMPLE  :   

LOCAL nRetVal := close_pg()

3.3 begin_pg()

Begin a transaction block.

PARAMETERS     : none.

RETURN VALUE   : integer : zero means success,  negative  
                 one (-1) indicates an error. Tail PG_ERROR_LOG
                 for the specific error message.

EXAMPLE  :   
LOCAL nRetVal = begin_pg()

3.4 end_pg()

Commit a transaction block started by begin_pg().

PARAMETERS     : none.

RETURN VALUE   : integer : zero means success,  negative  
                 one (-1) indicates an error. Tail PG_ERROR_LOG
                 for the specific error message.

EXAMPLE  :   

LOCAL nRetVal := end_pg()

3.5 rback_pg()

Abort or ROLLBACK a transaction block started by begin_pg().

PARAMETERS     : none.

RETURN VALUE   : integer : zero means success,  negative  
                 one (-1) indicates an error. Tail PG_ERROR_LOG
                 for the specific error message.

EXAMPLE  :   

LOCAL nRetVal := rback_pg()

3.6 ret_pg()

Retrieve (select) records from a PostgreSQL database.

PARAMETERS     :  three required.

   cSelect     :  SQL select statement

   @tfilename  :  a pointer to a variable that will contain the
                  temporary file name where the retrieved records
                  are stored.

   @fieldcount :  a pointer to a variable that will contain the
                  number of fields making up each retrieved record.

RETURN VALUE   :  A positive integer or zero indicating the number
                  of records retrieved; or a negative one (-1) 
                  indicating an error. Tail PG_ERROR_LOG for the
                  specific error message. 
                  If zero or -1 is returned, no temporary file is 
                  created.
EXAMPLE  :  

LOCAL cSelect := "select * from part order by part_no" 
LOCAL tfilename := "" 
LOCAL fieldcount := 0 
LOCAL nRowCount := sql_ret(cSelect, @tfilename, @fieldcount) 

This will retrieve into a temporary file all records in the part table in ascending order of their part number. Please note that parameters two and three are pointers and must have ``@'' in front of them. Their values are available after ret_pg() returns.

3.7 exec_pg()

Execute a non-select SQL statement.

PARAMETER   : one required.

  cStatement   : SQL statement

RETURN VALUE   : integer : zero means success,  negative  
                 one (-1) indicates an error. Tail PG_ERROR_LOG
                 for the specific error message.

EXAMPLE  :   

LOCAL cStatement := "update part set name = 'radiator' where part_no = 1034"
LOCAL nRetVal := exec_pg( cStatement )
In a multi-user environment you may find it necessary to start a transaction block with begin_pg() before issuing any SQL statements with exec_pg() that change the contents of the database.


Previous Next Table of Contents