Пример #1
0
 /**
  * Returns the alias under which a real column will be known in PHP-land.
  *
  * This alias defines how you may refer to the column in the query builder. You
  * may redefine this if, for example, you wish to change the name of a real column
  * without impacting the PHP application, or the other way around.
  *
  * @param GlueDB_Column $column
  *
  * @return string
  */
 public function get_column_alias(GlueDB_Column $column)
 {
     return $column->dbcolumn();
 }
Пример #2
0
 /**
  * Returns the appropriate formatter for given column.
  *
  * @param GlueDB_Column $column
  *
  * @return GlueDB_Formatter
  */
 public function get_formatter(GlueDB_Column $column)
 {
     // Extract first word from type (MySQL may return things like "float unsigned" sometimes) :
     if (preg_match('/^\\S+/', $column->dbtype(), $matches)) {
         $dbtype = $matches[0];
     }
     // Convert type to upper case :
     $dbtype = strtoupper($dbtype);
     // Create appropriate formatter :
     switch ($dbtype) {
         // Integer types :
         case 'TINYINT':
         case 'SMALLINT':
         case 'MEDIUMINT':
         case 'INT':
         case 'BIGINT':
             $formatter = new GlueDB_Formatter_Integer();
             break;
             // Real types :
         // Real types :
         case 'FLOAT':
         case 'DOUBLE':
         case 'DECIMAL':
             $formatter = new GlueDB_Formatter_Float();
             break;
             // Boolean types :
         // Boolean types :
         case 'BIT':
             $formatter = new GlueDB_Formatter_Boolean();
             break;
             // String types :
         // String types :
         case 'CHAR':
         case 'VARCHAR':
         case 'TINYTEXT':
         case 'TEXT':
         case 'MEDIUMTEXT':
         case 'LONGTEXT':
         case 'ENUM':
         case 'SET':
             $formatter = new GlueDB_Formatter_String();
             break;
             // Binary types :
         // Binary types :
         case 'BINARY':
         case 'VARBINARY':
         case 'TINYBLOB':
         case 'BLOB':
         case 'MEDIUMBLOB':
         case 'LONGBLOB':
             $formatter = new GlueDB_Formatter_String();
             // TODO Is this the right thing to do ?
             break;
             // Date and time types :
         // Date and time types :
         case 'DATE':
         case 'DATETIME':
         case 'TIME':
         case 'TIMESTAMP':
         case 'YEAR':
             $formatter = new GlueDB_Formatter_String();
             // TODO Is this the right thing to do ?
             break;
             // Default :
         // Default :
         default:
             throw new Kohana_Exception("Unknown MySQL data type : " . $dbtype);
     }
     return $formatter;
 }