Skip to content
Snippets Groups Projects
Commit af0e71e2 authored by Satish's avatar Satish
Browse files

Enhancement added to handle constraints in adodb library

parent 9ab4fc9d
No related branches found
No related tags found
1 merge request!192Adodb library updated to 5.20
......@@ -938,7 +938,7 @@ class ADODB_DataDict {
This function changes/adds new fields to your table. You don't
have to know if the col is new or not. It will check on its own.
*/
function ChangeTableSQL($tablename, $flds, $tableoptions = false, $dropOldFlds=false)
function ChangeTableSQL($tablename, $flds, $tableoptions = false, $dropOldFlds=false, $forceAlter = false) // GS Fix for constraint impl - forceAlter
{
global $ADODB_FETCH_MODE;
......@@ -955,7 +955,7 @@ class ADODB_DataDict {
if (isset($savem)) $this->connection->SetFetchMode($savem);
$ADODB_FETCH_MODE = $save;
if ( empty($cols)) {
if ( $forceAlter == false && empty($cols)) { // GS Fix for constraint impl
return $this->CreateTableSQL($tablename, $flds, $tableoptions);
}
......@@ -1028,6 +1028,39 @@ class ADODB_DataDict {
if ( !isset($lines[$id]) )
$sql[] = $alter . $this->dropCol . ' ' . $v->name;
}
return $sql;
// GS Fix for constraint impl -- start
if($forceAlter == false) {
return $sql;
}
$sqlarray = array();
$alter .= implode(",\n", $sql);
if (sizeof($pkey)>0) {
$alter .= ",\n PRIMARY KEY (";
$alter .= implode(", ",$pkey).")";
}
if (isset($tableoptions['CONSTRAINTS'])) {
$alter .= "\n".$tableoptions['CONSTRAINTS'];
}
if (isset($tableoptions[$this->upperName.'_CONSTRAINTS'])) {
$alter .= "\n".$tableoptions[$this->upperName.'_CONSTRAINTS'];
}
if (isset($tableoptions[$this->upperName])) {
$alter .= $tableoptions[$this->upperName];
}
$sqlarray[] = $alter;
$taboptions = $this->_Options($tableoptions);
$tsql = $this->_Triggers($this->TableName($tablename),$taboptions);
foreach($tsql as $s) {
$sqlarray[] = $s;
}
// GS Fix for constraint impl -- end
return $sqlarray;
}
} // class
......@@ -240,6 +240,7 @@ class dbTable extends dbObject {
* @access private
*/
var $drop_field = array();
var $alter; // GS Fix for constraint impl
/**
* Iniitializes a new table object.
......@@ -250,6 +251,10 @@ class dbTable extends dbObject {
function __construct( &$parent, $attributes = NULL ) {
$this->parent = $parent;
$this->name = $this->prefix($attributes['NAME']);
// GS Fix for constraint impl
if(isset($attributes['ALTER'])) {
$this->alter = $attributes['ALTER'];
}
}
/**
......@@ -324,12 +329,12 @@ class dbTable extends dbObject {
if( isset( $this->current_field ) ) {
$this->addFieldOpt( $this->current_field, $this->currentElement, $cdata );
} else {
$this->addTableOpt( $cdata );
$this->addTableOpt( $cdata, 'CONSTRAINTS' ); // GS Fix for constraint impl
}
break;
// Table option
case 'OPT':
$this->addTableOpt( $cdata );
$this->addTableOpt( $cdata, 'mysql' ); // GS Fix for constraint impl
break;
default:
......@@ -463,9 +468,13 @@ class dbTable extends dbObject {
* @param string $opt Table option
* @return array Options
*/
function addTableOpt( $opt ) {
if(isset($this->currentPlatform)) {
$this->opts[$this->parent->db->databaseType] = $opt;
function addTableOpt( $opt, $key = NULL) { // GS Fix for constraint impl
if ($key) {
$this->opts[$key] = $opt;
} else {
if(isset($this->currentPlatform)) {
$this->opts[$this->parent->db->databaseType] = $opt;
}
}
return $this->opts;
}
......@@ -548,7 +557,7 @@ class dbTable extends dbObject {
}
}
if( empty( $legacy_fields ) ) {
if( empty( $legacy_fields ) && !isset($this->alter)) { // GS Fix for constraint impl
// Create the new table
$sql[] = $xmls->dict->CreateTableSQL( $this->name, $fldarray, $this->opts );
logMsg( end( $sql ), 'Generated CreateTableSQL' );
......@@ -559,7 +568,7 @@ class dbTable extends dbObject {
// Use ChangeTableSQL
case 'ALTER':
logMsg( 'Generated ChangeTableSQL (ALTERing table)' );
$sql[] = $xmls->dict->ChangeTableSQL( $this->name, $fldarray, $this->opts );
$sql[] = $xmls->dict->ChangeTableSQL( $this->name, $fldarray, $this->opts, false, $this->alter ); // GS Fix for constraint impl
break;
case 'REPLACE':
logMsg( 'Doing upgrade REPLACE (testing)' );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment