Next: , Previous: , Up: PostgreSQL Support   [Contents][Index]

61.2 SXEmacs PostgreSQL libpq API

The SXEmacs PostgreSQL API is intended to be a policy-free, low-level binding to libpq. That is to provide all the basic functionality and then let high level Lisp code decide its own policies.

This documentation assumes that the reader has knowledge of SQL, but requires no prior knowledge of libpq.

There are many examples in this manual and some setup will be required. In order to run most of the following examples, the following code needs to be executed. The first example establishes a database connection and then creates a table ‘sxemacs_codenames’ in your default database.

It may happen for you that this code fails. The code heavily depends on your settings in pg_hba.conf (host-based access controls). On the other hand, nearly all of the examples during this documentation will assume that the free variable P refers to the database connection.

;; establish a connection to ‘$PGDATABASE’ as ‘$PGUSER
;; on ‘$PGHOST’ at port ‘$PGPORT
(setq P (pq-connectdb ""))
  ⇒ #<PGconn kantdb:5432 freundt/freundt>
;; establish a connection to a password-protected db
(setq P (pq-connectdb "password=foo234bar"))
  ⇒ #<PGconn kantdb:5432 freundt/freundt>
;; now create a test table
(pq-exec P (concat "CREATE TABLE sxemacs_codenames"
                   " (id int, version text, codename text);"))

Now we transfer following data to the table created.

  (pq-exec P "COPY sxemacs_codenames FROM stdin;")
  (pq-put-line P "1\t22.1.0\tAlfa Romeo\n")
  (pq-put-line P "2\t22.1.1\tAston Martin\n")
  (pq-put-line P "3\t22.1.2\tAudi\n")
  (pq-put-line P "4\t22.1.3\tBMW\n")
  (pq-put-line P "5\t22.1.4\tBentley Turbo\n")
  (pq-put-line P "\\.\n")
  (pq-end-copy P))
     ⇒ nil

Next: , Previous: , Up: PostgreSQL Support   [Contents][Index]