Beispiel #1
0
 /**
  * Get the SQL to generate the indexes of the given model.
  *
  * @param Object Model
  * @return array Array of SQL strings ready to execute.
  */
 function getSqlIndexes($model)
 {
     $index = array();
     foreach ($model->_a['idx'] as $idx => $val) {
         if (!isset($val['col'])) {
             $val['col'] = $idx;
         }
         $index[$this->con->pfx . $model->_a['table'] . '_' . $idx] = sprintf('CREATE INDEX `%s` ON `%s` (%s);', $idx, $this->con->pfx . $model->_a['table'], Pluf_DB_Schema::quoteColumn($val['col'], $this->con));
     }
     foreach ($model->_a['cols'] as $col => $val) {
         $field = new $val['type']();
         if ($field->type == 'foreignkey') {
             $index[$this->con->pfx . $model->_a['table'] . '_' . $col . '_foreignkey'] = sprintf('CREATE INDEX `%s` ON `%s` (`%s`);', $col . '_foreignkey_idx', $this->con->pfx . $model->_a['table'], $col);
         }
         if (isset($val['unique']) and $val['unique'] == true) {
             $index[$this->con->pfx . $model->_a['table'] . '_' . $col . '_unique'] = sprintf('CREATE UNIQUE INDEX `%s` ON `%s` (%s);', $col . '_unique_idx', $this->con->pfx . $model->_a['table'], Pluf_DB_Schema::quoteColumn($col, $this->con));
         }
     }
     return $index;
 }
Beispiel #2
0
 /**
  * Get the SQL to generate the indexes of the given model.
  *
  * @param Object Model
  * @return array Array of SQL strings ready to execute.
  */
 function getSqlIndexes($model)
 {
     $index = array();
     foreach ($model->_a['idx'] as $idx => $val) {
         if (!isset($val['col'])) {
             $val['col'] = $idx;
         }
         if ($val['type'] == 'unique') {
             $unique = 'UNIQUE ';
         } else {
             $unique = '';
         }
         $index[$this->con->pfx . $model->_a['table'] . '_' . $idx] = sprintf('CREATE ' . $unique . 'INDEX %s ON %s (%s);', $this->con->pfx . $model->_a['table'] . '_' . $idx, $this->con->pfx . $model->_a['table'], Pluf_DB_Schema::quoteColumn($val['col'], $this->con));
     }
     foreach ($model->_a['cols'] as $col => $val) {
         $field = new $val['type']();
         if (isset($val['unique']) and $val['unique'] == true) {
             $index[$this->con->pfx . $model->_a['table'] . '_' . $col . '_unique'] = sprintf('CREATE UNIQUE INDEX %s ON %s (%s);', $this->con->pfx . $model->_a['table'] . '_' . $col . '_unique_idx', $this->con->pfx . $model->_a['table'], Pluf_DB_Schema::quoteColumn($col, $this->con));
         }
     }
     return $index;
 }