|
@@ 5594-5611 (lines=18) @@
|
| 5591 |
|
/** |
| 5592 |
|
* @see QueryWriter::addUniqueIndex |
| 5593 |
|
*/ |
| 5594 |
|
public function addUniqueConstraint( $type, $properties ) |
| 5595 |
|
{ |
| 5596 |
|
$tableNoQ = $this->esc( $type, TRUE ); |
| 5597 |
|
$columns = array(); |
| 5598 |
|
foreach( $properties as $key => $column ) $columns[$key] = $this->esc( $column ); |
| 5599 |
|
$table = $this->esc( $type ); |
| 5600 |
|
sort( $columns ); // Else we get multiple indexes due to order-effects |
| 5601 |
|
$name = 'UQ_' . sha1( implode( ',', $columns ) ); |
| 5602 |
|
try { |
| 5603 |
|
$sql = "ALTER TABLE $table |
| 5604 |
|
ADD UNIQUE INDEX $name (" . implode( ',', $columns ) . ")"; |
| 5605 |
|
$this->adapter->exec( $sql ); |
| 5606 |
|
} catch ( SQLException $e ) { |
| 5607 |
|
//do nothing, dont use alter table ignore, this will delete duplicate records in 3-ways! |
| 5608 |
|
return FALSE; |
| 5609 |
|
} |
| 5610 |
|
return TRUE; |
| 5611 |
|
} |
| 5612 |
|
|
| 5613 |
|
/** |
| 5614 |
|
* @see QueryWriter::addIndex |
|
@@ 6424-6440 (lines=17) @@
|
| 6421 |
|
/** |
| 6422 |
|
* @see QueryWriter::addUniqueIndex |
| 6423 |
|
*/ |
| 6424 |
|
public function addUniqueConstraint( $type, $properties ) |
| 6425 |
|
{ |
| 6426 |
|
$tableNoQ = $this->esc( $type, TRUE ); |
| 6427 |
|
$columns = array(); |
| 6428 |
|
foreach( $properties as $key => $column ) $columns[$key] = $this->esc( $column ); |
| 6429 |
|
$table = $this->esc( $type ); |
| 6430 |
|
sort( $columns ); //else we get multiple indexes due to order-effects |
| 6431 |
|
$name = "UQ_" . sha1( $table . implode( ',', $columns ) ); |
| 6432 |
|
$sql = "ALTER TABLE {$table} |
| 6433 |
|
ADD CONSTRAINT $name UNIQUE (" . implode( ',', $columns ) . ")"; |
| 6434 |
|
try { |
| 6435 |
|
$this->adapter->exec( $sql ); |
| 6436 |
|
} catch( SQLException $e ) { |
| 6437 |
|
return FALSE; |
| 6438 |
|
} |
| 6439 |
|
return TRUE; |
| 6440 |
|
} |
| 6441 |
|
|
| 6442 |
|
/** |
| 6443 |
|
* @see QueryWriter::sqlStateIn |