note 50270 deleted from function.pg-field-size by tularis

From: Date: Wed, 23 Feb 2005 13:59:05 +0000
Subject: note 50270 deleted from function.pg-field-size by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-85433@lists.php.net to get a copy of this message
Note Submitter: php at tribun dot de Reason: spam ---- function get_create_syntax( $table ) { $qry = " SELECT * FROM $table LIMIT 1 "; $res = pg_query( $qry ); $row = pg_fetch_assoc( $res ); $create = "CREATE TABLE $table \n(\n"; $item = array(); for( $i = 0; $i < count( $row ); $i++ ) { $name = pg_field_name( $res, $i ); $type = pg_field_type( $res, $i ); $size = pg_field_size( $res, $i ); $item[$i] = '"'.$name.'" '.$type; $qry = " SELECT a.atttypmod AS size, a.attnotnull AS notnull FROM pg_attribute AS a, pg_class AS c WHERE c.relname = '$table' AND a.attrelid = c.oid AND a.attname = '$name' "; $res2 = pg_query( $qry ); $out = pg_fetch_object( $res2 ); if( $out -> size != -1 ) { $item[$i] .= '('.( $out -> size - 4 ).')'; } if( $out -> notnull == 't' ) $item[$i] .= ' NOT'; $item[$i] .= ' NULL'; } $create .= implode( ",\n", $item ) ."\n);"; return $create; }

« previous php.notes (#85433) next »