original_string: public function validateDefinition(xmldb_table $xmldb_table=null) {
          if (!$xmldb_table) {
              return 'Invalid xmldb_index->validateDefinition() call, $xmldb_table is required.';
          }
  
          $total = 0;
          foreach ($this->getFields() as $fieldname) {
              if (!$field = $xmldb_table->getField($fieldname)) {
                  // argh, we do not have the fields loaded yet, this should not happen during install
                  continue;
              }
  
              switch ($field->getType()) {
                  case XMLDB_TYPE_INTEGER:
                      $total += 8; // big int
                      break;
  
                  case XMLDB_TYPE_NUMBER:
                      $total += 12; // this is just a guess
                      break;
  
                  case XMLDB_TYPE_FLOAT:
                      $total += 8; // double precision
                      break;
  
                  case XMLDB_TYPE_CHAR:
                      if ($field->getLength() > self::INDEX_MAX_BYTES / 3) {
                          return 'Invalid index definition in table {'.$xmldb_table->getName(). '}: XMLDB_TYPE_CHAR field "'.$field->getName().'" can not be indexed because it is too long.'
                                  .' Limit is '.(self::INDEX_MAX_BYTES/3).' chars.';
                      }
                      $total += ($field->getLength() * 3); // the most complex utf-8 chars have 3 bytes
                      break;
  
                  case XMLDB_TYPE_TEXT:
                      return 'Invalid index definition in table {'.$xmldb_table->getName(). '}: XMLDB_TYPE_TEXT field "'.$field->getName().'" can not be indexed';
                      break;
  
                  case XMLDB_TYPE_BINARY:
                      return 'Invalid index definition in table {'.$xmldb_table->getName(). '}: XMLDB_TYPE_BINARY field "'.$field->getName().'" can not be indexed';
                      break;
  
                  case XMLDB_TYPE_DATETIME:
                      $total += 8; // this is just a guess
                      break;
  
                  case XMLDB_TYPE_TIMESTAMP:
                      $total += 8; // this is just a guess
                      break;
              }
          }
  
          if ($total > self::INDEX_COMPOSED_MAX_BYTES) {
              return 'Invalid index definition in table {'.$xmldb_table->getName(). '}: the composed index on fields "'.implode(',', $this->getFields()).'" is too long.'
                      .' Limit is '.self::INDEX_COMPOSED_MAX_BYTES.' bytes / '.(self::INDEX_COMPOSED_MAX_BYTES/3).' chars.';
          }
  
          return null;
      }
code: public function validateDefinition(xmldb_table $xmldb_table=null) {
          if (!$xmldb_table) {
              return 'Invalid xmldb_index->validateDefinition() call, $xmldb_table is required.';
          }
  
          $total = 0;
          foreach ($this->getFields() as $fieldname) {
              if (!$field = $xmldb_table->getField($fieldname)) {
                  // argh, we do not have the fields loaded yet, this should not happen during install
                  continue;
              }
  
              switch ($field->getType()) {
                  case XMLDB_TYPE_INTEGER:
                      $total += 8; // big int
                      break;
  
                  case XMLDB_TYPE_NUMBER:
                      $total += 12; // this is just a guess
                      break;
  
                  case XMLDB_TYPE_FLOAT:
                      $total += 8; // double precision
                      break;
  
                  case XMLDB_TYPE_CHAR:
                      if ($field->getLength() > self::INDEX_MAX_BYTES / 3) {
                          return 'Invalid index definition in table {'.$xmldb_table->getName(). '}: XMLDB_TYPE_CHAR field "'.$field->getName().'" can not be indexed because it is too long.'
                                  .' Limit is '.(self::INDEX_MAX_BYTES/3).' chars.';
                      }
                      $total += ($field->getLength() * 3); // the most complex utf-8 chars have 3 bytes
                      break;
  
                  case XMLDB_TYPE_TEXT:
                      return 'Invalid index definition in table {'.$xmldb_table->getName(). '}: XMLDB_TYPE_TEXT field "'.$field->getName().'" can not be indexed';
                      break;
  
                  case XMLDB_TYPE_BINARY:
                      return 'Invalid index definition in table {'.$xmldb_table->getName(). '}: XMLDB_TYPE_BINARY field "'.$field->getName().'" can not be indexed';
                      break;
  
                  case XMLDB_TYPE_DATETIME:
                      $total += 8; // this is just a guess
                      break;
  
                  case XMLDB_TYPE_TIMESTAMP:
                      $total += 8; // this is just a guess
                      break;
              }
          }
  
          if ($total > self::INDEX_COMPOSED_MAX_BYTES) {
              return 'Invalid index definition in table {'.$xmldb_table->getName(). '}: the composed index on fields "'.implode(',', $this->getFields()).'" is too long.'
                      .' Limit is '.self::INDEX_COMPOSED_MAX_BYTES.' bytes / '.(self::INDEX_COMPOSED_MAX_BYTES/3).' chars.';
          }
  
          return null;
      }
