From 3936597c23c4336b78e9d8288ad997e4fbf1cf52 Mon Sep 17 00:00:00 2001 From: Domas Mituzas Date: Sat, 11 Sep 2004 14:08:52 +0000 Subject: [PATCH] commit in resource efficient textFieldSize() (uses PG internal schema) --- includes/DatabasePostgreSQL.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/includes/DatabasePostgreSQL.php b/includes/DatabasePostgreSQL.php index e257dc393f..27bab67bf9 100644 --- a/includes/DatabasePostgreSQL.php +++ b/includes/DatabasePostgreSQL.php @@ -350,8 +350,17 @@ class DatabasePgsql extends Database { # Returns the size of a text field, or -1 for "unlimited" function textFieldSize( $table, $field ) { $table = $this->tableName( $table ); - $res = $this->query( "SELECT $field FROM $table LIMIT 1", "Database::textFieldLength" ); - $size = pg_field_size( $res, 0 ); + $sql = "SELECT t.typname as ftype,a.atttypmod as size + FROM pg_class c, pg_attribute a, pg_type t + WHERE relname='$table' AND a.attrelid=c.oid AND + a.atttypid=t.oid and a.attname='$field'"; + $res =$this->query($sql); + $row=$this->fetchObject($res); + if ($row->ftype=="varchar") { + $size=$row->size-4; + } else { + $size=$row->size; + } $this->freeResult( $res ); return $size; } -- 2.20.1