optimized a bit

This commit is contained in:
Loïc Chapeaux
2001-09-09 16:45:11 +00:00
parent 138da505eb
commit 37b7c5ece7

View File

@@ -22,12 +22,11 @@ mysql_select_db($db);
* The form used to define the structure of the table has been submitted * The form used to define the structure of the table has been submitted
*/ */
if (isset($submit)) { if (isset($submit)) {
if (!isset($query)) { $sql_query = $query_cpy = '';
$query = '';
}
// Builds the fields creation statements // Builds the fields creation statements
for ($i = 0; $i < count($field_name); $i++) { $fields_cnt = count($field_name);
for ($i = 0; $i < $fields_cnt; $i++) {
if (empty($field_name[$i])) { if (empty($field_name[$i])) {
continue; continue;
} }
@@ -37,7 +36,7 @@ if (isset($submit)) {
if (MYSQL_INT_VERSION < 32306) { if (MYSQL_INT_VERSION < 32306) {
check_reserved_words($field_name[$i]); check_reserved_words($field_name[$i]);
} }
$query .= backquote($field_name[$i]) . ' ' . $field_type[$i]; $query = backquote($field_name[$i]) . ' ' . $field_type[$i];
if ($field_length[$i] != '') { if ($field_length[$i] != '') {
if (get_magic_quotes_gpc()) { if (get_magic_quotes_gpc()) {
$query .= '(' . stripslashes($field_length[$i]) . ')'; $query .= '(' . stripslashes($field_length[$i]) . ')';
@@ -65,17 +64,18 @@ if (isset($submit)) {
} else { } else {
$query .= ', '; $query .= ', ';
} }
$sql_query .= $query;
$query_cpy .= "\n" . ' ' . $query;
} // end for } // end for
$query = ereg_replace(', $', '', $query); unset($fields_cnt);
unset($query);
$sql_query = ereg_replace(', $', '', $sql_query);
$query_cpy = ereg_replace(', $', '', $query_cpy);
// Builds the primary keys statements // Builds the primary keys statements
if (!isset($primary)) { $primary = '';
$primary = ''; $primary_cnt = (isset($field_primary) ? count($field_primary) : 0);
} for ($i = 0; $i < $primary_cnt; $i++) {
if (!isset($field_primary)) {
$field_primary = array();
}
for ($i = 0; $i < count($field_primary); $i++) {
$j = $field_primary[$i]; $j = $field_primary[$i];
if (!empty($field_name[$j])) { if (!empty($field_name[$j])) {
if (get_magic_quotes_gpc()) { if (get_magic_quotes_gpc()) {
@@ -84,40 +84,38 @@ if (isset($submit)) {
$primary .= backquote($field_name[$j]) . ', '; $primary .= backquote($field_name[$j]) . ', ';
} }
} // end for } // end for
unset($primary_cnt);
$primary = ereg_replace(', $', '', $primary); $primary = ereg_replace(', $', '', $primary);
if (!empty($primary)) { if (!empty($primary)) {
$primary = ', PRIMARY KEY (' . $primary . ')'; $sql_query .= ', PRIMARY KEY (' . $primary . ')';
$query_cpy .= ',' . "\n" . ' PRIMARY KEY (' . $primary . ')';
} }
unset($primary);
// Builds the indexes statements // Builds the indexes statements
if (!isset($index)) { $index = '';
$index = ''; $index_cnt = (isset($field_index) ? count($field_index) : 0);
} for ($i = 0;$i < $index_cnt; $i++) {
if (!isset($field_index)) {
$field_index = array();
}
for ($i = 0;$i < count($field_index); $i++) {
$j = $field_index[$i]; $j = $field_index[$i];
if (!empty($field_name[$j])) { if (!empty($field_name[$j])) {
if (get_magic_quotes_gpc()) { if (get_magic_quotes_gpc()) {
$field_name[$j] = stripslashes($field_name[$j]); $field_name[$j] = stripslashes($field_name[$j]);
} }
$index .= backquote($field_name[$j]) . ', '; $index .= backquote($field_name[$j]) . ', ';
} }
} // end for } // end for
unset($index_cnt);
$index = ereg_replace(', $', '', $index); $index = ereg_replace(', $', '', $index);
if (!empty($index)) { if (!empty($index)) {
$index = ', INDEX (' . $index . ')'; $sql_query .= ', INDEX (' . $index . ')';
$query_cpy .= ',' . "\n" . ' INDEX (' . $index . ')';
} }
unset($index);
// Builds the uniques statements // Builds the uniques statements
if (!isset($unique)) { $unique = '';
$unique = ''; $unique_cnt = (isset($field_unique) ? count($field_unique) : 0);
} for ($i = 0; $i < $unique_cnt; $i++) {
if (!isset($field_unique)) {
$field_unique = array();
}
for ($i = 0; $i < count($field_unique); $i++) {
$j = $field_unique[$i]; $j = $field_unique[$i];
if (!empty($field_name[$j])) { if (!empty($field_name[$j])) {
if (get_magic_quotes_gpc()) { if (get_magic_quotes_gpc()) {
@@ -126,19 +124,18 @@ if (isset($submit)) {
$unique .= backquote($field_name[$j]) . ', '; $unique .= backquote($field_name[$j]) . ', ';
} }
} // end for } // end for
unset($unique_cnt);
$unique = ereg_replace(', $', '', $unique); $unique = ereg_replace(', $', '', $unique);
if (!empty($unique)) { if (!empty($unique)) {
$unique = ', UNIQUE (' . $unique . ')'; $sql_query .= ', UNIQUE (' . $unique . ')';
$query_cpy .= ',' . "\n" . ' UNIQUE (' . $unique . ')';
} }
unset($unique);
// Builds the fulltextes statements // Builds the fulltextes statements
if (!isset($fulltext)) { $fulltext = '';
$fulltext = ''; $fulltext_cnt = (isset($field_fulltext) ? count($field_fulltext) : 0);
} for ($i = 0; $i < $fulltext_cnt; $i++) {
if (!isset($field_fulltext) || MYSQL_INT_VERSION < 32323) {
$field_fulltext = array();
}
for ($i = 0; $i < count($field_fulltext); $i++) {
$j = $field_fulltext[$i]; $j = $field_fulltext[$i];
if (!empty($field_name[$j])) { if (!empty($field_name[$j])) {
if (get_magic_quotes_gpc()) { if (get_magic_quotes_gpc()) {
@@ -147,32 +144,36 @@ if (isset($submit)) {
$fulltext .= backquote($field_name[$j]) . ', '; $fulltext .= backquote($field_name[$j]) . ', ';
} }
} // end for } // end for
unset($field_fulltext);
$fulltext = ereg_replace(', $', '', $fulltext); $fulltext = ereg_replace(', $', '', $fulltext);
if (!empty($fulltext)) { if (!empty($fulltext)) {
$fulltext = ', FULLTEXT (' . $fulltext . ')'; $sql_query .= ', FULLTEXT (' . $fulltext . ')';
$query_cpy .= ',' . "\n" . ' FULLTEXT (' . $fulltext . ')';
} }
unset($fulltext);
$query_keys = $primary . $index . $unique . $fulltext;
$query_keys = ereg_replace(', $', '', $query_keys);
// Builds the 'create table' statement // Builds the 'create table' statement
$sql_query = 'CREATE TABLE ' . backquote($table) . ' (' $sql_query = 'CREATE TABLE ' . backquote($table) . ' (' . $sql_query . ')';
. $query . ' ' $query_cpy = 'CREATE TABLE ' . backquote($table) . ' (' . $query_cpy . "\n" . ')';
. $query_keys . ')';
// Adds table type (2 May 2001 - Robbat2) // Adds table type and comments (2 May 2001 - Robbat2)
if (!empty($tbl_type) && ($tbl_type != 'Default')) { if (!empty($tbl_type) && ($tbl_type != 'Default')) {
$sql_query .= ' TYPE = ' . $tbl_type; $sql_query .= ' TYPE = ' . $tbl_type;
$query_cpy .= ' TYPE = ' . $tbl_type;
} }
if (MYSQL_INT_VERSION >= 32300 && !empty($comment)) { if (MYSQL_INT_VERSION >= 32300 && !empty($comment)) {
if (get_magic_quotes_gpc()) { if (get_magic_quotes_gpc()) {
$comment = stripslashes($comment); $comment = stripslashes($comment);
} }
$sql_query .= ' comment = \'' . sql_addslashes($comment) . '\''; $sql_query .= ' COMMENT = \'' . sql_addslashes($comment) . '\'';
$query_cpy .= "\n" . 'COMMENT = \'' . sql_addslashes($comment) . '\'';
} }
// Executes the query // Executes the query
$result = mysql_query($sql_query) or mysql_die(); $result = mysql_query($sql_query) or mysql_die();
$message = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenCreated; $sql_query = $query_cpy . ';';
unset($query_cpy);
$message = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenCreated;
include('./tbl_properties.php3'); include('./tbl_properties.php3');
exit(); exit();
} // end do create table } // end do create table