Professional Web Applications Themes

PGresult#type (and other postgres questions) - Ruby

I'm putting RDoc doents 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 doented in the supplied doentation. Neither is PGconn.quote either, but I figured that one out.) PGconn#insert_table( table, values ) What is 'table'? The supplied doentation merely says Inserts contents of the array into the table. My ...

  1. #1

    Default PGresult#type (and other postgres questions)

    I'm putting RDoc doents 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 doented in the
    supplied doentation. Neither is PGconn.quote either, but I figured
    that one out.)



    PGconn#insert_table( table, values )
    What is 'table'? The supplied doentation 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 doentation.)


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


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


    (More to come as a followup, likely :)
    --
    (-, /\ \/ / /\/
    Gavin Guest

  2. #2

    Default Re: PGresult#type (and other postgres questions)

    Gavin Kistner wrote: 

    Also missing:

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

    --
    (-, /\ \/ / /\/
    Gavin Guest

  3. #3

    Default Re: PGresult#type (and other postgres questions)

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

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

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


    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
    :-)

    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

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




    Martin Guest

  4. #4

    Default Re: PGresult#type (and other postgres questions)

    >>>>> "G" == Gavin Kistner <com> writes:

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

    OID

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

    select oid, typname from pg_type;

    G> PGconn.escape()

    Take a String and escape it

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

    G> 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



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

    yes

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

    Returns the result status of the command (PQresultStatus)

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

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

    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 Guest

  5. #5

    Default Re: PGresult#type (and other postgres questions)

    >>>>> "G" == Gavin Kistner <com> writes:

    G> PGresult#print( file, opt )
    G> 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 Guest

  6. #6

    Default Re: PGresult#type (and other postgres questions)

    >>>>> "t" == ts <inra.fr> writes:

    G> PGconn#status()
    ^^^^^^
    G> What does this method do? (Not in the supplied doentation.)

    t> 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




    ts Guest

  7. #7

    Default Re: PGresult#type (and other postgres questions)

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

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


    --
    (-, /\ \/ / /\/
    Gavin Guest

Similar Threads

  1. PGresult pointer and memory usage
    By Jeff Davis in forum PostgreSQL / PGSQL
    Replies: 2
    Last Post: January 24th, 11:51 PM
  2. php + postgres
    By Miszak in forum PHP Development
    Replies: 0
    Last Post: October 10th, 10:08 AM
  3. [OT] postgres
    By Tom Copeland in forum Ruby
    Replies: 0
    Last Post: August 16th, 05:14 PM
  4. Couple of array/reference type questions
    By Arvin Portlock in forum PERL Miscellaneous
    Replies: 4
    Last Post: July 14th, 09:48 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139