BIGINT field type added to table analysis on import

This commit is contained in:
Dieter Adriaenssens
2010-09-10 17:28:12 +02:00
parent 5d136abd8b
commit 194e357a99
2 changed files with 41 additions and 28 deletions

View File

@@ -6,6 +6,7 @@ $Id$
$HeadURL: https://phpmyadmin.svn.sourceforge.net/svnroot/phpmyadmin/trunk/phpMyAdmin/ChangeLog $ $HeadURL: https://phpmyadmin.svn.sourceforge.net/svnroot/phpmyadmin/trunk/phpMyAdmin/ChangeLog $
3.3.8.0 (not yet released) 3.3.8.0 (not yet released)
- bug #3059311 [import] BIGINT field type added to table analysis
3.3.7.0 (2010-09-07) 3.3.7.0 (2010-09-07)
- patch #3050492 [PDF scratchboard] Cannot drag table box to the edge after - patch #3050492 [PDF scratchboard] Cannot drag table box to the edge after

View File

@@ -408,6 +408,7 @@ define("NONE", 0);
define("VARCHAR", 1); define("VARCHAR", 1);
define("INT", 2); define("INT", 2);
define("DECIMAL", 3); define("DECIMAL", 3);
define("BIGINT", 4);
/* Decimal size defs */ /* Decimal size defs */
define("M", 0); define("M", 0);
@@ -493,6 +494,7 @@ function PMA_getDecimalSize(&$cell) {
* @uses FULL * @uses FULL
* @uses VARCHAR * @uses VARCHAR
* @uses DECIMAL * @uses DECIMAL
* @uses BIGINT
* @uses INT * @uses INT
* @uses NONE * @uses NONE
* @uses strcmp() * @uses strcmp()
@@ -501,8 +503,8 @@ function PMA_getDecimalSize(&$cell) {
* @uses PMA_getD() * @uses PMA_getD()
* @uses PMA_getDecimalSize() * @uses PMA_getDecimalSize()
* @param string $last_cumulative_size Last cumulative column size * @param string $last_cumulative_size Last cumulative column size
* @param int $last_cumulative_type Last cumulative column type (NONE or VARCHAR or DECIMAL or INT) * @param int $last_cumulative_type Last cumulative column type (NONE or VARCHAR or DECIMAL or INT or BIGINT)
* @param int $curr_type Type of the current cell (NONE or VARCHAR or DECIMAL or INT) * @param int $curr_type Type of the current cell (NONE or VARCHAR or DECIMAL or INT or BIGINT)
* @param string &$cell The current cell * @param string &$cell The current cell
* @return string Size of the given cell in the type-appropriate format * @return string Size of the given cell in the type-appropriate format
*/ */
@@ -520,7 +522,7 @@ function PMA_detectSize($last_cumulative_size, $last_cumulative_type, $curr_type
*/ */
elseif ($curr_type == VARCHAR) { elseif ($curr_type == VARCHAR) {
/** /**
* The last cumlative type was VARCHAR * The last cumulative type was VARCHAR
*/ */
if ($last_cumulative_type == VARCHAR) { if ($last_cumulative_type == VARCHAR) {
if ($curr_size >= $last_cumulative_size) { if ($curr_size >= $last_cumulative_size) {
@@ -530,7 +532,7 @@ function PMA_detectSize($last_cumulative_size, $last_cumulative_type, $curr_type
} }
} }
/** /**
* The last cumlative type was DECIMAL * The last cumulative type was DECIMAL
*/ */
elseif ($last_cumulative_type == DECIMAL) { elseif ($last_cumulative_type == DECIMAL) {
$oldM = PMA_getM($last_cumulative_size); $oldM = PMA_getM($last_cumulative_size);
@@ -542,9 +544,9 @@ function PMA_detectSize($last_cumulative_size, $last_cumulative_type, $curr_type
} }
} }
/** /**
* The last cumlative type was INT * The last cumulative type was BIGINT or INT
*/ */
elseif ($last_cumulative_type == INT) { elseif ($last_cumulative_type == BIGINT || $last_cumulative_type == INT) {
if ($curr_size >= $last_cumulative_size) { if ($curr_size >= $last_cumulative_size) {
return $curr_size; return $curr_size;
} else { } else {
@@ -573,7 +575,7 @@ function PMA_detectSize($last_cumulative_size, $last_cumulative_type, $curr_type
*/ */
elseif ($curr_type == DECIMAL) { elseif ($curr_type == DECIMAL) {
/** /**
* The last cumlative type was VARCHAR * The last cumulative type was VARCHAR
*/ */
if ($last_cumulative_type == VARCHAR) { if ($last_cumulative_type == VARCHAR) {
/* Convert $last_cumulative_size from varchar to decimal format */ /* Convert $last_cumulative_size from varchar to decimal format */
@@ -586,7 +588,7 @@ function PMA_detectSize($last_cumulative_size, $last_cumulative_type, $curr_type
} }
} }
/** /**
* The last cumlative type was DECIMAL * The last cumulative type was DECIMAL
*/ */
elseif ($last_cumulative_type == DECIMAL) { elseif ($last_cumulative_type == DECIMAL) {
$size = PMA_getDecimalSize($cell); $size = PMA_getDecimalSize($cell);
@@ -603,9 +605,9 @@ function PMA_detectSize($last_cumulative_size, $last_cumulative_type, $curr_type
} }
} }
/** /**
* The last cumlative type was INT * The last cumulative type was BIGINT or INT
*/ */
elseif ($last_cumulative_type == INT) { elseif ($last_cumulative_type == BIGINT || $last_cumulative_type == INT) {
/* Convert $last_cumulative_size from int to decimal format */ /* Convert $last_cumulative_size from int to decimal format */
$size = PMA_getDecimalSize($cell); $size = PMA_getDecimalSize($cell);
@@ -636,11 +638,11 @@ function PMA_detectSize($last_cumulative_size, $last_cumulative_type, $curr_type
} }
} }
/** /**
* What to do if the current cell is of type INT * What to do if the current cell is of type BIGINT or INT
*/ */
elseif ($curr_type == INT) { elseif ($curr_type == BIGINT || $curr_type == INT) {
/** /**
* The last cumlative type was VARCHAR * The last cumulative type was VARCHAR
*/ */
if ($last_cumulative_type == VARCHAR) { if ($last_cumulative_type == VARCHAR) {
if ($curr_size >= $last_cumulative_size) { if ($curr_size >= $last_cumulative_size) {
@@ -650,7 +652,7 @@ function PMA_detectSize($last_cumulative_size, $last_cumulative_type, $curr_type
} }
} }
/** /**
* The last cumlative type was DECIMAL * The last cumulative type was DECIMAL
*/ */
elseif ($last_cumulative_type == DECIMAL) { elseif ($last_cumulative_type == DECIMAL) {
$oldM = PMA_getM($last_cumulative_size); $oldM = PMA_getM($last_cumulative_size);
@@ -668,9 +670,9 @@ function PMA_detectSize($last_cumulative_size, $last_cumulative_type, $curr_type
} }
} }
/** /**
* The last cumlative type was INT * The last cumulative type was BIGINT or INT
*/ */
elseif ($last_cumulative_type == INT) { elseif ($last_cumulative_type == BIGINT || $last_cumulative_type == INT) {
if ($curr_size >= $last_cumulative_size) { if ($curr_size >= $last_cumulative_size) {
return $curr_size; return $curr_size;
} else { } else {
@@ -714,6 +716,7 @@ function PMA_detectSize($last_cumulative_size, $last_cumulative_type, $curr_type
* @access public * @access public
* *
* @uses DECIMAL * @uses DECIMAL
* @uses BIGINT
* @uses INT * @uses INT
* @uses VARCHAR * @uses VARCHAR
* @uses NONE * @uses NONE
@@ -721,13 +724,13 @@ function PMA_detectSize($last_cumulative_size, $last_cumulative_type, $curr_type
* @uses strcmp() * @uses strcmp()
* @uses strpos() * @uses strpos()
* @uses substr_count() * @uses substr_count()
* @param int $last_cumulative_type Last cumulative column type (VARCHAR or INT or DECIMAL or NONE) * @param int $last_cumulative_type Last cumulative column type (VARCHAR or INT or BIGINT or DECIMAL or NONE)
* @param string &$cell String representation of the cell for which a best-fit type is to be determined * @param string &$cell String representation of the cell for which a best-fit type is to be determined
* @return int The MySQL type representation (VARCHAR or INT or DECIMAL or NONE) * @return int The MySQL type representation (VARCHAR or INT or BIGINT or DECIMAL or NONE)
*/ */
function PMA_detectType($last_cumulative_type, &$cell) { function PMA_detectType($last_cumulative_type, &$cell) {
/** /**
* If numeric, determine if decimal or int * If numeric, determine if decimal, int or bigint
* Else, we call it varchar for simplicity * Else, we call it varchar for simplicity
*/ */
@@ -741,7 +744,11 @@ function PMA_detectType($last_cumulative_type, &$cell) {
if ($cell == (string)(float)$cell && strpos($cell, ".") !== false && substr_count($cell, ".") == 1) { if ($cell == (string)(float)$cell && strpos($cell, ".") !== false && substr_count($cell, ".") == 1) {
return DECIMAL; return DECIMAL;
} else { } else {
return INT; if ($cell > 2147483647) {
return BIGINT;
} else {
return INT;
}
} }
} else { } else {
return VARCHAR; return VARCHAR;
@@ -764,6 +771,7 @@ function PMA_detectType($last_cumulative_type, &$cell) {
* @uses ROWS * @uses ROWS
* @uses VARCHAR * @uses VARCHAR
* @uses DECIMAL * @uses DECIMAL
* @uses BIGINT
* @uses INT * @uses INT
* @uses NONE * @uses NONE
* @uses count() * @uses count()
@@ -808,21 +816,25 @@ function PMA_analyzeTable(&$table) {
$sizes[$i] = PMA_detectSize($sizes[$i], $types[$i], $curr_type, $table[ROWS][$j][$i]); $sizes[$i] = PMA_detectSize($sizes[$i], $types[$i], $curr_type, $table[ROWS][$j][$i]);
/** /**
* If a type for this column has alreday been delcared, * If a type for this column has already been declared,
* only alter it if it was a number and a varchar was found * only alter it if it was a number and a varchar was found
*/ */
if ($curr_type != NONE) { if ($curr_type != NONE) {
if ($curr_type == VARCHAR) { if ($curr_type == VARCHAR) {
$types[$i] = VARCHAR; $types[$i] = VARCHAR;
} else if ($curr_type == DECIMAL) { } else if ($curr_type == DECIMAL) {
if ($types[$i] != VARCHAR) { if ($types[$i] != VARCHAR) {
$types[$i] = DECIMAL; $types[$i] = DECIMAL;
} }
} else if ($curr_type == BIGINT) {
if ($types[$i] != VARCHAR && $types[$i] != DECIMAL) {
$types[$i] = BIGINT;
}
} else if ($curr_type == INT) { } else if ($curr_type == INT) {
if ($types[$i] != VARCHAR && $types[$i] != DECIMAL) { if ($types[$i] != VARCHAR && $types[$i] != DECIMAL && $types[$i] != BIGINT) {
$types[$i] = INT; $types[$i] = INT;
} }
} }
} }
} }
} }
@@ -952,7 +964,7 @@ function PMA_buildSQL($db_name, &$tables, &$analyses = NULL, &$additional_sql =
} }
if ($analyses != NULL) { if ($analyses != NULL) {
$type_array = array(NONE => "NULL", VARCHAR => "varchar", INT => "int", DECIMAL => "decimal"); $type_array = array(NONE => "NULL", VARCHAR => "varchar", INT => "int", DECIMAL => "decimal", BIGINT => "bigint");
/* TODO: Do more checking here to make sure they really are matched */ /* TODO: Do more checking here to make sure they really are matched */
if (count($tables) != count($analyses)) { if (count($tables) != count($analyses)) {