Skip to content

Commit

Permalink
MDL-31985 remove LOB sizes from code and UI
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Mar 11, 2012
1 parent 05aae0a commit f13489d
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 93 deletions.
10 changes: 8 additions & 2 deletions admin/tool/xmldb/actions/edit_field/edit_field.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,28 +75,33 @@ function transformForm(event) {
switch (typeField.value) {
case '1': // XMLDB_TYPE_INTEGER
lengthTip.innerHTML = ' 1...20';
lengthField.disabled = false;
decimalsTip.innerHTML = '';
decimalsField.disabled = true;
decimalsField.value = '';
break;
case '2': // XMLDB_TYPE_NUMBER
lengthTip.innerHTML = ' 1...20';
lengthField.disabled = false;
decimalsTip.innerHTML = ' 0...length or empty';
break;
case '3': // XMLDB_TYPE_FLOAT
lengthTip.innerHTML = ' 1...20 or empty';
lengthField.disabled = false;
decimalsTip.innerHTML = ' 0...length or empty';
break;
case '4': // XMLDB_TYPE_CHAR
lengthTip.innerHTML = ' 1...1333'; // Hardcoded, yes!
lengthField.disabled = false;
decimalsTip.innerHTML = '';
decimalsField.disabled = true;
decimalsField.value = '';
sequenceField.disabled = true;
sequenceField.value = '0';
break;
case '5': // XMLDB_TYPE_TEXT
lengthTip.innerHTML = ' small, medium, big';
lengthTip.innerHTML = '';
lengthField.disabled = true;
decimalsTip.innerHTML = '';
decimalsField.disabled = true;
decimalsField.value = '';
Expand All @@ -106,7 +111,8 @@ function transformForm(event) {
defaultField.value = '';
break;
case '6': // XMLDB_TYPE_BINARY
lengthTip.innerHTML = ' small, medium, big';
lengthTip.innerHTML = '';
lengthField.disabled = true;
decimalsTip.innerHTML = '';
decimalsField.disabled = true;
decimalsField.value = '';
Expand Down
26 changes: 2 additions & 24 deletions admin/tool/xmldb/actions/edit_field_save/edit_field_save.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ function init() {
'numberincorrectlength' => 'tool_xmldb',
'floatincorrectlength' => 'tool_xmldb',
'charincorrectlength' => 'tool_xmldb',
'textincorrectlength' => 'tool_xmldb',
'binaryincorrectlength' => 'tool_xmldb',
'numberincorrectdecimals' => 'tool_xmldb',
'floatincorrectdecimals' => 'tool_xmldb',
'defaultincorrect' => 'tool_xmldb',
Expand Down Expand Up @@ -201,28 +199,8 @@ function invoke() {
}
}
}
// Text checks
if ($type == XMLDB_TYPE_TEXT) {
if ($length != 'small' &&
$length != 'medium' &&
$length != 'big') {
$errors[] = $this->str['textincorrectlength'];
}
if ($default !== NULL && $default !== '') {
if (substr($default, 0, 1) == "'" ||
substr($default, -1, 1) == "'") {
$errors[] = $this->str['defaultincorrect'];
}
}
}
// Binary checks
if ($type == XMLDB_TYPE_BINARY) {
if ($length != 'small' &&
$length != 'medium' &&
$length != 'big') {
$errors[] = $this->str['binaryincorrectlength'];
}
}
// No text checks
// No binary checks

if (!empty($errors)) {
$tempfield = new xmldb_field($name);
Expand Down
2 changes: 0 additions & 2 deletions admin/tool/xmldb/lang/en/tool_xmldb.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
$string['aftertable'] = 'After table:';
$string['back'] = 'Back';
$string['backtomainview'] = 'Back to main';
$string['binaryincorrectlength'] = 'Incorrect length for binary field';
$string['cannotuseidfield'] = 'Cannot insert the "id" field. It is an autonumeric column';
$string['completelogbelow'] = '(see the complete log of the search below)';
$string['confirmdeletefield'] = 'Are you absolutely sure that you want to delete the field:';
Expand Down Expand Up @@ -159,7 +158,6 @@
$string['table'] = 'Table';
$string['tablenameempty'] = 'The table name cannot be empty';
$string['tables'] = 'Tables';
$string['textincorrectlength'] = 'Incorrect length for text field';
$string['unload'] = 'Unload';
$string['up'] = 'Up';
$string['view'] = 'View';
Expand Down
22 changes: 2 additions & 20 deletions lib/ddl/mysql_sql_generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,28 +202,10 @@ public function getTypeSQL($xmldb_type, $xmldb_length=null, $xmldb_decimals=null
$dbtype .= '(' . $xmldb_length . ')';
break;
case XMLDB_TYPE_TEXT:
if (empty($xmldb_length)) {
$xmldb_length = 'small';
}
if ($xmldb_length == 'small') {
$dbtype = 'TEXT';
} else if ($xmldb_length == 'medium') {
$dbtype = 'MEDIUMTEXT';
} else {
$dbtype = 'LONGTEXT';
}
$dbtype = 'LONGTEXT';
break;
case XMLDB_TYPE_BINARY:
if (empty($xmldb_length)) {
$xmldb_length = 'small';
}
if ($xmldb_length == 'small') {
$dbtype = 'BLOB';
} else if ($xmldb_length == 'medium') {
$dbtype = 'MEDIUMBLOB';
} else {
$dbtype = 'LONGBLOB';
}
$dbtype = 'LONGBLOB';
break;
case XMLDB_TYPE_DATETIME:
$dbtype = 'DATETIME';
Expand Down
1 change: 1 addition & 0 deletions lib/xmldb/xmldb.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

<xs:simpleType name="fieldLength" >
<xs:restriction base="xs:string" >
<!-- TODO: Moodle 2.5 - Drop LOB sizes, keep only numbers -->
<xs:pattern value='(\d+)|(small|medium|big)'/>
</xs:restriction >
</xs:simpleType >
Expand Down
54 changes: 10 additions & 44 deletions lib/xmldb/xmldb_field.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function setAttributes($type, $precision=null, $unsigned=null, $notnull=null, $s
* Set all the attributes of one xmldb_field
*
* @param string type XMLDB_TYPE_INTEGER, XMLDB_TYPE_NUMBER, XMLDB_TYPE_CHAR, XMLDB_TYPE_TEXT, XMLDB_TYPE_BINARY
* @param string precision length for integers and chars, two-comma separated numbers for numbers and 'small', 'medium', 'big' for texts and binaries
* @param string precision length for integers and chars, two-comma separated numbers for numbers
* @param string unsigned XMLDB_UNSIGNED or null (or false)
* @param string notnull XMLDB_NOTNULL or null (or false)
* @param string sequence XMLDB_SEQUENCE or null (or false)
Expand All @@ -97,6 +97,11 @@ function set_attributes($type, $precision=null, $unsigned=null, $notnull=null, $
$this->sequence = !empty($sequence) ? true : false;
$this->setDefault($default);

if ($this->type == XMLDB_TYPE_BINARY || $this->type == XMLDB_TYPE_TEXT) {
$this->length = null;
$this->decimals = null;
}

$this->previous = $previous;
}

Expand Down Expand Up @@ -266,19 +271,10 @@ function arr2xmldb_field($xmlarr) {
$result = false;
}
}
/// Check for big, medium, small to be applied to text and binary
/// Remove length from text and binary
if ($this->type == XMLDB_TYPE_TEXT ||
$this->type == XMLDB_TYPE_BINARY) {
if (!$length) {
$length == 'big';
}
if ($length != 'big' &&
$length != 'medium' &&
$length != 'small') {
$this->errormsg = 'Incorrect LENGTH attribute for text and binary fields (only big, medium and small allowed)';
$this->debug($this->errormsg);
$result = false;
}
$length = null;
}
/// Finally, set the length
$this->length = $length;
Expand Down Expand Up @@ -549,36 +545,10 @@ function setFromADOField($adofield) {
$this->length = $adofield->max_length;
}
if ($this->type == XMLDB_TYPE_TEXT) {
switch (strtolower($adofield->type)) {
case 'tinytext':
case 'text':
$this->length = 'small';
break;
case 'mediumtext':
$this->length = 'medium';
break;
case 'longtext':
$this->length = 'big';
break;
default:
$this->length = 'small';
}
$this->length = null;
}
if ($this->type == XMLDB_TYPE_BINARY) {
switch (strtolower($adofield->type)) {
case 'tinyblob':
case 'blob':
$this->length = 'small';
break;
case 'mediumblob':
$this->length = 'medium';
break;
case 'longblob':
$this->length = 'big';
break;
default:
$this->length = 'small';
}
$this->length = null;
}
/// Calculate the decimals of the field
if ($adofield->max_length > 0 &&
Expand Down Expand Up @@ -709,10 +679,6 @@ function readableInfo() {
$o .= ')';
}
}
if ($this->type == XMLDB_TYPE_TEXT ||
$this->type == XMLDB_TYPE_BINARY) {
$o .= ' (' . $this->length . ')';
}
/// not null
if ($this->notnull) {
$o .= ' not null';
Expand Down
2 changes: 1 addition & 1 deletion lib/xmldb/xmldb_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ function addFieldInfo($name, $type, $precision=null, $unsigned=null, $notnull=nu
*
* @param string name name of the field
* @param string type XMLDB_TYPE_INTEGER, XMLDB_TYPE_NUMBER, XMLDB_TYPE_CHAR, XMLDB_TYPE_TEXT, XMLDB_TYPE_BINARY
* @param string precision length for integers and chars, two-comma separated numbers for numbers and 'small', 'medium', 'big' for texts and binaries
* @param string precision length for integers and chars, two-comma separated numbers for numbers
* @param string unsigned XMLDB_UNSIGNED or null (or false)
* @param string notnull XMLDB_NOTNULL or null (or false)
* @param string sequence XMLDB_SEQUENCE or null (or false)
Expand Down

0 comments on commit f13489d

Please sign in to comment.