Index: adodb-datadict.inc.php
===================================================================
--- adodb-datadict.inc.php	(revision 1)
+++ adodb-datadict.inc.php	(working copy)
@@ -936,7 +936,7 @@
 	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;
 	
@@ -953,7 +953,7 @@
 		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);
 		}
 		
@@ -1026,7 +1026,24 @@
 			    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
 ?>
\ No newline at end of file
Index: adodb-xmlschema.inc.php
===================================================================
--- adodb-xmlschema.inc.php	(revision 1)
+++ adodb-xmlschema.inc.php	(working copy)
@@ -241,6 +241,7 @@
 	* @access private
 	*/
 	var $drop_field = array();
+	var $alter; // GS Fix for constraint impl
 	
 	/**
 	* Iniitializes a new table object.
@@ -251,6 +252,11 @@
 	function dbTable( &$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'];
+		}
 	}
 	
 	/**
@@ -323,12 +329,12 @@
 				if( isset( $this->current_field ) ) {
 					$this->addFieldOpt( $this->current_field, $this->currentElement, $cdata );
 				} else {
-					$this->addTableOpt( $cdata );
+					$this->addTableOpt('CONSTRAINTS', $cdata ); // GS Fix for constraint impl
 				}
 				break;
 			// Table option
 			case 'OPT':
-				$this->addTableOpt( $cdata );
+				$this->addTableOpt('mysql', $cdata ); // GS Fix for constraint impl
 				break;
 			default:
 				
@@ -462,13 +468,12 @@
 	* @param string $opt Table option
 	* @return array Options
 	*/
-	function addTableOpt( $opt ) {
-		if(isset($this->currentPlatform)) {
-			$this->opts[$this->parent->db->databaseType] = $opt;
-		}
+	function addTableOpt($key, $opt ) { // GS Fix for constraint impl
+		//$this->opts[] = $opt;
+		$this->opts[$key] = $opt;
+		
 		return $this->opts;
 	}
-
 	
 	/**
 	* Generates the SQL that will create the table in the database
@@ -546,8 +551,7 @@
 				}
 			}
 		}
-		
-		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' );
@@ -558,7 +562,7 @@
 				// 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)' );