In: |
postgres.c
|
Parent: | Object |
The class to access PostgreSQL database. All other functionality of libpq save the large object to a file.
For example, to send query to the database on the localhost:
require "postgres" conn = PGconn.connect("localhost", 5432, "", "", "test1") res = conn.exec("select * from a;")
See the PGresult class for information on working with the results of a query.
Returns a SQL-safe version of the String str. Unlike quote, does not wrap the String in ’…’.
For more information, see PQescapestring which is called internally by this method.
Escapes binary data for use within an SQL command with the type bytea.
Certain byte values must be escaped (but all byte values may be escaped) when used as part of a bytea literal in an SQL statement. In general, to escape a byte, it is converted into the three digit octal number equal to the octet value, and preceded by two backslashes. The single quote (’) and backslash (\) characters have special alternative escape sequences. escape_bytea performs this operation, escaping only the minimally required bytes.
For more information, see PQescapeBytea which is called internally by this method.
pghost: | server hostname (String) |
pgport: | server port number (Integer) |
pgoptions: | backend options (String) |
pgtty: | tty to print backend debug message (ignored in newer versions of PostgreSQL) (String) |
dbname: | connecting database name (String) |
login: | login user name (String) |
passwd: | login password (String) |
On failure, it raises a PGError exception.
If obj is a Number, String, Array, nil, true, or false then quote returns a String representation of that object safe for use in PostgreSQL.
If obj is not one of the above classes and a block is supplied to quote, the block is invoked, passing along the object. The return value from the block is returned as a string.
If obj is not one of the recognized classes and no block is supplied, a PGError is raised.
Sends an asynchronous SQL query request specified by sql to the PostgreSQL. Returns an Array as the resulting tuple on success. On failure, it returns nil, and the error details can be obtained by error.
Reads a line from the backend server into internal buffer. Returns nil for EOF, +0+ for success, +1+ for buffer overflowed. You need to ensure single "." from backend to confirm transmission completion. The sample program psql.rb (see source for postgres) treats this copy protocol right.
Returns the next notification from a list of unhandled notification messages received from the server. It returns a null pointer if there are no pending notifications. Once a notification is returned from PQnotifies, it is considered handled and will be removed from the list of notifications.
For more information, see PQnotifies which is called internally by this method.
Sends the string to the backend server. Users must send a single "." to denote the end of data transmission.
Sends SQL query request specified by sql to the PostgreSQL. Returns an Array as the resulting tuple on success. On failure, it returns nil, and the error details can be obtained by error.
Returns the status of the connection. May be either:
For more information, see PQstatus which is called internally by this method.