Beispiel #1
0
 /**
  * Compiles a CREATE TABLE statement from components array
  *
  * @param 	array		$components Array of SQL query components
  * @return 	array		array with SQL CREATE TABLE/INDEX command(s)
  * @see parseCREATETABLE()
  */
 public function compileCREATETABLE($components)
 {
     $query = array();
     // Execute query (based on handler derived from the TABLE name which we actually know for once!)
     switch ((string) $this->databaseConnection->handlerCfg[$this->databaseConnection->handler_getFromTableList($components['TABLE'])]['type']) {
         case 'native':
             $query[] = parent::compileCREATETABLE($components);
             break;
         case 'adodb':
             // Create fields and keys:
             $fieldsKeys = array();
             $indexKeys = array();
             foreach ($components['FIELDS'] as $fN => $fCfg) {
                 $handlerKey = $this->databaseConnection->handler_getFromTableList($components['TABLE']);
                 $fieldsKeys[$fN] = $this->databaseConnection->quoteName($fN, $handlerKey, TRUE) . ' ' . $this->compileFieldCfg($fCfg['definition']);
             }
             if (isset($components['KEYS']) && is_array($components['KEYS'])) {
                 foreach ($components['KEYS'] as $kN => $kCfg) {
                     if ($kN === 'PRIMARYKEY') {
                         foreach ($kCfg as $field) {
                             $fieldsKeys[$field] .= ' PRIMARY';
                         }
                     } elseif ($kN === 'UNIQUE') {
                         foreach ($kCfg as $n => $field) {
                             $indexKeys = array_merge($indexKeys, $this->databaseConnection->handlerInstance[$this->databaseConnection->handler_getFromTableList($components['TABLE'])]->DataDictionary->CreateIndexSQL($n, $components['TABLE'], $field, array('UNIQUE')));
                         }
                     } else {
                         $indexKeys = array_merge($indexKeys, $this->databaseConnection->handlerInstance[$this->databaseConnection->handler_getFromTableList($components['TABLE'])]->DataDictionary->CreateIndexSQL($components['TABLE'] . '_' . $kN, $components['TABLE'], $kCfg));
                     }
                 }
             }
             // Generally create without OID on PostgreSQL
             $tableOptions = array('postgres' => 'WITHOUT OIDS');
             // Fetch table/index generation query:
             $tableName = $this->databaseConnection->quoteName($components['TABLE'], NULL, TRUE);
             $query = array_merge($this->databaseConnection->handlerInstance[$this->databaseConnection->lastHandlerKey]->DataDictionary->CreateTableSQL($tableName, implode(',' . chr(10), $fieldsKeys), $tableOptions), $indexKeys);
             break;
     }
     return $query;
 }