PGresult#type (and other postgres questions)


(Gavin Kistner) #1

I’m putting RDoc documents into postgres.c, and I have a few questions
about what various methods do.

PGresult#type( fieldIndex )
What does the number that is returned correspond to?
(Looks like integer/serial is 23, varchar(50) is 1043, smallint is 21
… where is there a lookup of constants for these values?)

PGconn.escape()
PGconn.escape_bytea( … )
What do these two class methods do? (They’re not documented in the
supplied documentation. Neither is PGconn.quote either, but I figured
that one out.)

PGconn#insert_table( table, values )
What is ‘table’? The supplied documentation merely says
Inserts contents of the array into the table.
My guess (from playing around) is that ‘table’ is a String with the name
of the table, and ‘values’ must be an Array of tuples (array of arrays).
Is this correct?

Also, is there any way to use this method to insert values into a table
where one column is of type ‘serial’? You can explicitly shove an
integer in, but doing so does not cause the serial value to
auto-increment…a future call to insert a value in the table which
doesn’t specify a value for the serial column may choose an existing
value, and error.

PGconn#notifies()
What does this method do? (Not in the supplied documentation.)

PGconn#status()
What does this method do? (Not in the supplied documentation.)

PGresult#cmdtuples()
What does this method do? (Not in the supplied documentation.)
res = conn.exec(‘select * from t_lists;’)
puts res.result.length => 5
puts res.cmdtuples => 0

(More to come as a followup, likely :slight_smile:

···


(-, /\ / / //


(Gavin Kistner) #2

Gavin Kistner wrote:

(More to come as a followup, likely :slight_smile:

Also missing:

PGresult#print( file, opt )
What’s this do?

···


(-, /\ / / //


(Martin Hart) #3

I’m putting RDoc documents into postgres.c, and I have a few questions
about what various methods do.

PGconn.escape()
PGconn.escape_bytea( … )
What do these two class methods do? (They’re not documented in the
supplied documentation. Neither is PGconn.quote either, but I figured
that one out.)

Escape the supplied string so that it is valid SQL I believe - e.g. replace '
with either ‘’ or ’ (can’t remember which)

PGconn#notifies()
What does this method do? (Not in the supplied documentation.)

This supplies information about the backend notifies waiting to be processed
(see NOTIFY and LISTEN in postgres documentation)

Sorry for being terse and not answering everything - if nobody else has
replied when I finish for the day, I’ll send through a more detailed response
:slight_smile:

NOTE - the last time I used ruby-postgres (just after pgsql 7.4 release) it
was broken with Postgresql 7.4 in that the listen/notify stuff did not work
properly. It may have been patched since then - I’ll dig through my notes
from the time.

Cheers,
Martin

···

On Tuesday 24 February 2004 22:59, Gavin Kistner wrote:


Martin Hart
Arnclan Limited
53 Union Street
Dunstable, Beds
LU6 1EX
http://www.arnclanit.com


(ts) #4

PGresult#type( fieldIndex )
What does the number that is returned correspond to?

OID

(Looks like integer/serial is 23, varchar(50) is 1043, smallint is 21
.... where is there a lookup of constants for these values?)

select oid, typname from pg_type;

PGconn.escape()

Take a String and escape it

http://www.postgresql.org/docs/7.4/static/libpq-exec.html#LIBPQ-EXEC-ESCAPE-STRING

PGconn.escape_bytea( ... )

same than previous but with binary strings

http://www.postgresql.org/docs/7.4/static/libpq-exec.html#LIBPQ-EXEC-ESCAPE-BYTEA

PGconn#insert_table( table, values )
What is 'table'? The supplied documentation merely says
  Inserts contents of the array into the table.
My guess (from playing around) is that 'table' is a String with the name
of the table, and 'values' must be an Array of tuples (array of arrays).
Is this correct?

yes

PGconn#status()
What does this method do? (Not in the supplied documentation.)

Returns the result status of the command (PQresultStatus)

  http://www.postgresql.org/docs/7.4/static/libpq-exec.html

PGresult#cmdtuples()
What does this method do? (Not in the supplied documentation.)

Returns the number of rows affected by the SQL command. (PQcmdTuples)

http://www.postgresql.org/docs/7.4/static/libpq-exec.html#LIBPQ-EXEC-NONSELECT

Guy Decoux


(ts) #5

PGresult#print( file, opt )
What's this do?

http://www.postgresql.org/docs/7.4/static/libpq-exec.html#LIBPQ-EXEC-SELECT-INFO

PQprint

Prints out all the rows and, optionally, the column names to the specified
output stream.

There is an example in sample/psql.rb

Guy Decoux


(ts) #6

PGconn#status()

   ^^^^^^

What does this method do? (Not in the supplied documentation.)

Returns the result status of the command (PQresultStatus)

Well, this is the status of the connection (PQstatus)

  http://www.postgresql.org/docs/7.4/static/libpq-status.html

Guy Decoux


(Gavin Kistner) #7

ts wrote:
[snip - a great many helpful pieces of missing information]

Guy Decoux

Thanks so much, Guy. See accompanying top-level announcement :slight_smile:

···


(-, /\ / / //