function metadata($table = "")
 {
     $count = 0;
     $id = 0;
     $res = array();
     if ($table) {
         $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.");
         }
     } else {
         $id = $this->Query_ID;
         if (!$id) {
             $this->halt("No query specified.");
         }
     }
     $count = pg_NumFields($id);
     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"] = "";
     }
     if ($table) {
         pg_FreeResult($id);
     }
     return $res;
 }
Example #2
0
 function metadata($table)
 {
     $count = 0;
     $id = 0;
     $res = array();
     $this->connect();
     $id = pg_exec($this->Link_ID, "select * from {$table} LIMIT 1");
     if ($id < 0) {
         $this->Error = pg_ErrorMessage($id);
         $this->Errno = 1;
         $this->Errors->addError("Metadata query failed: " . $this->Error);
         return 0;
     }
     $count = pg_NumFields($id);
     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"] = "";
     }
     pg_FreeResult($id);
     return $res;
 }
 function metadata($table)
 {
     $count = 0;
     $id = 0;
     $res = 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);
     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'] = '';
     }
     pg_FreeResult($id);
     return $res;
 }
 function metadata($table = "", $iArr = 0)
 {
     $count = 0;
     $id = 0;
     $res = array();
     if ($table) {
         $this->connect();
         $id = pg_exec($this->conn, "select * from {$table}");
         if ($id < 0) {
             $this->Error = pg_ErrorMessage($id);
             $this->Errno = 1;
             $this->halt("Metadata query failed.");
         }
     } else {
         $id = $this->rs[$iArr];
         if (!$id) {
             $this->halt("No query specified.");
         }
     }
     $count = pg_NumFields($id);
     for ($i = 0; $i < $count; $i++) {
         $res['fields'][$i]["name"] = pg_FieldName($id, $i);
         $res['fields'][$i]["type"] = pg_FieldType($id, $i);
         $res['fields'][$i]["pkey"] = "0";
     }
     $this->query("select a.attname,    t.typname, case when a.attlen = -1 then 0 " . "else a.attlen end + case when a.atttypmod = -1 then 0 " . "else (a.atttypmod - 4) end ," . "case when d.description isnull THEN a.attname else d.description end , " . "a.attnum from pg_class c " . "inner join pg_attribute a ON (c.oid = a.attrelid AND a.attnum > 0) " . "INNER JOIN pg_type t ON (a.atttypid = t.oid) " . "LEFT OUTER JOIN pg_description d ON (c.relfilenode = d.objoid AND a.attnum = d.objsubid) " . "where c.relname = '" . $table . "' order by a.attnum");
     for ($i = 0; $i < $this->numrecords(); $i++) {
         $res['fields'][$i]["size"] = $this->f($i, 2);
         $res['fields'][$i]["desc"] = $this->f($i, 3);
     }
     $j = 0;
     for ($i = 0; $i < $count; $i++) {
         $this->query("SELECT relname, indkey[" . $i . "] " . "FROM pg_catalog.pg_index join pg_catalog.pg_class " . "ON pg_index.indrelid = pg_class.oid " . "WHERE indisprimary=true " . "AND relname = '" . $table . "';", 1);
         if ($this->f(0, 1, 1) != "0") {
             $res['fields'][$this->f(0, 1, 1) - 1]["pkey"] = "1";
             $res['pkey'][$j++] = pg_FieldName($id, $this->f(0, 1, 1) - 1);
         }
     }
     if ($table) {
         pg_FreeResult($id);
     }
     $this->query(' SELECT cl.relname AS table_name, a.attname AS column_name, ' . 'clf.relname AS foreign_table_name, af.attname AS foreign_column_name ' . 'FROM pg_attribute a ' . 'JOIN pg_class cl ON a.attrelid = cl.oid AND cl.relkind = \'r\'::"char" ' . 'JOIN pg_namespace n ON n.oid = cl.relnamespace ' . 'JOIN pg_constraint ct ON a.attrelid = ct.conrelid AND ct.confrelid <> 0::oid ' . 'AND ct.conkey[1] = a.attnum ' . 'JOIN pg_class clf ON ct.confrelid = clf.oid AND clf.relkind = \'r\'::"char" ' . 'JOIN pg_namespace nf ON nf.oid = clf.relnamespace ' . 'JOIN pg_attribute af ON af.attrelid = ct.confrelid AND af.attnum = ct.confkey[1] ' . 'WHERE cl.relname = \'' . $table . '\';');
     for ($i = 0; $i < $this->numrecords(); $i++) {
         $res['foreign'][$i]["idcol"] = $this->f($i, 'column_name');
         $res['foreign'][$i]["foretable"] = $this->f($i, 'foreign_table_name');
         $res['foreign'][$i]["forecol"] = $this->f($i, 'foreign_column_name');
     }
     $this->disconnect();
     return $res;
 }
Example #5
0
 function metadata($table)
 {
     $count = 0;
     $id = 0;
     $res = 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);
     for ($i = 0; $i < $count; $i++) {
         $res[$i]["table"] = $table;
         $name = pg_FieldName($id, $i);
         $res[$i]["name"] = $name;
         $res[$i]["type"] = pg_FieldType($id, $i);
         //zot:  phplib is wrong, $name in field size should be $i
         //Mike got the line above corrected.
         $res[$i]["len"] = pg_FieldSize($id, $i);
         $res[$i]["flags"] = "";
     }
     pg_FreeResult($id);
     return $res;
 }