Skip to content

Commit

Permalink
Prevent Unique Keys generation. Instead use unique indexes at DB level.
Browse files Browse the repository at this point in the history
With this, all we'll have are PRIMARY KEYS + INDEXES, that are pretty
well supported by ADODB MetaXXX functions.
Both Unique and Foreign Keys will be used once ADODB support them and
the relational mode was enforced.
  • Loading branch information
stronk7 committed Sep 24, 2006
1 parent d13c1ae commit b0ec41a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/xmldb/classes/generators/mssql/mssql.class.php
Expand Up @@ -42,10 +42,11 @@ class XMLDBmssql extends XMLDBgenerator {
var $specify_nulls = true; //To force the generator if NULL clauses must be specified. It shouldn't be necessary
//but some mssql drivers require them or everything is created as NOT NULL :-(

var $unique_keys = false; // Does the generator build unique keys
var $foreign_keys = false; // Does the generator build foreign keys

var $primary_index = false;// Does the generator need to build one index for primary keys
var $unique_index = false; // Does the generator need to build one index for unique keys
var $unique_index = true; // Does the generator need to build one index for unique keys
var $foreign_index = true; // Does the generator need to build one index for foreign keys

var $sequence_extra_code = false; //Does the generator need to add extra code to generate the sequence fields
Expand Down
4 changes: 3 additions & 1 deletion lib/xmldb/classes/generators/mysql/mysql.class.php
Expand Up @@ -38,10 +38,12 @@ class XMLDBmysql extends XMLDBGenerator {

var $primary_key_name = ''; //To force primary key names to one string (null=no force)

var $unique_keys = false; // Does the generator build unique key
var $foreign_keys = false; // Does the generator build foreign keys

var $primary_index = false;// Does the generator need to build one index for primary keys
var $unique_index = false; // Does the generator need to build one index for unique keys
var $unique_index = true; // Does the generator need to build one index for unique keys
var $foreign_index = true; // Does the generator need to build one index for foreign keys

var $sequence_extra_code = false; //Does the generator need to add extra code to generate the sequence fields
var $sequence_name = 'auto_increment'; //Particular name for inline sequences in this generator
Expand Down
3 changes: 2 additions & 1 deletion lib/xmldb/classes/generators/oci8po/oci8po.class.php
Expand Up @@ -43,10 +43,11 @@ class XMLDBoci8po extends XMLDBgenerator {

var $default_after_null = false; //To decide if the default clause of each field must go after the null clause

var $unique_keys = false; // Does the generator build unique keys
var $foreign_keys = false; // Does the generator build foreign keys

var $primary_index = false;// Does the generator need to build one index for primary keys
var $unique_index = false; // Does the generator need to build one index for unique keys
var $unique_index = true; // Does the generator need to build one index for unique keys
var $foreign_index = true; // Does the generator need to build one index for foreign keys

var $sequence_extra_code = true; //Does the generator need to add extra code to generate the sequence fields
Expand Down
50 changes: 49 additions & 1 deletion lib/xmldb/classes/generators/postgres7/postgres7.class.php
Expand Up @@ -37,10 +37,11 @@ class XMLDBpostgres7 extends XMLDBgenerator {
var $unsigned_allowed = false; // To define in the generator must handle unsigned information
var $default_for_char = ''; // To define the default to set for NOT NULLs CHARs without default (null=do nothing)

var $unique_keys = false; // Does the generator build unique keys
var $foreign_keys = false; // Does the generator build foreign keys

var $primary_index = false;// Does the generator need to build one index for primary keys
var $unique_index = false; // Does the generator need to build one index for unique keys
var $unique_index = true; // Does the generator need to build one index for unique keys
var $foreign_index = true; // Does the generator need to build one index for foreign keys

var $sequence_extra_code = false; //Does the generator need to add extra code to generate the sequence fields
Expand Down Expand Up @@ -136,6 +137,53 @@ function getCommentSQL ($xmldb_table) {
return array($comment);
}

/**
* Given one XMLDBTable and one XMLDBField, return the SQL statements needded to alter the field in the table
* PostgreSQL has some severe limits:
* - Any change of type or precision requires a new temporary column to be created, values to
* be transfered potentially casting them, to apply defaults if the column is not null and
* finally, to rename it
* - Changes in null/not null require the SET/DROP NOT NULL clause
* - Changes in default require the SET/DROP DEFAULT clause
*/
function getAlterFieldSQL($xmldb_table, $xmldb_field) {

global $db;

/// Get the quoted name of the table and field
$tablename = $this->getEncQuoted($this->prefix . $xmldb_table->getName());
$fieldname = $this->getEncQuoted($xmldb_field->getName());

/// Take a look to field metadata
$meta = array_change_key_case($db->MetaColumns($tablename));
$metac = $meta[$fieldname];
print_object($metac);
$oldtype = strtolower($metac->type);
$oldlength = $metac->max_length;
$olddecimals = empty($metac->scale) ? null : $metac->scale;
$oldnotnull = empty($metac->not_null) ? false : $metac->not_null;
$olddefault = empty($metac->default_value) ? null : $metac->default_value;
/// If field is CLOB and new one is also XMLDB_TYPE_TEXT or
/// if fiels is BLOB and new one is also XMLDB_TYPE_BINARY
/// prevent type to be specified, so only NULL and DEFAULT clauses are allowed
if (($oldtype = 'clob' && $xmldb_field->getType() == XMLDB_TYPE_TEXT) ||
($oldtype = 'blob' && $xmldb_field->getType() == XMLDB_TYPE_BINARY)) {
$this->alter_column_skip_type = true;
$islob = true;
}

/// If field is NOT NULL and the new one too or
/// if field is NULL and the new one too
/// prevent null clause to be specified
if (($oldnotnull && $xmldb_field->getNotnull()) ||
(!$oldnotnull && !$xmldb_field->getNotnull())) {
$this->alter_column_skip_notnull = true;
}

/// In the rest of cases, use the general generator
return parent::getAlterFieldSQL($xmldb_table, $xmldb_field);
}

/**
* Returns an array of reserved words (lowercase) for this DB
*/
Expand Down

0 comments on commit b0ec41a

Please sign in to comment.