Example #1
0
 /**
  * Given one correct xmldb_index, returns the SQL statements
  * needed to create it (in array).
  *
  * @param xmldb_table $xmldb_table The xmldb_table instance to create the index on.
  * @param xmldb_index $xmldb_index The xmldb_index to create.
  * @return array An array of SQL statements to create the index.
  * @throws coding_exception Thrown if the xmldb_index does not validate with the xmldb_table.
  */
 public function getCreateIndexSQL($xmldb_table, $xmldb_index)
 {
     if ($error = $xmldb_index->validateDefinition($xmldb_table)) {
         throw new coding_exception($error);
     }
     $unique = '';
     $suffix = 'ix';
     if ($xmldb_index->getUnique()) {
         $unique = ' UNIQUE';
         $suffix = 'uix';
     }
     $index = 'CREATE' . $unique . ' INDEX ';
     $index .= $this->getNameForObject($xmldb_table->getName(), implode(', ', $xmldb_index->getFields()), $suffix);
     $index .= ' ON ' . $this->getTableName($xmldb_table);
     $index .= ' (' . implode(', ', $this->getEncQuoted($xmldb_index->getFields())) . ')';
     return array($index);
 }