DB::Object::Mysql::Tables - MySQL Table Object
use DB::Object::Mysql::Tables; my $this = DB::Object::Mysql::Tables->new || die( DB::Object::Mysql::Tables->error, "\n" );
v1.0.1
This is a MySQL table object class.
This will prepare the statement to check the table.
check
Checking table is a query specific to MySQL
MySQL
If called in void context, the resulting statement handler will be executed immediately.
It returns the newly created statement handler.
This creates a table.
It takes some array reference data containing the columns definitions, some optional parameters and a statement handler.
If a statement handler is provided, then no need to provide an array reference of columns definition. The columns definition will be taken from the statement handler. However, at least either one of them needs to be provided to set the columns definition.
Possible parameters are:
Takes the name of another table to inherit from
If provided, this will create a temporary table.
If true, this will enable table oid
If true, this will disable table oid
This will return an error if the table already exists, so best to check beforehand with "exists".
Upon success, it will return the new statement to create the table. However, if "create" is called in void context, then the statement is executed right away and returned.
This returns the create info for the current table object as a string representing the sql script necessary to recreate the table.
This will prepare a drop statement to drop the current table.
If it is called in void context, then the statement is executed immediately and returned, otherwise it is just returned.
It takes no option.
See MySQL documentation for more information
Returns true if the current table exists, or false otherwise.
If no parameter is provided, this will issue the following query LOCK t LOW_PRIORITY WRITE where t is the table name.
LOCK t LOW_PRIORITY WRITE
If one parameter is provided and is an array reference containing the table alias and some lock option, otherwise if the one parameter provided is the lock option. If no lock option is provided this will default to LOW_PRIORITY WRITE.
LOW_PRIORITY WRITE
For example:
$t->lock([ 'n', 'low_priority write' ]);
This will issue the following query:
LOCK TABLE t AS n LOW_PRIORITY WRITE $t->lock( 'low_priority write' );
LOCK TABLE t LOW_PRIORITY WRITE
If the parameters provided is an hash of table name-option pairs, such as:
$t->lock( t1 => ['n' => 'low_priority write'], # alias to n with option t2 => 'low_priority write', # only option );
LOCK TABLES t1 AS n LOW_PRIORITY WRITE, t2 LOW_PRIORITY WRITE
The option can only be:
This will prepare the query to lock the table or tables and return the statement handler. If it is called in void context, the statement handler returned is executed immediately.
See MyQL documentation for more information
my $sth = $t->optimize; # OPTIMIZE TABLE t
This will prepare a query to optimize the table. If it is called in void context, the statement handler returned is executed immediately.
optimize
This return a fully qualified name to be used as a prefix to columns in queries.
Note that in MySQL there is no meaning of schema like in other modern drivers like PostgreSQL. In MySQL a schema is equivalent to a database. See this StackOverflow discussion
schema
database
If "prefixed" in DB::Object::Tables is greater than 2, the database name will be added.
At minimum, the table name is added.
$tbl->prefixed(2); $tbl->qualified_name; # Would return something like: mydb.my_table $tbl->prefixed(1); $tbl->qualified_name; # Would return only: my_table
Provided with a new table name, and this will prepare the necessary query to rename the table and return the statement handler.
If it is called in void context, the statement handler is executed immediately.
# Get the prefs table object my $tbl = $dbh->pref; $tbl->rename( 'prefs' ); # Would issue a statement handler for the query: ALTER TABLE pref RENAME TO prefs
It returns the statement handler created.
See PostgreSQL documentation for more information
Provided with an optional hash or hash reference of parameter, and this will prepare a query to repair the MySQL table.
repair
my $tbl = $dbh->my_table || die( $dbh->error ); my $sth = $tbl->repair || die( $tbl->error ); $sth->exec || die( $sth->error );
Provided with a table name and this will prepare a SHOW TABLE STATUS MySQL query. If no table explicitly specified, then this will prepare a stat query for all tables in the database.
SHOW TABLE STATUS
$tbl->stat( 'my_table' ); # SHOW TABLE STATUS FROM my_database LIKE 'my_table' $tbl->stat; # SHOW TABLE STATUS FROM my_database
The stat statement will be executed and an hash reference of property-value pairs in lower case will be retrieved for each table. Each table hash is stored in another hash reference of table name-properties hash reference pairs.
If only one table was the subject of the stat, in list context, this returns an hash of those table stat properties, and in scalar context its hash reference.
If the stat was done for the entire database, in list context, this returns an hash of all those tables to properties pairs, or an hash reference in scalar context.
This returns in list context an hash and in scalar context an hash reference of the table structure.
The hash, or hash reference returned contains the column name and its definition.
This method will also set the following object properties:
The table type.
No such thing in MySQL, so this is unavailable.
A column name to default value hash reference
A column name to field position (integer) hash reference
A column name to a boolean representing whether the column is nullable or not.
An array reference of column names that are used as primary key for the table.
A column name to its sql definition
A column name to column data type hash reference
This is an alias for "table_info" in DB::Object::Mysql
This will unlock a previously locked table.
If an argument is provided, this calls instead CORE::unlock passing it whatever parameters provided.
CORE::unlock
Otherwise, it will prepare a query UNLOCK TABLES and returns the statement handler.
UNLOCK TABLES
If it is called in void context, this will execute the statement handler immediately.
perl
Jacques Deguest <jack@deguest.jp>
Copyright (c) 2019-2021 DEGUEST Pte. Ltd.
You can use, copy, modify and redistribute this package and associated files under the same terms as Perl itself.
To install DB::Object, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DB::Object
CPAN shell
perl -MCPAN -e shell install DB::Object
For more information on module installation, please visit the detailed CPAN module installation guide.