Exemple #1
0
 function charset_collation(Modyllic_Type $other = null)
 {
     $other_charset = $other instanceof Modyllic_Type_String ? $other->charset() : $this->default_charset;
     $other_collate = $other instanceof Modyllic_Type_String ? $other->collate() : $this->default_collate;
     $diff_charset = $this->charset() != $other_charset;
     $diff_collate = $this->collate() != $other_collate;
     if ($diff_charset or $diff_collate) {
         if ($this->charset() == "latin1" and $this->collate() == "latin1_general_ci") {
             return " ASCII";
         }
         if ($this->charset() == "ucs2" and $this->collate() == "ucs2_general_ci") {
             return " UNICODE";
         }
     }
     $sql = "";
     if ($diff_charset) {
         $sql .= " CHARACTER SET " . $this->charset();
     }
     if ($diff_collate) {
         if (preg_match('/_bin$/', $this->collate())) {
             $sql .= " BINARY";
         } else {
             $sql .= " COLLATE " . $this->collate();
         }
     }
     return $sql;
 }
Exemple #2
0
 function clone_from(Modyllic_Type $old)
 {
     parent::clone_from($old);
     $this->unsigned = $old->unsigned;
     $this->zerofill = $old->zerofill;
     $this->length = $old->length;
 }
Exemple #3
0
 function get_type()
 {
     // reserved[(token ...)>] [SIGNED|UNSIGNED] [ZEROFILL] [BINARY|ASCII|UNICODE] [{CHARACTER SET|CHARSET} ident] [COLLATE ident]
     $type = Modyllic_Type::create($this->get_reserved());
     if ($this->peek_next()->value() == '(') {
         $this->get_symbol();
         if ($type instanceof Modyllic_Type_Numeric) {
             $args = $this->get_array();
             $type->length = $args[0];
             if (count($args) > 1) {
                 $type->scale = $args[1];
             }
         } else {
             if ($type instanceof Modyllic_Type_Float) {
                 $args = $this->get_array();
                 $type->length = $args[0];
                 if (count($args) > 1) {
                     $type->decimals = $args[1];
                 }
             } else {
                 if ($type instanceof Modyllic_Type_Compound) {
                     $type->values = $this->get_array();
                 } else {
                     $type->length = $this->get_list();
                     if ($type instanceof Modyllic_Type_VarChar and $type->length > 65535) {
                         $type = new Modyllic_Type_Text($type->name, $type->length);
                     } else {
                         if ($type instanceof Modyllic_Type_VarBinary and $type->length > 65535) {
                             $type = new Modyllic_Type_Blob($type->name, $type->length);
                         }
                     }
                 }
             }
         }
     }
     $binary = false;
     while ($this->peek_next() instanceof Modyllic_Token_Reserved) {
         if (in_array($this->peek_next()->token(), array('SIGNED', 'UNSIGNED', 'ZEROFILL', 'ASCII', 'UNICODE', 'BINARY'))) {
             switch ($this->get_reserved()) {
                 case 'SIGNED':
                     $type->unsigned = false;
                     break;
                 case 'UNSIGNED':
                     $type->unsigned = true;
                     break;
                 case 'ZEROFILL':
                     $type->zerofill = true;
                     $type->unsigned = true;
                     break;
                 case 'ASCII':
                     $type->charset('latin1');
                     $type->collate('latin1_general_ci');
                     break;
                 case 'UNICODE':
                     $type->charset('ucs2');
                     $type->collate('ucs2_general_ci');
                     break;
                 case 'BINARY':
                     $binary = true;
                     break;
             }
         } else {
             if (in_array($this->peek_next()->token(), array('CHARACTER SET', 'CHARSET'))) {
                 $this->get_reserved();
                 $new = $this->get_ident();
                 if (isset($type->charset) and isset($type->collate)) {
                     $type->collate = $this->updated_collate($type->charset, $new, $type->collate);
                 }
                 $type->charset($new);
             } else {
                 if ($this->peek_next()->token() == 'COLLATE') {
                     $this->get_reserved();
                     $type->collate($this->get_ident());
                 } else {
                     break;
                 }
             }
         }
     }
     if (($type instanceof Modyllic_Type_VarChar or $type instanceof Modyllic_Type_Text) and strtolower($type->charset()) == 'binary') {
         $type = $type->binary();
     } else {
         if ($binary) {
             $type->collate($type->charset() . "_bin");
         }
     }
     if (!$type->is_valid()) {
         #            throw $this->error( "Syntax error in type declaration of ".$type->to_sql() );
     }
     return $type;
 }
Exemple #4
0
 function func_returns_docs(Modyllic_Type $returns)
 {
     $this->phpdoc("@returns " . $returns->to_sql());
     return $this;
 }
Exemple #5
0
 function clone_from(Modyllic_Type $old)
 {
     parent::clone_from($old);
     $this->length = $old->length;
 }