php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28089 pg_field_size always returns -1 instead of actual field size
Submitted: 2004-04-21 12:17 UTC Modified: 2004-04-22 08:20 UTC
From: tony at gigaday dot com Assigned:
Status: Not a bug Package: PostgreSQL related
PHP Version: 4.3.4 OS: Gentoo Linux
Private report: No CVE-ID: None
 [2004-04-21 12:17 UTC] tony at gigaday dot com
Description:
------------
                                                                                                     I am unable to get pg_field_size to return the correct storage size of a field; I have pg_field_num and pg_field_type working but not pg_field_size.

Reproduce code:
---------------
<?php
//  get fields sizes for currency file $dbconn_str = "host=localhost port=5432 dbname=pacs user=YYY password=XXXX";
if ( $dbconn = pg_connect($dbconn_str) ) {
  if ( !$db_status = pg_connection_status($dbconn) ) {
    $res = pg_query($dbconn, "select * from ccy limit 1");     $ccy_code_fnr = pg_field_num($res, "ccy_code");
    $ccy_code_type = pg_field_type($res, $ccy_code_fnr);
    $ccy_code_size = pg_field_size($res, $ccy_code_fnr);
    echo "res:", $res, " code:", $ccy_code_fnr, " type:", $ccy_code_type, " size:", $ccy_code_size; 
?>

Expected result:
----------------
res:Resource id #3 code:0 type:bpchar size:-1

Actual result:
--------------
res:Resource id #3 code:0 type:bpchar size:6

since psql gives:-

pacs=# \d ccy
            Table "public.ccy"
    Column     |     Type      | Modifiers
---------------+---------------+-----------
 ccy_code      | character(6)  | not null
 ccy_desc      | character(20) |
 ccy_curr_rate | numeric(12,4) |
 ccy_std_rate  | numeric(12,4) |
 ccy_alt_rate  | numeric(12,4) |
Indexes: ccy_pkey primary key btree (ccy_code)
 
pacs=#


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-04-21 12:23 UTC] tony at gigaday dot com
Sorry, I got the actual and expect results in the wrong boxes in the bug report.  :(

The incorrect value of -1 is the actual returned value.
 [2004-04-22 01:52 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

PQfsize returns  the  size  in  bytes of the field 
associated with the given field index. If the  size 
returned  is  -1,  the  field  is a variable length 
field.  
The PQfsize() is the underlying function behind  
pg_field_size(). 
 [2004-04-22 08:20 UTC] tony at gigaday dot com
Thanks for getting back.

Maybe I am doing something wrong, in which case I am sorry to waste your time, but I still think that this is a bug.

I am aware that a return of -1 indicates a variable length field, but none of the fields is variable length and I just gave  the field ccy_code (fixed length) as an example.  None of the fields is variable length but they all return -1.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jun 19 13:01:31 2024 UTC