<?php
/*
Last change in version: 2.1 Alpha 2
#########################################################################################
# ADbNewsSender 2 #
# Copyright (C) 2010 Florian Grannemann (E-mail: hide@address.com) #
# Website: http://adbnewssender.sf.net #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see http://www.gnu.org/licenses/. #
#########################################################################################
*/
/*
This file implements the rename_table function.
*/
//$querystring contains the old table name
//$params contains the new table name
$res=@pg_query("SELECT column_name FROM information_schema.key_column_usage, information_schema.table_constraints WHERE information_schema.table_constraints.table_name = '".strtolower($querystring)."' and information_schema.key_column_usage.table_name='".strtolower($querystring)."' and (constraint_type ='PRIMARY KEY');");
$pkeys="";
//storing primary keys in an string
$firstentry="yes";
while($row=pg_fetch_row($res)){
if($firstentry !="yes"){
$pkeys=$pkeys.", ";
}
else{
$firstentry="no";
}
$pkeys=$pkeys.$row[0];
}
$query="ALTER TABLE $querystring RENAME TO $params;";
if(@pg_query($this->session,$query)){
//now drop all primary keys of the old table name:
@pg_query("ALTER TABLE ".$params." drop constraint ".$querystring."_pkey;");
//now add primary keys to the new table name:
@pg_query("ALTER TABLE ".$params." ADD PRIMARY KEY (".$pkeys.");");
$result=true;
}
?>