NAME
DBIx::Table::TestDataGenerator::UniqueConstraint - unique constraint information
DESCRIPTION
This class determines information about unique key constraints defined on the target table, in particular about the primary key.
SUBROUTINES/METHODS
schema
Accessor for the DBIx::Class schema for the target database, required constructor argument.
table
Accessor for target table, required constructor argument.
pkey_col_incrementor
Accessor for the method to be used to increment the primary key column chosen to be incremented, externally read-only.
pkey_col
Accessor for the name of the primary key column to be incremented, externally read-only.
pkey_col_names
Accessor for a reference to an array containing the names of the primary key columns, externally read-only.
type_preference_for_incrementing
Accessor for a reference to an array containing a list of SQL data type names sorted descendingly by the priority in which columns of the corresponding type will get selected for incrementing, externally read-only.
unique_cols_to_incr
Accessor for a reference to an array containing the names of the columns in unique constraints which will be increased for new records, externally read-only.
pkey_is_auto_increment
Accessor which is true if the corresponding primary key column is auto-increment and false otherwise, externally read-only.
BUILD
Arguments: none.
Determines information about the unique constraints on the target table.
unique_columns_with_max
Arguments:
schema: DBIx::Class schema
table: name of target table
handle_pkey: if true, determines information about the primary key constraint, otherwise about the other unique constraints
In case handle_pkey is false, this method returns a hash reference of the following structure:
{
UNIQUE_CONSTR_1 =>
{
DATA_TYPE_1 => [ [ COL_NAME_1, MAX_VAL_1 ], ..., [COL_NAME_N, MAX_VAL_N] ],
DATA_TYPE_2 => [ [ COL_NAME_N+1, MAX_VAL_N+1 ], ..., [COL_NAME_M, MAX_VAL_M] ],
...
}
UNIQUE_CONSTR_2 => {...}
...
}
Here, the keys of the base hash are the names of all uniqueness constraints. For each such constraint, the value of the base hash is another hash having as values all the data types used for columns in the constraint and as values an array reference where each element is a pair (column_name, max_value) where column_name runs over all column names in the constraint and max_value is the corresponding current maximum value. (Please note the comment in the description of get_incrementor on how we currently determine this maximum in case of string data types.)
In case handle_pkey is true, the corresponding information is returned for the primary key constraint, in particular the base hash has only one key as there may be only one primary key constraint:
{
PRIMARY_KEY_NAME =>
{
DATA_TYPE_1 => [ [ COL_NAME_1, MAX_VAL_1 ], ..., [COL_NAME_N, MAX_VAL_N] ],
DATA_TYPE_2 => [ [ COL_NAME_N+1, MAX_VAL_N+1 ], ..., [COL_NAME_M, MAX_VAL_M] ],
...
}
}
get_auto_increment_pkey_col
Arguments:
schema: DBIx::Class schema
table: name of target table
Checks if we have an auto-increment column. If we have one and it is not part of the primary key, we abort, otherwise, pkey_is_auto_increment is set to true.
get_random_pkey_val
This method is for handling an auto-increment primary key column when root nodes have pkey = referenced pkey and the referencing column does not allow null values. Since in this case we define a Row object and use it to retrieve the auto-increment value, i.e. the pkey value is not known beforehand, we need to pass a non-null value for the referencing column. The current method returns a valid temporary value.
AUTHOR
Jose Diaz Seng, <josediazseng at gmx.de>
COPYRIGHT AND LICENSE
Copyright (C) 2012-2013, Jose Diaz Seng.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl 5.10.0. For more details, see the full text of the licenses in the directory LICENSES.
This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.