code_tokens: public function validateDefinition ( xmldb_table $ xmldb_table = null ) { if ( ! $ xmldb_table ) { return 'Invalid xmldb_index->validateDefinition() call, $xmldb_table is required.' ; } $ total = 0 ; foreach ( $ this -> getFields ( ) as $ fieldname ) { if ( ! $ field = $ xmldb_table -> getField ( $ fieldname ) ) { // argh, we do not have the fields loaded yet, this should not happen during install continue ; } switch ( $ field -> getType ( ) ) { case XMLDB_TYPE_INTEGER : $ total += 8 ; // big int break ; case XMLDB_TYPE_NUMBER : $ total += 12 ; // this is just a guess break ; case XMLDB_TYPE_FLOAT : $ total += 8 ; // double precision break ; case XMLDB_TYPE_CHAR : if ( $ field -> getLength ( ) > self :: INDEX_MAX_BYTES / 3 ) { return 'Invalid index definition in table {' . $ xmldb_table -> getName ( ) . '}: XMLDB_TYPE_CHAR field "' . $ field -> getName ( ) . '" can not be indexed because it is too long.' . ' Limit is ' . ( self :: INDEX_MAX_BYTES / 3 ) . ' chars.' ; } $ total += ( $ field -> getLength ( ) * 3 ) ; // the most complex utf-8 chars have 3 bytes break ; case XMLDB_TYPE_TEXT : return 'Invalid index definition in table {' . $ xmldb_table -> getName ( ) . '}: XMLDB_TYPE_TEXT field "' . $ field -> getName ( ) . '" can not be indexed' ; break ; case XMLDB_TYPE_BINARY : return 'Invalid index definition in table {' . $ xmldb_table -> getName ( ) . '}: XMLDB_TYPE_BINARY field "' . $ field -> getName ( ) . '" can not be indexed' ; break ; case XMLDB_TYPE_DATETIME : $ total += 8 ; // this is just a guess break ; case XMLDB_TYPE_TIMESTAMP : $ total += 8 ; // this is just a guess break ; } } if ( $ total > self :: INDEX_COMPOSED_MAX_BYTES ) { return 'Invalid index definition in table {' . $ xmldb_table -> getName ( ) . '}: the composed index on fields "' . implode ( ',' , $ this -> getFields ( ) ) . '" is too long.' . ' Limit is ' . self :: INDEX_COMPOSED_MAX_BYTES . ' bytes / ' . ( self :: INDEX_COMPOSED_MAX_BYTES / 3 ) . ' chars.' ; } return null ; }
docstring: Validates the index restrictions.
  
  The error message should not be localised because it is intended for developers,
  end users and admins should never see these problems!
  
  @param xmldb_table $xmldb_table optional when object is table
  @return string null if ok, error message if problem found
docstring_tokens: Validates the index restrictions .