<?php
class vrupdcol
{
var $colafter;
	function vrupdcol($tabla,$colu,$tipo,$after='',$defa='')
	{
		require('../cfg/cfg.php');
		require('../cfg/res.php');
		
		if (substr($tabla,-1,1)=='0')	{if (substr($colu,4,1)!='_'){$colu=substr($tabla,0,4).'_'.substr($colu,4,20);}}
		
		if($tipo=='X')
	{
		$xstr='alter table '.$tabla.' drop column '.$colu;
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;}
	}
	else
	{
		$xstr='alter table '.$tabla.' add column '.$colu.' '.$tipo;
		if (mysql_query($xstr,$link_vcrx)==1){echo "\n";echo ' --> ADD OK '.$tabla.'-'.$colu;}

		
		$xstr='alter table '.$tabla.' change column '.$colu.' '.$colu.' '.$tipo;if($after>""){$xstr.=' after '.$after;};
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;}

		$this->colafter=$colu;
	}

	if ($defa>""){
	//  DEFAULT	
		$xstr='alter table '.$tabla.' alter column '.$colu.' drop default ';
		mysql_query($xstr,$link_vcrx);

		$xstr='alter table '.$tabla.' alter column '.$colu.' set  default "'.$defa.'"';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;}

		$xstr='update '.$tabla.' set '.$colu.'="'.$defa.'" where '.$colu.' is null';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;}

		$xstr='insert into '.$colu.'0('.$colu.'_codigo,'.$colu.'_descri)value("'.$defa.'","_DEFAULT")';
		if (mysql_query($xstr,$link_vcrx)==1){echo "\n";echo ' --> DEFA OK '.$tabla.'-'.$colu.'->'.$defa;}
// 		echo "\n";echo $xstr;
	}
	
	}
	
}
?>