Exemplo n.º 1
0
 /**
  * Get the SQL syntax for a single column that would be included in a table create or alter statement.
  *
  * @param   SimpleXMLElement  $field  The XML field definition.
  *
  * @return  string
  *
  * @since   11.1
  */
 protected function getColumnSQL(SimpleXMLElement $field)
 {
     // TODO Incorporate into parent class and use $this.
     $blobs = array('text', 'smalltext', 'mediumtext', 'largetext');
     $fName = (string) $field['Field'];
     $fType = (string) $field['Type'];
     $fNull = (string) $field['Null'];
     $fDefault = isset($field['Default']) ? (string) $field['Default'] : null;
     $fExtra = (string) $field['Extra'];
     $query = $this->db->quoteName($fName) . ' ' . $fType;
     if ($fNull == 'NO') {
         if (in_array($fType, $blobs) || $fDefault === null) {
             $query .= ' NOT NULL';
         } else {
             // TODO Don't quote numeric values.
             $query .= ' NOT NULL DEFAULT ' . $this->db->quote($fDefault);
         }
     } else {
         if ($fDefault === null) {
             $query .= ' DEFAULT NULL';
         } else {
             // TODO Don't quote numeric values.
             $query .= ' DEFAULT ' . $this->db->quote($fDefault);
         }
     }
     if ($fExtra) {
         $query .= ' ' . strtoupper($fExtra);
     }
     return $query;
 }