The functions listed bellow are for accessing PostgreSQL database.
Function | Parameter Type | Remark |
pgsql([params]) | string | Creates a PosqgreSQL client object. It also tries to connect to a server if the optional parameter is provided. |
.version() | Returns version number as integer. | |
.connect(params) | string | Connects to a database server and reports error if failed. The params string may contain any of the following parameters in any order in the form of key=value separated by space character(s): host=host_name, hostaddr=host_IP, port=port_number, dbname=database_name, user=user_name, password=passsword, and connect_timeout=seconds. Refer to the PostgreSQL reference for more details. |
.query(sql) | string | Performs SQL query. Returns an array containing the number of rows the number of columns in the result if successful; otherwise, returns an error string. |
.fetch(irow) | integer | Returns the record of ith row as string or array depending on whether a record has one or more items. It returns null when all records are fetched. |
.data(ptr, n) | user, integer | Fetches all query results, converts them to double floating numbers, and put them into the doubel array ptr of size n. Returns the number of data converted. |
.print() | Display query result. | |
.escape(s) | string | Create a legal SQL that can be used in an SQL statement. |
.escape(ptr, n) | user, integer | Create a legal SQL string that can be used in an SQL statement. The ptr object must a pointer to binary data of n-bytes. |
.unescape(s) | string | Unescape string to binary data. It returns array containing a pointer to the binary data and the number of byte. |
.reset() | Tries to re-connect to the server. |
load("pgysql.dll"); sql = pgsql("hostaddr=127.0.0.1 user=uname password=psw dbname=mydb"); ret = sql.query("SELECT * FROM mytable"); if (isstring(ret)) error(ret); sql.print();