diff --git a/phpgwapi/inc/adodb/adodb-datadict.inc.php b/phpgwapi/inc/adodb/adodb-datadict.inc.php index 6aa7a151de..eb68903e59 100644 --- a/phpgwapi/inc/adodb/adodb-datadict.inc.php +++ b/phpgwapi/inc/adodb/adodb-datadict.inc.php @@ -162,10 +162,12 @@ class ADODB_DataDict { var $connection; var $debug = false; var $dropTable = 'DROP TABLE %s'; + var $renameTable = 'RENAME TABLE %s TO %s'; var $dropIndex = 'DROP INDEX %s'; var $addCol = ' ADD'; var $alterCol = ' ALTER COLUMN'; var $dropCol = ' DROP COLUMN'; + var $renameCol = 'ALTER TABLE %s RENAME COLUMN %s TO %s'; // table, old-column, new-column, column-definitions (not used by default) var $nameRegex = '\w'; var $schema = false; var $serverInfo = array(); @@ -350,6 +352,18 @@ class ADODB_DataDict { return $sql; } + // $flds is only used for mysql so far + function RenameColumnSQL($tabname,$oldcolumn,$newcolumn,$flds='') + { + $tabname = $this->TableName ($tabname); + if ($flds) { + list($lines,$pkey) = $this->_GenFields($flds); + list(,$first) = each($lines); + list(,$column_def) = split("[\t ]+",$first,2); + } + return array(sprintf($this->renameColumn,$tabname,$this->NameQuote($oldcolumn),$this->NameQuote($newcolumn),$column_def)); + } + function DropColumnSQL($tabname, $flds) { $tabname = $this->TableName ($tabname); @@ -367,6 +381,11 @@ class ADODB_DataDict { return array (sprintf($this->dropTable, $this->TableName($tabname))); } + function RenameTableSQL($tabname,$newname) + { + return array (sprintf($this->renameTable, $this->TableName($tabname),$this->TableName($newname))); + } + /* Generate the SQL to create table. Returns an array of sql strings. */ diff --git a/phpgwapi/inc/adodb/datadict/datadict-mssql.inc.php b/phpgwapi/inc/adodb/datadict/datadict-mssql.inc.php index 017fe64726..114fd0f4b6 100644 --- a/phpgwapi/inc/adodb/datadict/datadict-mssql.inc.php +++ b/phpgwapi/inc/adodb/datadict/datadict-mssql.inc.php @@ -17,6 +17,8 @@ class ADODB2_mssql extends ADODB_DataDict { var $databaseType = 'mssql'; var $dropIndex = 'DROP INDEX %2$s.%1$s'; + var $renameTable = "EXEC sp_rename '%1','%2'"; + var $renameColumn = "EXEC sp_rename '%1.%2','%3'"; function MetaType($t,$len=-1,$fieldobj=false) { diff --git a/phpgwapi/inc/adodb/datadict/datadict-mysql.inc.php b/phpgwapi/inc/adodb/datadict/datadict-mysql.inc.php index c8b757753d..73065dc112 100644 --- a/phpgwapi/inc/adodb/datadict/datadict-mysql.inc.php +++ b/phpgwapi/inc/adodb/datadict/datadict-mysql.inc.php @@ -20,6 +20,7 @@ class ADODB2_mysql extends ADODB_DataDict { var $dropTable = 'DROP TABLE IF EXISTS %s'; // requires mysql 3.22 or later var $dropIndex = 'DROP INDEX %s ON %s'; + var $renameColumn = 'ALTER TABLE %s CHANGE COLUMN %s %s %s'; // needs column-definition! function MetaType($t,$len=-1,$fieldobj=false) { diff --git a/phpgwapi/inc/adodb/datadict/datadict-postgres.inc.php b/phpgwapi/inc/adodb/datadict/datadict-postgres.inc.php index 52ae421018..52cd0473ec 100644 --- a/phpgwapi/inc/adodb/datadict/datadict-postgres.inc.php +++ b/phpgwapi/inc/adodb/datadict/datadict-postgres.inc.php @@ -20,6 +20,7 @@ class ADODB2_postgres extends ADODB_DataDict { var $seqPrefix = 'SEQ_'; var $addCol = ' ADD COLUMN'; var $quote = '"'; + var $renameTable = 'ALTER TABLE %s RENAME TO %s'; function MetaType($t,$len=-1,$fieldobj=false) { diff --git a/phpgwapi/inc/adodb/datadict/datadict-sapdb.inc.php b/phpgwapi/inc/adodb/datadict/datadict-sapdb.inc.php index 6631bc1352..bac91a6fdd 100644 --- a/phpgwapi/inc/adodb/datadict/datadict-sapdb.inc.php +++ b/phpgwapi/inc/adodb/datadict/datadict-sapdb.inc.php @@ -18,6 +18,7 @@ class ADODB2_sapdb extends ADODB_DataDict { var $databaseType = 'sapdb'; var $seqField = false; + var $renameCol = 'RENAME COLUMN %s.%s TO %s'; function ActualType($meta) { @@ -48,15 +49,6 @@ class ADODB2_sapdb extends ADODB_DataDict { } } - function CreateTableSQL($tabname, $flds, $tableoptions=false) - { - $sql = ADODB_DataDict::CreateTableSQL($tabname, $flds, $tableoptions); - - echo "
".print_r($sql,true)."
\n"; - - return $sql; - } - // return string must begin with space function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned) { @@ -92,7 +84,7 @@ class ADODB2_sapdb extends ADODB_DataDict { foreach($flds as $k => $v) { $flds[$k] = $this->NameQuote($v); } - return array( 'ALTER TABLE ' . $tabname . 'DROP (' . implode(',',$flds) . ')' ); + return array( 'ALTER TABLE ' . $tabname . ' DROP (' . implode(',',$flds) . ')' ); } } diff --git a/phpgwapi/inc/adodb/drivers/adodb-sapdb.inc.php b/phpgwapi/inc/adodb/drivers/adodb-sapdb.inc.php index 40446cc181..19f93df754 100644 --- a/phpgwapi/inc/adodb/drivers/adodb-sapdb.inc.php +++ b/phpgwapi/inc/adodb/drivers/adodb-sapdb.inc.php @@ -36,9 +36,15 @@ class ADODB_SAPDB extends ADODB_odbc { $this->ADODB_odbc(); } - // ToDo: retrive column-names and use $primary !!! function &MetaIndexes ($table, $primary = FALSE) { + if ($primary) { + return array( + 'SYSPRIMARYKEYINDEX' => array( + 'unique' => True, // by definition + 'columns' => $this->MetaPrimaryKeys($table), + )); + } $table = $this->Quote(strtoupper($table)); $sql = "SELECT INDEXNAME,TYPE,COLUMNNAME FROM INDEXCOLUMNS ". " WHERE TABLENAME=$table".