The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

XAO::DO::FS::Glue::Base_MySQL - MySQL specific overrides - base for MySQL_DBI and MySQL drivers

SYNOPSIS

Should not be used directly.

DESCRIPTION

This module implements some functionality required by FS::Glue in MySQL specific way.

METHODS

new ($%)

Creates new instance of the driver connected to the given database using DSN, user and password.

Example:

 my $driver=XAO::Objects->new(objname => 'FS::Glue::MySQL',
                              dsn => 'OS:MySQL_DBI:dbname',
                              user => 'username',
                              password => '123123123');
add_field_integer ($$$$)

Adds new integer field to the given table. First parameter is table name, then field name, then index flag, then unique flag, then minimal value and then maximum value and default value.

Note: Indexes only work with MySQL 3.23 and later.

add_field_real ($$;$$)

Adds new real field to the given table. First parameter is table name, then field name, then index flag, then unique flag, then optional minimal value and then optional maximum value and default value.

Note: Indexes only work with MySQL 3.23 and later.

add_field_text ($$$$$)

Adds new text field to the given table. First is table name, then field name, then index flag, then unique flag, maximum length, default value and 'connected' flag. Depending on maximum length it will create CHAR, TEXT, MEDIUMTEXT or LONGTEXT.

'Connected' flag must be set if that table holds elements deeper into the tree then the top level.

Note: Modifiers 'index' and 'unique' only work with MySQL 3.23 and later.

add_table ($$$)

Creates new empty table with unique_id, key and optionally connector fields.

charset_change_prepare ($)

Prepares an internal structure for a later one-shot modification of charsets in a table.

charset_change_field

Adds a field to the list of things to alter on charset_change_execute()

charset_change_execute

Executes actual SQL collected from charset_change_field()

scale_change_prepare ($)

Prepares an internal structure for a later one-shot modification of scale values in a table.

scale_change_field

Adds a field to the list of things to alter on scale_change_execute()

scale_change_execute

Executes actual SQL collected from scale_change_field()

consistency_checked

Returns true if load_structure() was asked to and performed meta-data consistency checks (SHOW TABLE STATUS, compare requested table_type to on-disk type, table & db version compatibility, etc).

consistency_check_set

If called before load_structure() with a true argument then the load_structure will also check meta-data consistency.

delete_row ($$)

Deletes a row from the given name and unique_id.

disconnect ()

Permanently disconnects driver from database. Normally perl's garbage collector will do that for you.

drop_field ($$$$$)

Drops the given field from the given table in the database. Whatever content was in that field is lost irrevocably.

If index, unique and connected flags are given then it first will drop the appropriate index.

drop_table ($)

Drops the given table with all its data. Whatever content was in that table before is lost irrevocably.

increment_key_seq ($)

Increments the value of key_seq in Global_Fields table identified by the given row unique ID. Returns previous value.

Note: Always executed as a part of some outer level transaction. Does not create any locks or starts transactions.

initialize_database ($)

Removes all data from all tables and creates minimal tables that support objects database.

list_keys ($$$$)

Returns a reference to an array containing all possible values of a given field (list key) in the given table. If connector is given - then it is used in select too.

load_structure ()

Loads Global_Fields and Global_Classes tables into internal hash for use in Glue.

Returns the hash reference.

TODO: This should be changed so that data types would not be hard-coded here. Probably a reference to a subroutine that will parse and store them would do the job?

mangle_field_name ($)

Adds underscore to the end of field name to avoid problems with reserved words. Could do something else in other drivers, do not count on the fact that there would be underscore at the end.

reset ()

Brings driver to usable state. Unlocks tables if they were somehow left in locked state. Reconnects to the database if the connection expired.

retrieve_fields ($$$@)

Retrieves individual fields from the given table by unique ID of the row. Always returns array reference even if there is just one field in it.

search (\%query)

performs a search on the given query and returns a reference to an array of arrays containing search results. Query hash is as prepared by _build_search_query() in the Glue.

search_clause_wq ($field $string)

Returns database specific syntax for REGEX matching a complete word if database supports it or undef otherwise. For MySQL returns REGEXP clause.

search_clause_ws ($field $string)

Returns database specific syntax for REGEX matching the beginning of a word if database supports it or undef otherwise. For MySQL returns REGEXP clause.

store_row ($$$$$$$)

Stores complete row of data into the given table. New name is generated in the given key field if there is no name given.

Example:

 $self->_driver->store_row($table,
                           $key_name,$key_value,
                           $conn_name,$conn_value,
                           \%row);

Connector name and connector value are optional if this list is directly underneath of Global.

text_field_definition

Returns a MySQL definition for the field suitable for use in CREATE TABLE or ALTER TABLE.

Something like "TEXT CHARACTER SET 'charset' NOT NULL DEFAULT ?".

Note that the default needs to be substituted in later!

unique_id ($$$$$)

Looks up row unique ID by given key name and value (required) and connector name and value (optional for top level lists).

update_fields ($$$;$) {

Stores new values. Example:

 $self->_driver->update_field($table,$unique_id,{ name => 'value' });

Optional last argument can be used to disable transactional wrapping if set to a non-zero value.

tr_loc_active ()

Checks if we currently have active local or external transaction.

tr_loc_begin ()

Starts new local transaction. Will only really start it if we do not have currently active external transaction. Does nothing for MyISAM.

tr_loc_commit ()

Commits changes for local transaction if it is active.

tr_loc_rollback ()

Rolls back changes for local transaction if it is active. Called automatically on errors.

tr_ext_active ()

Checks if an external transaction is currently active.

AUTHORS

Copyright (c) 2005 Andrew Maltsev

Copyright (c) 2001-2004 Andrew Maltsev, XAO Inc.

<am@ejelta.com> -- http://ejelta.com/xao/

SEE ALSO

Further reading: XAO::FS, XAO::DO::FS::Glue::SQL_DBI, XAO::DO::FS::Glue.