8000 Add some documentation to PG::Result#fnumber (fixes #139) · danielcode/ruby-pg@a79be36 · GitHub
[go: up one dir, main page]

Skip to content

Commit a79be36

Browse files
committed
Add some documentation to PG::Result#fnumber (fixes #139)
1 parent 1bf286d commit a79be36

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

ext/pg_result.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,24 @@ pgresult_fname(VALUE self, VALUE index)
331331
* call-seq:
332332
* res.fnumber( name ) -> Fixnum
333333
*
334-
* Returns the index of the field specified by the string _name_.
334+
* Returns the index of the field specified by the string +name+.
335+
* The given +name+ is treated like an identifier in an SQL command, that is,
336+
* it is downcased unless double-quoted. For example, given a query result
337+
* generated from the SQL command:
335338
*
336-
* Raises an ArgumentError if the specified _name_ isn't one of the field names;
337-
* raises a TypeError if _name_ is not a String.
339+
* result = conn.exec( %{SELECT 1 AS FOO, 2 AS "BAR"} )
340+
*
341+
* we would have the results:
342+
*
343+
* result.fname( 0 ) # => "foo"
344+
* result.fname( 1 ) # => "BAR"
345+
* result.fnumber( "FOO" ) # => 0
346+
* result.fnumber( "foo" ) # => 0
347+
* result.fnumber( "BAR" ) # => ArgumentError
348+
* result.fnumber( %{"BAR"} ) # => 1
349+
*
350+
* Raises an ArgumentError if the specified +name+ isn't one of the field names;
351+
* raises a TypeError if +name+ is not a String.
338352
*/
339353
static VALUE
340354
pgresult_fnumber(VALUE self, VALUE name)

0 commit comments

Comments
 (0)
0