[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/admin/xmldb/actions/test/ -> test.class.php (source)

   1  <?php // $Id: test.class.php,v 1.39.2.1 2008/05/18 23:34:50 stronk7 Exp $
   2  
   3  ///////////////////////////////////////////////////////////////////////////
   4  //                                                                       //
   5  // NOTICE OF COPYRIGHT                                                   //
   6  //                                                                       //
   7  // Moodle - Modular Object-Oriented Dynamic Learning Environment         //
   8  //          http://moodle.com                                            //
   9  //                                                                       //
  10  // Copyright (C) 1999 onwards Martin Dougiamas        http://dougiamas.com  //
  11  //           (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com  //
  12  //                                                                       //
  13  // This program is free software; you can redistribute it and/or modify  //
  14  // it under the terms of the GNU General Public License as published by  //
  15  // the Free Software Foundation; either version 2 of the License, or     //
  16  // (at your option) any later version.                                   //
  17  //                                                                       //
  18  // This program is distributed in the hope that it will be useful,       //
  19  // but WITHOUT ANY WARRANTY; without even the implied warranty of        //
  20  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
  21  // GNU General Public License for more details:                          //
  22  //                                                                       //
  23  //          http://www.gnu.org/copyleft/gpl.html                         //
  24  //                                                                       //
  25  ///////////////////////////////////////////////////////////////////////////
  26  
  27  /// This class will perform one full test of all the available DDL
  28  /// functions under your DB
  29  
  30  class test extends XMLDBAction {
  31  
  32      /**
  33       * Init method, every subclass will have its own
  34       */
  35      function init() {
  36          parent::init();
  37  
  38      /// Set own custom attributes
  39  
  40      /// Get needed strings
  41          $this->loadStrings(array(
  42              'back' => 'xmldb'
  43          ));
  44      }
  45  
  46      /**
  47       * Invoke method, every class will have its own
  48       * returns true/false on completion, setting both
  49       * errormsg and output as necessary
  50       */
  51      function invoke() {
  52          parent::invoke();
  53  
  54          $result = true;
  55  
  56      /// Set own core attributes
  57          //$this->does_generate = ACTION_NONE;
  58          $this->does_generate = ACTION_GENERATE_HTML;
  59  
  60      /// These are always here
  61          global $CFG, $XMLDB, $db;
  62  
  63      /// ADD YOUR CODE HERE
  64          require_once ($CFG->libdir . '/ddllib.php');
  65  
  66      /// Where all the tests will be stored
  67          $tests = array();
  68  
  69      /// The back to edit table button
  70          $b = ' <p class="centerpara buttons">';
  71          $b .= '<a href="index.php">[' . $this->str['back'] . ']</a>';
  72          $b .= '</p>';
  73          $o = $b;
  74  
  75      /// Silenty drop any previous test tables
  76          $table = new XMLDBTable('testtable');
  77          if (table_exists($table)) {
  78              $status = drop_table($table, true, false);
  79          }
  80          $table = new XMLDBTable ('anothertest');
  81          if (table_exists($table)) {
  82              $status = drop_table($table, true, false);
  83          }
  84          $table = new XMLDBTable ('newnameforthetable');
  85          if (table_exists($table)) {
  86              $status = drop_table($table, true, false);
  87          }
  88  
  89      /// 1st test. Complete table creation.
  90          $table = new XMLDBTable('testtable');
  91          $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
  92          $table->addFieldInfo('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
  93          $table->addFieldInfo('type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general');
  94          $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null);
  95          $table->addFieldInfo('intro', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null);
  96          $table->addFieldInfo('logo', XMLDB_TYPE_BINARY, 'big', null, XMLDB_NOTNULL, null, null, null);
  97          $table->addFieldInfo('assessed', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
  98          $table->addFieldInfo('assesstimestart', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
  99          $table->addFieldInfo('assesstimefinish', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
 100          $table->addFieldInfo('scale', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
 101          $table->addFieldInfo('maxbytes', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
 102          $table->addFieldInfo('forcesubscribe', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
 103          $table->addFieldInfo('trackingtype', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1');
 104          $table->addFieldInfo('rsstype', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
 105          $table->addFieldInfo('rssarticles', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
 106          $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
 107          $table->addFieldInfo('grade', XMLDB_TYPE_NUMBER, '20,0', XMLDB_UNSIGNED, null, null, null, null, null);
 108          $table->addFieldInfo('percent', XMLDB_TYPE_NUMBER, '5,2', null, null, null, null, null, null);
 109          $table->addFieldInfo('warnafter', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
 110          $table->addFieldInfo('blockafter', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
 111          $table->addFieldInfo('blockperiod', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
 112          $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
 113          $table->addKeyInfo('type-name', XMLDB_KEY_UNIQUE, array('type', 'name'));
 114          $table->addIndexInfo('course', XMLDB_INDEX_NOTUNIQUE, array('course'));
 115          $table->addIndexInfo('rsstype', XMLDB_INDEX_UNIQUE, array('rsstype'));
 116  
 117          $table->setComment("This is a test'n drop table. You can drop it safely");
 118  
 119      /// Get SQL code and execute it
 120          $test = new stdClass;
 121          $test->sql = $table->getCreateTableSQL($CFG->dbtype, $CFG->prefix, true);
 122          $test->status = create_table($table, false, false);
 123          if (!$test->status) {
 124              $test->error = $db->ErrorMsg();
 125          }
 126          $tests['create table'] = $test;
 127  
 128      /// 2nd test. drop table
 129          if ($test->status) {
 130          /// Get SQL code and execute it
 131              $test = new stdClass;
 132              $test->sql = $table->getDropTableSQL($CFG->dbtype, $CFG->prefix, true);
 133              $test->status = drop_table($table, false, false);
 134              if (!$test->status) {
 135                  $test->error = $db->ErrorMsg();
 136              }
 137              $tests['drop table'] = $test;
 138          }
 139  
 140      /// 3rd test. creating another, smaller table
 141          if ($test->status) {
 142              $table = new XMLDBTable ('anothertest');
 143              $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
 144              $table->addFieldInfo('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
 145              $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '30', null, null, null, null, null, 'Moodle');
 146              $table->addFieldInfo('secondname', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, null);
 147              $table->addFieldInfo('intro', XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null, null, null);
 148              $table->addFieldInfo('avatar', XMLDB_TYPE_BINARY, 'medium', null, null, null, null, null, null);
 149              $table->addFieldInfo('grade', XMLDB_TYPE_NUMBER, '20,10', null, null, null, null, null);
 150              $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
 151          /// Get SQL code and execute it
 152              $test = new stdClass;
 153              $test->sql = $table->getCreateTableSQL($CFG->dbtype, $CFG->prefix, true);
 154              $test->status = create_table($table, false, false);
 155              if (!$test->status) {
 156                  $test->error = $db->ErrorMsg();
 157              }
 158              $tests['create table - 2'] = $test;
 159          }
 160  
 161      /// Insert two records to do the work with real data
 162          $rec->course = 1;
 163          $rec->name = 'Martin';
 164          $rec->secondname = 'Dougiamas';
 165          $rec->intro = 'The creator of Moodle';
 166          $rec->grade = 10.0001;
 167          insert_record('anothertest', $rec);
 168          $rec->course = 2;
 169          $rec->name = 'Eloy';
 170          $rec->secondname = 'Lafuente';
 171          $rec->intro = 'One poor developer';
 172          $rec->grade = 9.99;
 173          insert_record('anothertest', $rec);
 174  
 175      /// 4th test. Adding one complex enum field
 176          if ($test->status) {
 177          /// Create a new field with complex specs (enums are good candidates)
 178              $field = new XMLDBField('type');
 179              $field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general', 'course');
 180          /// Get SQL code and execute it
 181              $test = new stdClass;
 182              $test->sql = $table->getAddFieldSQL($CFG->dbtype, $CFG->prefix, $field, true);
 183              $test->status = add_field($table, $field, false, false);
 184              if (!$test->status) {
 185                  $test->error = $db->ErrorMsg();
 186              }
 187              $tests['add enum field'] = $test;
 188          }
 189  
 190      /// 5th test. Dropping one complex enum field
 191          if ($test->status) {
 192          /// Create a new field with complex specs (enums are good candidates)
 193              $test = new stdClass;
 194              $test->sql = $table->getDropFieldSQL($CFG->dbtype, $CFG->prefix, $field, true);
 195              $test->status = drop_field($table, $field, false, false);
 196              if (!$test->status) {
 197                  $test->error = $db->ErrorMsg();
 198              }
 199              $tests['drop enum field'] = $test;
 200          }
 201  
 202      /// 6th test. Adding one complex enum field
 203          if ($test->status) {
 204          /// Create a new field with complex specs (enums are good candidates)
 205              $field = new XMLDBField('type');
 206              $field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general', 'course');
 207          /// Get SQL code and execute it
 208              $test = new stdClass;
 209              $test->sql = $table->getAddFieldSQL($CFG->dbtype, $CFG->prefix, $field, true);
 210              $test->status = add_field($table, $field, false, false);
 211              if (!$test->status) {
 212                  $test->error = $db->ErrorMsg();
 213              }
 214              $tests['add enum field again'] = $test;
 215          }
 216  
 217      /// 7th test. Adding one numeric field
 218          if ($test->status) {
 219          /// Create a new field (numeric)
 220              $field = new XMLDBField('onenumber');
 221              $field->setAttributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, 0, 'type');
 222          /// Get SQL code and execute it
 223              $test = new stdClass;
 224              $test->sql = $table->getAddFieldSQL($CFG->dbtype, $CFG->prefix, $field, true);
 225              $test->status = add_field($table, $field, false, false);
 226              if (!$test->status) {
 227                  $test->error = $db->ErrorMsg();
 228              }
 229              $tests['add numeric field'] = $test;
 230          }
 231  
 232      /// 8th test. Dropping one complex enum field
 233          if ($test->status) {
 234          /// Create a new field with complex specs (enums are good candidates)
 235              $field = new XMLDBField('type');
 236              $test = new stdClass;
 237              $test->sql = $table->getDropFieldSQL($CFG->dbtype, $CFG->prefix, $field, true);
 238              $test->status = drop_field($table, $field, false, false);
 239              if (!$test->status) {
 240                  $test->error = $db->ErrorMsg();
 241              }
 242              $tests['drop enum field again'] = $test;
 243          }
 244  
 245      /// 9th test. Change the type of one column from integer to varchar
 246          if ($test->status) {
 247          /// Get SQL code and execute it
 248              $test = new stdClass;
 249              $field = new XMLDBField('course');
 250              $field->setAttributes(XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, '0');
 251  
 252              $test->sql = $table->getAlterFieldSQL($CFG->dbtype, $CFG->prefix, $field, true);
 253              $test->status = change_field_type($table, $field, false, false);
 254              if (!$test->status) {
 255                  $test->error = $db->ErrorMsg();
 256              }
 257              $tests['change field type (int2char)'] = $test;
 258          }
 259  
 260      /// 10th test. Change the type of one column from varchar to integer
 261          if ($test->status) {
 262          /// Get SQL code and execute it
 263              $test = new stdClass;
 264              $field = new XMLDBField('course');
 265              $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
 266  
 267              $test->sql = $table->getAlterFieldSQL($CFG->dbtype, $CFG->prefix, $field, true);
 268              $test->status = change_field_type($table, $field, false, false);
 269              if (!$test->status) {
 270                  $test->error = $db->ErrorMsg();
 271              }
 272              $tests['change field type (char2int)'] = $test;
 273          }
 274  
 275      /// 11th test. Change the type of one column from number to varchar
 276          if ($test->status) {
 277          /// Get SQL code and execute it
 278              $test = new stdClass;
 279              $field = new XMLDBField('grade');
 280              $field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, "test'n drop");
 281  
 282              $test->sql = $table->getAlterFieldSQL($CFG->dbtype, $CFG->prefix, $field, true);
 283              $test->status = change_field_type($table, $field, false, false);
 284              if (!$test->status) {
 285                  $test->error = $db->ErrorMsg();
 286              }
 287              $tests['change field type (number2char)'] = $test;
 288          }
 289  
 290      /// 12th test. Change the type of one column from varchar to float
 291          if ($test->status) {
 292          /// Get SQL code and execute it
 293              $test = new stdClass;
 294              $field = new XMLDBField('grade');
 295              $field->setAttributes(XMLDB_TYPE_FLOAT, '20,10', XMLDB_UNSIGNED, null, null, null, null, null);
 296  
 297              $test->sql = $table->getAlterFieldSQL($CFG->dbtype, $CFG->prefix, $field, true);
 298              $test->status = change_field_type($table, $field, false, false);
 299              if (!$test->status) {
 300                  $test->error = $db->ErrorMsg();
 301              }
 302              $tests['change field type (char2float)'] = $test;
 303          }
 304  
 305      /// 13th test. Change the type of one column from float to char
 306          if ($test->status) {
 307          /// Get SQL code and execute it
 308              $test = new stdClass;
 309              $field = new XMLDBField('grade');
 310              $field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, 'test');
 311  
 312              $test->sql = $table->getAlterFieldSQL($CFG->dbtype, $CFG->prefix, $field, true);
 313              $test->status = change_field_type($table, $field, false, false);
 314              if (!$test->status) {
 315                  $test->error = $db->ErrorMsg();
 316              }
 317              $tests['change field type (float2char)'] = $test;
 318          }
 319  
 320      /// 14th test. Change the type of one column from char to number
 321          if ($test->status) {
 322          /// Get SQL code and execute it
 323              $test = new stdClass;
 324              $field = new XMLDBField('grade');
 325              $field->setAttributes(XMLDB_TYPE_NUMBER, '20,10', XMLDB_UNSIGNED, null, null, null, null, null);
 326  
 327              $test->sql = $table->getAlterFieldSQL($CFG->dbtype, $CFG->prefix, $field, true);
 328              $test->status = change_field_type($table, $field, false, false);
 329              if (!$test->status) {
 330                  $test->error = $db->ErrorMsg();
 331              }
 332              $tests['change field type (char2number)'] = $test;
 333          }
 334  
 335  
 336      /// 15th test. Change the precision of one text field
 337          if ($test->status) {
 338          /// Get SQL code and execute it
 339              $test = new stdClass;
 340              $field = new XMLDBField('intro');
 341              $field->setAttributes(XMLDB_TYPE_TEXT, 'big', null, XMLDB_NOTNULL, null, null, null, null);
 342  
 343              $test->sql = $table->getAlterFieldSQL($CFG->dbtype, $CFG->prefix, $field, true);
 344              $test->status = change_field_precision($table, $field, false, false);
 345              if (!$test->status) {
 346                  $test->error = $db->ErrorMsg();
 347              }
 348              $tests['change field precision (text)'] = $test;
 349          }
 350  
 351      /// 16th test. Change the precision of one char field
 352          if ($test->status) {
 353          /// Get SQL code and execute it
 354              $test = new stdClass;
 355              $field = new XMLDBField('secondname');
 356              $field->setAttributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, null, null);
 357  
 358              $test->sql = $table->getAlterFieldSQL($CFG->dbtype, $CFG->prefix, $field, true);
 359              $test->status = change_field_precision($table, $field, false, false);
 360              if (!$test->status) {
 361                  $test->error = $db->ErrorMsg();
 362              }
 363              $tests['change field precision (char)'] = $test;
 364          }
 365  
 366      /// 17th test. Change the precision of one numeric field
 367          if ($test->status) {
 368          /// Get SQL code and execute it
 369              $test = new stdClass;
 370              $field = new XMLDBField('grade');
 371              $field->setAttributes(XMLDB_TYPE_NUMBER, '10,2', null, null, null, null, null, null);
 372  
 373              $test->sql = $table->getAlterFieldSQL($CFG->dbtype, $CFG->prefix, $field, true);
 374              $test->status = change_field_precision($table, $field, false, false);
 375              if (!$test->status) {
 376                  $test->error = $db->ErrorMsg();
 377              }
 378              $tests['change field precision (number)'] = $test;
 379          }
 380  
 381      /// 18th test. Change the precision of one integer field to a smaller one
 382          if ($test->status) {
 383          /// Get SQL code and execute it
 384              $test = new stdClass;
 385              $field = new XMLDBField('course');
 386              $field->setAttributes(XMLDB_TYPE_INTEGER, '5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
 387  
 388              $test->sql = $table->getAlterFieldSQL($CFG->dbtype, $CFG->prefix, $field, true);
 389              $test->status = change_field_precision($table, $field, false, false);
 390              if (!$test->status) {
 391                  $test->error = $db->ErrorMsg();
 392              }
 393              $tests['change field precision (integer) to smaller one'] = $test;
 394          }
 395  
 396      /// 19th test. Change the sign of one numeric field to unsigned
 397          if ($test->status) {
 398          /// Get SQL code and execute it
 399              $test = new stdClass;
 400              $field = new XMLDBField('grade');
 401              $field->setAttributes(XMLDB_TYPE_NUMBER, '10,2', XMLDB_UNSIGNED, null, null, null, null, null);
 402  
 403              $test->sql = $table->getAlterFieldSQL($CFG->dbtype, $CFG->prefix, $field, true);
 404              $test->status = change_field_unsigned($table, $field, false, false);
 405              if (!$test->status) {
 406                  $test->error = $db->ErrorMsg();
 407              }
 408              $tests['change field sign (unsigned)'] = $test;
 409          }
 410  
 411      /// 20th test. Change the sign of one numeric field to signed
 412          if ($test->status) {
 413          /// Get SQL code and execute it
 414              $test = new stdClass;
 415              $field = new XMLDBField('grade');
 416              $field->setAttributes(XMLDB_TYPE_NUMBER, '10,2', null, null, null, null, null, null);
 417  
 418              $test->sql = $table->getAlterFieldSQL($CFG->dbtype, $CFG->prefix, $field, true);
 419              $test->status = change_field_unsigned($table, $field, false, false);
 420              if (!$test->status) {
 421                  $test->error = $db->ErrorMsg();
 422              }
 423              $tests['change field sign (signed)'] = $test;
 424          }
 425  
 426      /// 21th test. Change the nullability of one char field to not null
 427          if ($test->status) {
 428          /// Get SQL code and execute it
 429              $test = new stdClass;
 430              $field = new XMLDBField('name');
 431              $field->setAttributes(XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, 'Moodle');
 432  
 433              $test->sql = $table->getAlterFieldSQL($CFG->dbtype, $CFG->prefix, $field, true);
 434              $test->status = change_field_notnull($table, $field, false, false);
 435              if (!$test->status) {
 436                  $test->error = $db->ErrorMsg();
 437              }
 438              $tests['change field nullability (not null)'] = $test;
 439          }
 440  
 441      /// 22th test. Change the nullability of one char field to null
 442          if ($test->status) {
 443          /// Get SQL code and execute it
 444              $test = new stdClass;
 445              $field = new XMLDBField('name');
 446              $field->setAttributes(XMLDB_TYPE_CHAR, '30', null, null, null, null, null, 'Moodle');
 447  
 448              $test->sql = $table->getAlterFieldSQL($CFG->dbtype, $CFG->prefix, $field, true);
 449              $test->status = change_field_notnull($table, $field, false, false);
 450              if (!$test->status) {
 451                  $test->error = $db->ErrorMsg();
 452              }
 453              $tests['change field nullability (null)'] = $test;
 454          }
 455  
 456      /// 23th test. Dropping the default of one field
 457          if ($test->status) {
 458          /// Get SQL code and execute it
 459              $test = new stdClass;
 460              $field = new XMLDBField('name');
 461              $field->setAttributes(XMLDB_TYPE_CHAR, '30', null, null, null, null, null, null);
 462  
 463              $test->sql = $table->getModifyDefaultSQL($CFG->dbtype, $CFG->prefix, $field, true);
 464              $test->status = change_field_default($table, $field, false, false);
 465              if (!$test->status) {
 466                  $test->error = $db->ErrorMsg();
 467              }
 468              $tests['drop field default of NULL field'] = $test;
 469          }
 470  
 471      /// 24th test. Creating the default for one field
 472          if ($test->status) {
 473          /// Get SQL code and execute it
 474              $test = new stdClass;
 475              $field = new XMLDBField('name');
 476              $field->setAttributes(XMLDB_TYPE_CHAR, '30', null, null, null, null, null, 'Moodle');
 477  
 478              $test->sql = $table->getModifyDefaultSQL($CFG->dbtype, $CFG->prefix, $field, true);
 479              $test->status = change_field_default($table, $field, false, false);
 480              if (!$test->status) {
 481                  $test->error = $db->ErrorMsg();
 482              }
 483              $tests['add field default of NULL field'] = $test;
 484          }
 485  
 486      /// 25th test. Creating the default for one field
 487          if ($test->status) {
 488          /// Get SQL code and execute it
 489              $test = new stdClass;
 490              $field = new XMLDBField('secondname');
 491              $field->setAttributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, null, 'Moodle2');
 492  
 493              $test->sql = $table->getModifyDefaultSQL($CFG->dbtype, $CFG->prefix, $field, true);
 494              $test->status = change_field_default($table, $field, false, false);
 495              if (!$test->status) {
 496                  $test->error = $db->ErrorMsg();
 497              }
 498              $tests['add field default of NOT NULL field'] = $test;
 499          }
 500  
 501  
 502      /// 26th test. Dropping the default of one NOT NULL field
 503          if ($test->status) {
 504          /// Get SQL code and execute it
 505              $test = new stdClass;
 506              $field = new XMLDBField('secondname');
 507              $field->setAttributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, null, null);
 508  
 509              $test->sql = $table->getModifyDefaultSQL($CFG->dbtype, $CFG->prefix, $field, true);
 510              $test->status = change_field_default($table, $field, false, false);
 511              if (!$test->status) {
 512                  $test->error = $db->ErrorMsg();
 513              }
 514              $tests['drop field default of NOT NULL field'] = $test;
 515          }
 516  
 517      /// 27th test. Adding one unique index to the table
 518          if ($test->status) {
 519          /// Get SQL code and execute it
 520              $test = new stdClass;
 521              $index = new XMLDBIndex('secondname');
 522              $index->setAttributes(XMLDB_INDEX_UNIQUE, array('name', 'secondname', 'grade'));
 523  
 524              $test->sql = $table->getAddIndexSQL($CFG->dbtype, $CFG->prefix, $index, true);
 525              $test->status = add_index($table, $index, false, false);
 526              if (!$test->status) {
 527                  $test->error = $db->ErrorMsg();
 528              }
 529              $tests['add unique index'] = $test;
 530          }
 531  
 532      /// 28th test. Adding one not unique index to the table
 533          if ($test->status) {
 534          /// Get SQL code and execute it
 535              $test = new stdClass;
 536              $index = new XMLDBIndex('secondname');
 537              $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('course', 'name'));
 538  
 539              $test->sql = $table->getAddIndexSQL($CFG->dbtype, $CFG->prefix, $index, true);
 540              $test->status = add_index($table, $index, false, false);
 541              if (!$test->status) {
 542                  $test->error = $db->ErrorMsg();
 543              }
 544              $tests['add not unique index'] = $test;
 545          }
 546  
 547      /// 29th test. Re-add the same index than previous test. Check find_index_name() works.
 548          if ($test->status) {
 549          /// Get SQL code and execute it
 550              $test = new stdClass;
 551              $index = new XMLDBIndex('secondname');
 552              $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('name', 'course'));
 553  
 554              if ($indexfound = find_index_name($table, $index)) {
 555                  $test->status = true;
 556                  $test->sql = array();
 557              } else {
 558                  $test->status = true;
 559                  $test->error = 'Index not found!';
 560                  $test->sql = array();
 561              }
 562  
 563              $tests['check find_index_name()'] = $test;
 564          }
 565  
 566      /// 30th test. Dropping one index from the table
 567          if ($test->status) {
 568          /// Get SQL code and execute it
 569              $test = new stdClass;
 570              $index = new XMLDBIndex('name');
 571              $index->setAttributes(XMLDB_INDEX_UNIQUE, array('name', 'grade', 'secondname'));
 572  
 573              $test->sql = $table->getDropIndexSQL($CFG->dbtype, $CFG->prefix, $index, true);
 574              $test->status = drop_index($table, $index, false, false);
 575              if (!$test->status) {
 576                  $test->error = $db->ErrorMsg();
 577              }
 578              $tests['drop index'] = $test;
 579          }
 580  
 581      /// 31th test. Adding one unique key to the table
 582          if ($test->status) {
 583          /// Get SQL code and execute it
 584              $test = new stdClass;
 585              $key = new XMLDBKey('id-course-grade');
 586              $key->setAttributes(XMLDB_KEY_UNIQUE, array('id', 'course', 'grade'));
 587  
 588              $test->sql = $table->getAddKeySQL($CFG->dbtype, $CFG->prefix, $key, true);
 589              $test->status = add_key($table, $key, false, false);
 590              if (!$test->status) {
 591                  $test->error = $db->ErrorMsg();
 592              }
 593              $tests['add unique key'] = $test;
 594          }
 595  
 596      /// 32th test. Adding one foreign+unique key to the table
 597          if ($test->status) {
 598          /// Get SQL code and execute it
 599              $test = new stdClass;
 600              $key = new XMLDBKey('course');
 601              $key->setAttributes(XMLDB_KEY_FOREIGN_UNIQUE, array('course'), 'anothertest', array('id'));
 602  
 603              $test->sql = $table->getAddKeySQL($CFG->dbtype, $CFG->prefix, $key, true);
 604              $test->status = add_key($table, $key, false, false);
 605              if (!$test->status) {
 606                  $test->error = $db->ErrorMsg();
 607              }
 608              $tests['add foreign+unique key'] = $test;
 609          }
 610  
 611      /// 33th test. Drop one key
 612          if ($test->status) {
 613          /// Get SQL code and execute it
 614              $test = new stdClass;
 615              $key = new XMLDBKey('course');
 616              $key->setAttributes(XMLDB_KEY_FOREIGN_UNIQUE, array('course'), 'anothertest', array('id'));
 617  
 618              $test->sql = $table->getDropKeySQL($CFG->dbtype, $CFG->prefix, $key, true);
 619              $test->status = drop_key($table, $key, false, false);
 620              if (!$test->status) {
 621                  $test->error = $db->ErrorMsg();
 622              }
 623              $tests['drop foreign+unique key'] = $test;
 624          }
 625  
 626      /// 34th test. Adding one foreign key to the table
 627          if ($test->status) {
 628          /// Get SQL code and execute it
 629              $test = new stdClass;
 630              $key = new XMLDBKey('course');
 631              $key->setAttributes(XMLDB_KEY_FOREIGN, array('course'), 'anothertest', array('id'));
 632  
 633              $test->sql = $table->getAddKeySQL($CFG->dbtype, $CFG->prefix, $key, true);
 634              $test->status = add_key($table, $key, false, false);
 635              if (!$test->status) {
 636                  $test->error = $db->ErrorMsg();
 637              }
 638              $tests['add foreign key'] = $test;
 639          }
 640  
 641      /// 35th test. Drop one foreign key
 642          if ($test->status) {
 643          /// Get SQL code and execute it
 644              $test = new stdClass;
 645              $key = new XMLDBKey('course');
 646              $key->setAttributes(XMLDB_KEY_FOREIGN, array('course'), 'anothertest', array('id'));
 647  
 648              $test->sql = $table->getDropKeySQL($CFG->dbtype, $CFG->prefix, $key, true);
 649              $test->status = drop_key($table, $key, false, false);
 650              if (!$test->status) {
 651                  $test->error = $db->ErrorMsg();
 652              }
 653              $tests['drop foreign key'] = $test;
 654          }
 655  
 656      /// 36th test. Adding one complex enum field
 657          if ($test->status) {
 658          /// Create a new field with complex specs (enums are good candidates)
 659              $field = new XMLDBField('type');
 660              $field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general', 'course');
 661          /// Get SQL code and execute it
 662              $test = new stdClass;
 663              $test->sql = $table->getAddFieldSQL($CFG->dbtype, $CFG->prefix, $field, true);
 664              $test->status = add_field($table, $field, false, false);
 665              if (!$test->status) {
 666                  $test->error = $db->ErrorMsg();
 667              }
 668              $tests['add field with enum'] = $test;
 669          }
 670  
 671      /// 37th test. Dropping the enum of one field
 672          if ($test->status) {
 673          /// Get SQL code and execute it
 674              $test = new stdClass;
 675              $field = new XMLDBField('type');
 676              $field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, 'general', 'course');
 677  
 678              $test->sql = $table->getModifyEnumSQL($CFG->dbtype, $CFG->prefix, $field, true);
 679              $test->status = change_field_enum($table, $field, false, false);
 680              if (!$test->status) {
 681                  $test->error = $db->ErrorMsg();
 682              }
 683              $tests['delete enumlist from one field'] = $test;
 684          }
 685  
 686      /// 38th test. Creating the enum for one field
 687          if ($test->status) {
 688          /// Get SQL code and execute it
 689              $test = new stdClass;
 690              $field = new XMLDBField('type');
 691              $field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general', 'course');
 692              $test->sql = $table->getModifyEnumSQL($CFG->dbtype, $CFG->prefix, $field, true);
 693              $test->status = change_field_enum($table, $field, false, false);
 694              if (!$test->status) {
 695                  $test->error = $db->ErrorMsg();
 696              }
 697              $tests['add enumlist to one field'] = $test;
 698          }
 699  
 700      /// 39th test. Renaming one index
 701          if ($test->status) {
 702          /// Get SQL code and execute it
 703              $test = new stdClass;
 704              $index = new XMLDBIndex('anyname');
 705              $index->setAttributes(XMLDB_INDEX_UNIQUE, array('name', 'course'));
 706  
 707              $test->sql = $table->getRenameIndexSQL($CFG->dbtype, $CFG->prefix, $index, 'newnamefortheindex', true);
 708              $test->status = rename_index($table, $index, 'newnamefortheindex', false, false);
 709              if (!$test->status) {
 710                  $test->error = $db->ErrorMsg();
 711              }
 712              $tests['rename index (experimental. DO NOT USE IT)'] = $test;
 713          }
 714  
 715      /// 40th test. Renaming one key
 716          if ($test->status) {
 717          /// Get SQL code and execute it
 718              $test = new stdClass;
 719              $key = new XMLDBKey('anyname');
 720              $key->setAttributes(XMLDB_KEY_UNIQUE, array('id', 'course', 'grade'));
 721  
 722              $test->sql = $table->getRenameKeySQL($CFG->dbtype, $CFG->prefix, $key, 'newnameforthekey', true);
 723              $test->status = rename_key($table, $key, 'newnameforthekey', false, false);
 724              if (!$test->status) {
 725                  $test->error = $db->ErrorMsg();
 726              }
 727              $tests['rename key (experimental. DO NOT USE IT)'] = $test;
 728          }
 729  
 730      /// 41th test. Renaming one field
 731          if ($test->status) {
 732          /// Get SQL code and execute it
 733              $test = new stdClass;
 734              $field = new XMLDBField('type');
 735              $field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general', 'course');
 736  
 737              $test->sql = $table->getRenameFieldSQL($CFG->dbtype, $CFG->prefix, $field, 'newnameforthefield', true);
 738              $test->status = rename_field($table, $field, 'newnameforthefield', false, false);
 739              if (!$test->status) {
 740                  $test->error = $db->ErrorMsg();
 741              }
 742              $tests['rename field'] = $test;
 743          }
 744  
 745      /// 42th test. Renaming one table
 746          if ($test->status) {
 747          /// Get SQL code and execute it
 748              $test = new stdClass;
 749  
 750              $test->sql = $table->getRenameTableSQL($CFG->dbtype, $CFG->prefix, 'newnameforthetable', true);
 751              $test->status = rename_table($table, 'newnameforthetable', false, false);
 752              if (!$test->status) {
 753                  $test->error = $db->ErrorMsg();
 754              }
 755              $tests['rename table'] = $test;
 756          }
 757  
 758      /// 43th test. Add enum to field containing enum
 759          if ($test->status) {
 760          /// Add enum to field containing enum
 761              $table->setName('newnameforthetable');
 762              $field = new XMLDBField('newnameforthefield');
 763              $field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'), 'general', 'course');
 764          /// Get SQL code and execute it
 765              $test = new stdClass;
 766              $test->sql = $table->getModifyEnumSQL($CFG->dbtype, $CFG->prefix, $field, true);
 767              $test->status = change_field_enum($table, $field, false, false);
 768          /// Let's see if the constraint exists to alter results
 769              if (check_constraint_exists($table, $field)) {
 770                  $test->sql = array('Nothing executed. Enum already exists. Correct.');
 771              } else {
 772                  $test->status = false;
 773              }
 774              if (!$test->status) {
 775                  $test->error = $db->ErrorMsg();
 776              }
 777              $tests['add enum to field containing enum'] = $test;
 778          }
 779  
 780      /// 44th test. Drop enum from field containing enum
 781          if ($test->status) {
 782          /// Drop enum from field containing enum
 783              $table->setName('newnameforthetable');
 784              $field = new XMLDBField('newnameforthefield');
 785              $field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, 'general', 'course');
 786          /// Get SQL code and execute it
 787              $test = new stdClass;
 788              $test->sql = $table->getModifyEnumSQL($CFG->dbtype, $CFG->prefix, $field, true);
 789              $test->status = change_field_enum($table, $field, false, false);
 790              if (!$test->status) {
 791                  $test->error = $db->ErrorMsg();
 792              }
 793              $tests['drop enum from field containing enum'] = $test;
 794          }
 795  
 796      /// 45th test. Drop enum from field not containing enum
 797          if ($test->status) {
 798          /// Drop enum from field not containing enum
 799              $table->setName('newnameforthetable');
 800              $field = new XMLDBField('newnameforthefield');
 801              $field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, 'general', 'course');
 802          /// Get SQL code and execute it
 803              $test = new stdClass;
 804              $test->sql = $table->getModifyEnumSQL($CFG->dbtype, $CFG->prefix, $field, true);
 805              $test->status = change_field_enum($table, $field, false, false);
 806          /// Let's see if the constraint exists to alter results
 807              if (!check_constraint_exists($table, $field)) {
 808                  $test->sql = array('Nothing executed. Enum does not exists. Correct.');
 809              } else {
 810                  $test->status = false;
 811              }
 812              if (!$test->status) {
 813                  $test->error = $db->ErrorMsg();
 814              }
 815              $tests['drop enum from field not containing enum'] = $test;
 816          }
 817  
 818      /// 46th test. Getting the PK sequence name for one table
 819          if ($test->status) {
 820              $test = new stdClass;
 821              $test->sql =  array(find_sequence_name($table));
 822              $test->status = find_sequence_name($table);
 823              if (!$test->status) {
 824                  if (!$test->error = $db->ErrorMsg()) { //If no db errors, result is ok. Just the driver doesn't support this
 825                      $test->sql = array('Not needed for this DB. Correct.');
 826                      $test->status = true;
 827                  }
 828              }
 829              $tests['find sequence name'] = $test;
 830          }
 831  
 832      /// 47th test. Inserting TEXT contents
 833          $textlib = textlib_get_instance();
 834          if ($test->status) {
 835              $test = new stdClass;
 836              $test->status = false;
 837              $test->sql = array();
 838              $basetext = "\\ ''語 • Русский • Deutsch • English • Español • Français • Italiano • Nederlands • Polski • Português • Svenska • العربية • فارسی 한국어 • עברית • ไทย中文  Ελληνικά • Български • Српски • Українська • Bosanski • Català • Česky • Dansk • Eesti • Simple English • Esperanto • Euskara • Galego • Hrvatski • Ido • Bahasa Indonesia • Íslenska • Lëtzebuergesch • Lietuvių • Magyar • Bahasa Melayu اردو • ئۇيغۇرچه • हिन्दी • नेपाल भाषा मराठी • தமிழ் Հայերեն • Беларуская • Чăваш • Ирон æвзаг • Македонски • Сибирской говор • Afrikaans • Aragonés • Arpitan • Asturianu • Kreyòl Ayisyen • Azərbaycan • Bân-lâm-gú • Basa Banyumasan • Brezhoneg • Corsu • Cymraeg • Deitsch • Føroyskt • Frysk • Furlan • Gaeilge • Gàidhlig • Ilokano • Interlingua • Basa Jawa • Kapampangan • Kernewek • Kurdî  كوردی • Ladino  לאדינו • Latina • Latviešu • Limburgs • Lumbaart • Nedersaksisch • Nouormand • Occitan • O‘zbek • Piemontèis • Plattdüütsch • Ripoarisch • Sámegiella • Scots • Shqip • Sicilianu • Sinugboanon • Srpskohrvatski / Српскохрватски • Basa Sunda • Kiswahili • Tagalog • Tatarça • Walon • Winaray  Авар • Башҡорт • Кыргызча  Монгол • Қазақша • Тоҷикӣ • Удмурт • Armãneashce • Bamanankan • Eald Englisc • Gaelg • Interlingue • Kaszëbsczi • Kongo • Ligure • Lingála • lojban • Malagasy • Malti • Māori • Nāhuatl • Ekakairũ Naoero • Novial • Pangasinán • Tok Pisin • Romani / रोमानी • Rumantsch • Runa Simi • Sardu • Tetun • Türkmen / تركمن / Туркмен • Vèneto • Volapük • Võro • West-Vlaoms • Wollof • Zazaki • Žemaitėška";
 839          /// Create one big text (1.500.000 chars)
 840              $fulltext = '';
 841              for ($i=0; $i<1000; $i++) { //1500 * 1000 chars
 842                  $fulltext .= $basetext;
 843              }
 844  
 845          /// Build the record to insert
 846              $rec->intro = addslashes($fulltext);
 847              $rec->name = 'texttest';
 848          /// Calculate its length
 849              $textlen = $textlib->strlen($fulltext);
 850              if ($rec->id = insert_record('newnameforthetable', $rec)) {
 851                  if ($new = get_record('newnameforthetable', 'id', $rec->id)) {
 852                      delete_records('newnameforthetable', 'id', $new->id);
 853                      $newtextlen = $textlib->strlen($new->intro);
 854                      if ($fulltext === $new->intro) {
 855                          $test->sql = array($newtextlen . ' cc. (text) sent and received ok');
 856                          $test->status = true;
 857                      } else {
 858                          $test->error = $db->ErrorMsg();
 859                          $test->sql = array($newtextlen . ' cc. (text) transfer failed. Data changed!');
 860                          $test->status = false;
 861                      }
 862                  } else {
 863                      $test->error = $db->ErrorMsg();
 864                  }
 865              } else {
 866                  $test->error = $db->ErrorMsg();
 867              }
 868              $tests['insert record '. $textlen . ' cc. (text)'] = $test;
 869          }
 870  
 871      /// 48th test. Inserting BINARY contents
 872          if ($test->status) {
 873              $test = new stdClass;
 874              $test->status = false;
 875          /// Build the record to insert
 876              $rec->avatar = addslashes($fulltext);
 877              $rec->name = 'binarytest';
 878          /// Calculate its length
 879              $textlen = strlen($fulltext);
 880              if ($rec->id = insert_record('newnameforthetable', $rec)) {
 881                  if ($new = get_record('newnameforthetable', 'id', $rec->id)) {
 882                      $newtextlen = strlen($new->avatar);
 883                      if ($fulltext === $new->avatar) {
 884                          $test->sql = array($newtextlen . ' bytes (binary) sent and received ok');
 885                          $test->status = true;
 886                      } else {
 887                          $test->error = $db->ErrorMsg();
 888                          $test->sql = array($newtextlen . ' bytes (binary) transfer failed. Data changed!');
 889                          $test->status = false;
 890                      }
 891                  } else {
 892                      $test->error = $db->ErrorMsg();
 893                  }
 894              } else {
 895                  $test->error = $db->ErrorMsg();
 896              }
 897              $tests['insert record '. $textlen . ' bytes (binary)'] = $test;
 898          }
 899  
 900      /// 49th test. update_record with TEXT and BINARY contents
 901          if ($test->status) {
 902              $test = new stdClass;
 903              $test->status = false;
 904              $test->sql = array();
 905          /// Build the record to insert
 906              $rec->intro = addslashes($basetext);
 907              $rec->avatar = addslashes($basetext);
 908              $rec->name = 'updatelobs';
 909          /// Calculate its length
 910              $textlen = $textlib->strlen($basetext);
 911              $imglen = strlen($basetext);
 912              if (update_record('newnameforthetable', $rec)) {
 913                  if ($new = get_record('newnameforthetable', 'id', $rec->id)) {
 914                      $newtextlen = $textlib->strlen($new->intro);
 915                      $newimglen = strlen($new->avatar);
 916                      if ($basetext === $new->avatar && $basetext === $new->intro) {
 917                          $test->sql = array($newtextlen . ' cc. (text) sent and received ok',
 918                                             $newimglen . ' bytes (binary) sent and received ok');
 919                          $test->status = true;
 920                      } else {
 921                          if ($rec->avatar !== $new->avatar) {
 922                              $test->error = $db->ErrorMsg();
 923                              $test->sql = array($newimglen . ' bytes (binary) transfer failed. Data changed!');
 924                              $test->status = false;
 925                          } else {
 926                              $test->error = $db->ErrorMsg();
 927                              $test->sql = array($newtextlen . ' cc. (text) transfer failed. Data changed!');
 928                              $test->status = false;
 929                          }
 930                      }
 931                  } else {
 932                      $test->error = $db->ErrorMsg();
 933                  }
 934              } else {
 935                  $test->error = $db->ErrorMsg();
 936              }
 937              $tests['update record '. $textlen . ' cc. (text) and ' . $imglen . ' bytes (binary)'] = $test;
 938          }
 939  
 940      /// 50th test. set_field with TEXT contents
 941          if ($test->status) {
 942              $test = new stdClass;
 943              $test->status = false;
 944              $test->sql = array();
 945          /// Build the record to insert
 946              $rec->intro = addslashes($fulltext);
 947              $rec->name = 'updatelobs';
 948          /// Calculate its length
 949              $textlen = $textlib->strlen($fulltext);
 950              if (set_field('newnameforthetable', 'intro', $rec->intro, 'name', $rec->name)) {
 951                  if ($new = get_record('newnameforthetable', 'id', $rec->id)) {
 952                      $newtextlen = $textlib->strlen($new->intro);
 953                      if ($fulltext === $new->intro) {
 954                          $test->sql = array($newtextlen . ' cc. (text) sent and received ok');
 955                          $test->status = true;
 956                      } else {
 957                          $test->error = $db->ErrorMsg();
 958                          $test->sql = array($newtextlen . ' cc. (text) transfer failed. Data changed!');
 959                          $test->status = false;
 960                      }
 961                  } else {
 962                      $test->error = $db->ErrorMsg();
 963                  }
 964              } else {
 965                  $test->error = $db->ErrorMsg();
 966              }
 967              $tests['set field '. $textlen . ' cc. (text)'] = $test;
 968          }
 969  
 970      /// 51th test. set_field with BINARY contents
 971          if ($test->status) {
 972              $test = new stdClass;
 973              $test->status = false;
 974              $test->sql = array();
 975          /// Build the record to insert
 976              $rec->avatar = addslashes($fulltext);
 977              $rec->name = 'updatelobs';
 978          /// Calculate its length
 979              $textlen = strlen($fulltext);
 980              if (set_field('newnameforthetable', 'avatar', $rec->avatar, 'name', $rec->name)) {
 981                  if ($new = get_record('newnameforthetable', 'id', $rec->id)) {
 982                      $newtextlen = strlen($new->avatar);
 983                      if ($fulltext === $new->avatar) {
 984                          $test->sql = array($newtextlen . ' bytes (binary) sent and received ok');
 985                          $test->status = true;
 986                      } else {
 987                          $test->error = $db->ErrorMsg();
 988                          $test->sql = array($newtextlen . ' bytes (binary) transfer failed. Data changed!');
 989                          $test->status = false;
 990                      }
 991                  } else {
 992                      $test->error = $db->ErrorMsg();
 993                  }
 994              } else {
 995                  $test->error = $db->ErrorMsg();
 996              }
 997              $tests['set field '. $textlen . ' bytes (binary)'] = $test;
 998          }
 999  
1000      /// TODO: Check here values of the inserted records to see that everything ha the correct value
1001  
1002  
1003      /// Iterate over tests, showing information as needed
1004          $o .= '<ol>';
1005          foreach ($tests as $key => $test) {
1006              $o .= '<li>' . $key . ($test->status ? '<font color="green"> Ok</font>' : ' <font color="red">Error</font>');
1007              if (!$test->status) {
1008                  $o .= '<br/><font color="red">' . $test->error . '</font>';
1009              }
1010              $o .= '<pre>' . implode('<br/>', $test->sql) . '</pre>';
1011              $o .= '</li>';
1012          }
1013          $o .= '</ol>';
1014  
1015          $this->output = $o;
1016  
1017      /// Launch postaction if exists (leave this here!)
1018          if ($this->getPostAction() && $result) {
1019              return $this->launch($this->getPostAction());
1020          }
1021      /// Return ok if arrived here
1022          return $result;
1023      }
1024  }
1025  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7