[Phplib-trackers] [ phplib-Bugs-561963 ] PG_SQL will not give accurate sizes
Brought to you by:
nhruby,
richardarcher
|
From: <no...@so...> - 2002-05-29 16:32:27
|
Bugs item #561963, was opened at 2002-05-29 09:32 You can respond by visiting: http://sourceforge.net/tracker/?func=detail&atid=403611&aid=561963&group_id=31885 Category: DB_SQL Group: 7.4pre1 Status: Open Resolution: None Priority: 5 Submitted By: Nobody/Anonymous (nobody) Assigned to: Nobody/Anonymous (nobody) Summary: PG_SQL will not give accurate sizes Initial Comment: I have found that the libraray will not give accurate results when the php functions are used to determine the size of varchar fields. This makes for some problems. For example on a form it is possible to have a -1 maxlength on a text input. I have developed a workaround that seems to address all the variable types except to text and blobs. Below is the code I found. I have commented out the old code that was there and added the new. This is a bit slower then the php functions but it works right. The query was initally found in the phpPgAdmin program. function metadata($table) { $count = 0; $id = 0; $res = array(); $row = array(); $this->connect(); // $id = pg_exec($this->Link_ID, "select * from $table"); // if ($id < 0) { // $this->Error = pg_ErrorMessage($id); // $this->Errno = 1; // $this->halt("Metadata query failed."); // } // $count = pg_NumFields($id); // $id = pg_exec($this->Link_ID, "select * from $table"); // for ($i=0; $i<$count; $i++) { // $res[$i]["table"] = $table; // $res[$i]["name"] = pg_FieldName ($id, $i); // $res[$i]["type"] = pg_FieldType ($id, $i); // $res[$i]["len"] = pg_FieldSize ($id, $i); // $res[$i]["flags"] = ""; // } // Additional code to get rid of the -1 errors. // include ("array_dump.inc"); $query = sprintf (" select a.attnum,a.attname as field, t.typname as type, case when a.attlen='-1' then a.atttypmod else a.attlen end as length, a.attnotnull as notnul from pg_class c, pg_attribute a, pg_type t where c.relname='%s' and a.attnum > 0 and a.attrelid = c.oid and a.atttypid = t.oid order by a.attnum; ",$table); $res_fields = @pg_exec($this->Link_ID, $query); for ($i=0; $row= @pg_fetch_array ($res_fields,$i); $i++) { $res[$i]["table"] = $table; $res[$i]["name"] = $row["field"]; $res[$i]["len"] = $row["length"]; $res[$i]["type"] = $row["type"]; $res[$i]["flags"] = ""; // array_dump ($row); } pg_FreeResult($res_fields); // pg_FreeResult($id); return $res; } ---------------------------------------------------------------------- You can respond by visiting: http://sourceforge.net/tracker/?func=detail&atid=403611&aid=561963&group_id=31885 |