Exemplo n.º 1
0
 /**
  * 
  * Get the column declaration string for a DB_Table column.
  * 
  * @static
  * 
  * @access public
  * 
  * @param string $coltype The DB_Table column type.
  * 
  * @param int $size The size for the column (needed for string and
  * decimal).
  * 
  * @param int $scope The scope for the column (needed for decimal).
  * 
  * @param bool $require True if the column should be NOT NULL, false
  * allowed to be NULL.
  * 
  * @param string $default The SQL calculation for a default value.
  * 
  * @param int $max_scope The maximal scope for all table column
  * (pass-by-reference).
  * 
  * @return string|object A MDB2 column definition array on success, or a
  * PEAR_Error on failure.
  * 
  */
 function getDeclareMDB2($coltype, $size = null, $scope = null, $require = null, $default = null, &$max_scope)
 {
     // validate char/varchar/decimal type declaration
     $validation = DB_Table_Manager::_validateTypeDeclaration($coltype, $size, $scope);
     if (PEAR::isError($validation)) {
         return $validation;
     }
     // map of MDB2 column types
     $map = $GLOBALS['_DB_TABLE']['mdb2_type'];
     // is it a recognized column type?
     $types = array_keys($map);
     if (!in_array($coltype, $types)) {
         return DB_Table::throwError(DB_TABLE_ERR_DECLARE_TYPE, "('{$coltype}')");
     }
     // build declaration array
     $new_column = array('type' => $map[$coltype], 'notnull' => $require);
     if ($size) {
         $new_column['length'] = $size;
     }
     // determine integer length to be used in MDB2
     if (in_array($coltype, array('smallint', 'integer', 'bigint'))) {
         switch ($coltype) {
             case 'smallint':
                 $new_column['length'] = 2;
                 break;
             case 'integer':
                 $new_column['length'] = 4;
                 break;
             case 'bigint':
                 $new_column['length'] = 5;
                 break;
         }
     }
     if ($scope) {
         $max_scope = max($max_scope, $scope);
     }
     if ($default) {
         $new_column['default'] = $default;
     }
     return $new_column;
 }