Beispiel #1
0
 /**
  * Compile field definition
  *
  * @param 	array		$fieldCfg Field definition parts
  * @return 	string		Field definition string
  */
 public function compileFieldCfg($fieldCfg)
 {
     $cfg = '';
     switch ((string) $this->databaseConnection->handlerCfg[$this->databaseConnection->lastHandlerKey]['type']) {
         case 'native':
             $cfg = parent::compileFieldCfg($fieldCfg);
             break;
         case 'adodb':
             // Set type:
             $type = $this->databaseConnection->MySQLMetaType($fieldCfg['fieldType']);
             $cfg = $type;
             // Add value, if any:
             if (strlen($fieldCfg['value']) && in_array($type, array('C', 'C2'))) {
                 $cfg .= ' ' . $fieldCfg['value'];
             } elseif (!isset($fieldCfg['value']) && in_array($type, array('C', 'C2'))) {
                 $cfg .= ' 255';
             }
             // Add additional features:
             $noQuote = TRUE;
             if (is_array($fieldCfg['featureIndex'])) {
                 // MySQL assigns DEFAULT value automatically if NOT NULL, fake this here
                 // numeric fields get 0 as default, other fields an empty string
                 if (isset($fieldCfg['featureIndex']['NOTNULL']) && !isset($fieldCfg['featureIndex']['DEFAULT']) && !isset($fieldCfg['featureIndex']['AUTO_INCREMENT'])) {
                     switch ($type) {
                         case 'I8':
                         case 'F':
                         case 'N':
                             $fieldCfg['featureIndex']['DEFAULT'] = array('keyword' => 'DEFAULT', 'value' => array('0', ''));
                             break;
                         default:
                             $fieldCfg['featureIndex']['DEFAULT'] = array('keyword' => 'DEFAULT', 'value' => array('', '\''));
                     }
                 }
                 foreach ($fieldCfg['featureIndex'] as $feature => $featureDef) {
                     switch (TRUE) {
                         case $feature === 'UNSIGNED' && !$this->databaseConnection->runningADOdbDriver('mysql'):
                         case $feature === 'NOTNULL' && $this->databaseConnection->runningADOdbDriver('oci8'):
                             continue;
                         case $feature === 'AUTO_INCREMENT':
                             $cfg .= ' AUTOINCREMENT';
                             break;
                         case $feature === 'NOTNULL':
                             $cfg .= ' NOTNULL';
                             break;
                         default:
                             $cfg .= ' ' . $featureDef['keyword'];
                     }
                     // Add value if found:
                     if (is_array($featureDef['value'])) {
                         if ($featureDef['value'][0] === '') {
                             $cfg .= ' "\'\'"';
                         } else {
                             $cfg .= ' ' . $featureDef['value'][1] . $this->compileAddslashes($featureDef['value'][0]) . $featureDef['value'][1];
                             if (!is_numeric($featureDef['value'][0])) {
                                 $noQuote = FALSE;
                             }
                         }
                     }
                 }
             }
             if ($noQuote) {
                 $cfg .= ' NOQUOTE';
             }
             break;
     }
     // Return field definition string:
     return $cfg;
 }