#!/usr/bin/perl
# ----------------------------------------------------------------------------
# This software is Copyright (C) 2007, All Rights Reserved
# ----------------------------------------------------------------------------
# This program is protected by local and international copyright laws. Any
# use of this program is subject to the the terms of the license agreement
# included as part of this distribution archive. Any other uses are strictly
# prohibited without the written permission of the Vendor and all
# other rights are reserved.
# -----------------------------------------------------------------------------
# Warning : Modifying this program violates your license agreement!
# -----------------------------------------------------------------------------

package IT::DB::Globals;
require Exporter;

# This module just creates global aliases variables in all the modules that include
# it.  So if you re-assign $FORM in one module it will be re-assigned in the others

$VERSION   = "1.00";
@EXPORT    = (  '$ACTIVE_LIST_QUERY',
                '$LIST_STOP',
                '$MAX_INT',
                '$MAX_STRING',
                '$MAX_MEMO',
                '$MAX_FIELDNAME_LENGTH',
                '$MAX_TABLENAME_LENGTH',
                '$MAX_TABLE_PREFIX_LENGTH',
                '%VALID_CONNECTION_ATTRIBUTES',
                '%VALID_TABLE_ATTRIBUTES',
                '%VALID_FIELD_ATTRIBUTES',
                '%VALID_FIELD_TYPES',
                '%DB_TYPE_TO_MYSQL_TYPE',
                );
@EXPORT_OK = qw();
@ISA       = qw(Exporter);

use strict;

use vars qw($ACTIVE_LIST_QUERY $LIST_STOP $MINIMUM_DBI_VERSION_REQUIRED
            $MINIMUM_DBD_MYSQL_VERSION_REQUIRED $MINIMUM_MYSQL_VERSION_REQUIRED
            $QUALIFY_WHERE $MAX_INT $MAX_STRING $MAX_MEMO $MAX_FIELDNAME_LENGTH $MAX_TABLE_PREFIX_LENGTH
            $MAX_TABLENAME_LENGTH
            %VALID_CONNECTION_ATTRIBUTES %VALID_TABLE_ATTRIBUTES %VALID_FIELD_ATTRIBUTES %VALID_FIELD_TYPES
            %DB_TYPE_TO_MYSQL_TYPE
            );

# define globals
$ACTIVE_LIST_QUERY                  = 0;              # is a query being executed
$LIST_STOP                          = 0;              # should DB_List* operations be stopped
$MAX_INT                            = 4_294_967_295;
$MAX_STRING                         = 255;
$MAX_MEMO                           = 16_777_215;
$MAX_FIELDNAME_LENGTH               = 50;   # Reference: http://dev.mysql.com/doc/mysql/en/legal-names.html (max is 64)
$MAX_TABLENAME_LENGTH               = 40;   # Reference: http://dev.mysql.com/doc/mysql/en/legal-names.html (max is 64)
$MAX_TABLE_PREFIX_LENGTH            = 10;   # So if max length in mysql is 64 we're still less with 40 + 10 = 50
                                            # NOTE: we add a "-new" suffix when migrating tables, so prefix + name + suffix must be less than 64


%VALID_CONNECTION_ATTRIBUTES = map { $_, 1 } (
  'name', 'engine',                                                                      # all engines
  'hostname', 'port', 'database', 'username', 'password', 'mysqlcompression',            # mySQL only
  'appTablePrefix',                                                                      # used by application (not db layer)
  'disableDatabaseWrites','_allowWritesForCurrentProcessOnly',
);

%VALID_TABLE_ATTRIBUTES = map { $_, 1 } (
  'name', 'connectionName', 'fields', 'defaultSort', 'autoSequencing',
  'appTableDescription', 'appDefaultSearchFields',                      # used by application code
);

%VALID_FIELD_ATTRIBUTES = map { $_, 1 } (
  'name', 'type',                                                            # all engines
  'appDisplayOrder', 'appUserEditable',                                      # used by application code
  'appFieldLabel', 'appFieldType', 'appDisplayOnly', 'appFieldOptions',      # used by application code
  'appFieldValidationRules', 'appFieldSeparator', 'appHiddenField',          # used by application code
  'appCustomFieldType',
);

%VALID_FIELD_TYPES = map { $_, 1 } qw(string memo int);

%DB_TYPE_TO_MYSQL_TYPE = (
  'int'    => 'INT UNSIGNED NOT NULL',
  'string' => 'VARCHAR(255) NOT NULL',
  'memo'   => 'MEDIUMTEXT NOT NULL',
);

# ----------------------------------------------------------------------------
# end of file
1;

