includes/dbal.php
changeset 628 ab6f55abb17e
parent 619 80fa6fa6bf3a
child 636 c9ea830a211f
equal deleted inserted replaced
627:460e483987ab 628:ab6f55abb17e
  1102    * @return int
  1102    * @return int
  1103    */
  1103    */
  1104   
  1104   
  1105   function insert_id()
  1105   function insert_id()
  1106   {
  1106   {
  1107     return @pg_last_oid();
  1107     // list of primary keys in Enano tables
       
  1108     // this is a bit hackish, but not much choice.
       
  1109     static $primary_keys = false;
       
  1110     if ( !is_array($primary_keys) )
       
  1111     {
       
  1112       $primary_keys = array(
       
  1113         table_prefix . 'comments' => 'comment_id',
       
  1114         table_prefix . 'logs' => 'log_id',
       
  1115         table_prefix . 'users' => 'user_id',
       
  1116         table_prefix . 'banlist' => 'ban_id',
       
  1117         table_prefix . 'files' => 'file_id',
       
  1118         table_prefix . 'buddies' => 'buddy_id',
       
  1119         table_prefix . 'privmsgs' => 'message_id',
       
  1120         table_prefix . 'sidebar' => 'item_id',
       
  1121         table_prefix . 'hits' => 'hit_id',
       
  1122         table_prefix . 'groups' => 'group_id',
       
  1123         table_prefix . 'group_members' => 'member_id',
       
  1124         table_prefix . 'acl' => 'rule_id',
       
  1125         table_prefix . 'page_groups' => 'pg_id',
       
  1126         table_prefix . 'page_group_members' => 'pg_member_id',
       
  1127         table_prefix . 'tags' => 'tag_id',
       
  1128         table_prefix . 'lockout' => 'id',
       
  1129         table_prefix . 'language' => 'lang_id',
       
  1130         table_prefix . 'language_strings' => 'string_id',
       
  1131         table_prefix . 'ranks' => 'rank_id',
       
  1132         table_prefix . 'captcha' => 'code_id',
       
  1133         table_prefix . 'diffiehellman' => 'key_id',
       
  1134         table_prefix . 'plugins' => 'plugin_id'
       
  1135       );
       
  1136       // allow plugins to patch this if needed
       
  1137       global $plugins;
       
  1138       $code = $plugins->setHook('pgsql_set_serial_list');
       
  1139       foreach ( $code as $cmd )
       
  1140       {
       
  1141         eval($cmd);
       
  1142       }
       
  1143     }
       
  1144     $last_was_insert = preg_match('/^INSERT INTO ([a-z0-9_]+)\(/i', $this->latest_query, $match);
       
  1145     if ( $last_was_insert )
       
  1146     {
       
  1147       // trick based on PunBB's PostgreSQL driver
       
  1148       $table =& $match[1];
       
  1149       if ( isset($primary_keys[$table]) )
       
  1150       {
       
  1151         $primary_key = "{$table}_{$primary_keys[$table]}_seq";
       
  1152         $q = pg_query("SELECT CURRVAL('$primary_key');");
       
  1153         return ( $q ) ? intval(@pg_fetch_result($q, 0)) : false;
       
  1154       }
       
  1155     }
       
  1156     return false;
  1108   }
  1157   }
  1109   
  1158   
  1110   function fetchrow($r = false) {
  1159   function fetchrow($r = false) {
  1111     $this->enable_errorhandler();
  1160     $this->enable_errorhandler();
  1112     if(!$this->_conn) return false;
  1161     if(!$this->_conn) return false;