function chado_validate_custom_table_schema

2.x tripal_core.custom_tables.api.inc chado_validate_custom_table_schema($schema_array)
3.x tripal_chado.custom_tables.api.inc chado_validate_custom_table_schema($schema_array)

This function is used to validate a Drupal Schema API array prior to passing it ot the chado_create_custom_table_schema(). This function can be used in a form validate function or whenver a schema is provided by a user and needs validation.

Parameters

$schema_array: the Drupal Schema API compatible array.

Return value

An empty string for success or a message string for failure.

Related topics

3 calls to chado_validate_custom_table_schema()
tripal_custom_tables_form_validate in tripal_chado/includes/tripal_chado.custom_tables.inc
Implements hook_validate(). Validate the Create/Edit custom table form.
tripal_extensions_form_submit in tripal/includes/tripal.extensions.inc
Process the import buttons.
tripal_mviews_form_validate in tripal_chado/includes/tripal_chado.mviews.inc
Validate the Create/Edit Materialized View Form Implements hook_form_validate().

File

tripal_chado/api/tripal_chado.custom_tables.api.inc, line 255
Provides an API to manage custom tables in Chado.

Code

function chado_validate_custom_table_schema($schema_array) {


  if (is_array($schema_array) and !array_key_exists('table', $schema_array)) {
    return "The schema array must have key named 'table'";
  }

  if (preg_match('/[ABCDEFGHIJKLMNOPQRSTUVWXYZ]/', $schema_array['table'])) {
    return "Postgres will automatically change the table name to lower-case. To prevent unwanted side-effects, please rename the table with all lower-case characters.";
  }


  // Check index length.
  if (array_key_exists('indexes', $schema_array)) {
    foreach ($schema_array['indexes'] as $index_name => $details) {
      if (strlen($schema_array['table'] . '_' . $index_name) > 60) {
        return "One ore more index names appear to be too long. For example: '" . $schema_array['table'] . '_' . $index_name .
          ".'  Index names are created by concatenating the table name with the index name provided " .
          "in the 'indexes' array of the schema. Please alter any indexes that when combined with the table name are " .
          "longer than 60 characters.";
      }
    }
  }

  // Check unique key length.
  if (array_key_exists('unique keys', $schema_array)) {
    foreach ($schema_array['unique keys'] as $index_name => $details) {
      if (strlen($schema_array['table'] . '_' . $index_name) > 60) {
        return "One ore more unique key names appear to be too long. For example: '" . $schema_array['table'] . '_' . $index_name .
          ".'  Unique key names are created by concatenating the table name with the key name provided " .
          "in the 'unique keys' array of the schema. Please alter any unique keys that when combined with the table name are " .
          "longer than 60 characters.";
      }
    }
  }

}