DB-Object
view release on metacpan or search on metacpan
lib/DB/Object/Mysql/Tables.pm view on Meta::CPAN
This will issue the following query:
LOCK TABLES t1 AS n LOW_PRIORITY WRITE, t2 LOW_PRIORITY WRITE
The option can only be:
=over 4
=item I<read>
=item I<read local>
=item I<write>
=item I<low priority write>
=back
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 L<MyQL documentation for more information|https://dev.mysql.com/doc/refman/5.7/en/lock-tables.html>
=head2 on_conflict
A convenient wrapper to L<DB::Object::Mysql::Query/on_conflict>
=head2 optimize
my $sth = $t->optimize; # OPTIMIZE TABLE t
This will prepare a query to C<optimize> the table. If it is called in void context, the statement handler returned is executed immediately.
See L<MyQL documentation for more information|https://dev.mysql.com/doc/refman/5.7/en/optimize-table.html>
=head2 qualified_name
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 C<schema> is equivalent to a C<database>. See this L<StackOverflow discussion|https://stackoverflow.com/questions/11618277/difference-between-sc...
If L<DB::Object::Tables/prefixed> 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
See L<MyQL documentation for more information|https://dev.mysql.com/doc/refman/5.7/en/identifier-qualifiers.html>
=head2 rename
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 L<PostgreSQL documentation for more information|https://dev.mysql.com/doc/refman/5.7/en/alter-table.html>
=head2 repair
Provided with an optional hash or hash reference of parameter, and this will prepare a query to C<repair> the MySQL table.
my $tbl = $dbh->my_table || die( $dbh->error );
my $sth = $tbl->repair || die( $tbl->error );
$sth->exec || die( $sth->error );
If it is called in void context, the statement handler is executed immediately.
It returns the statement handler created.
See L<PostgreSQL documentation for more information|https://dev.mysql.com/doc/refman/5.7/en/repair-table.html>
=head2 stat
Provided with a table name and this will prepare a C<SHOW TABLE STATUS> MySQL query. If no table explicitly specified, then this will prepare a stat query for all tables in the database.
$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.
=head2 structure
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:
=over 4
=item L<DB::Object::Tables/type>
The table type.
=item L<DB::Object::Tables/schema>
No such thing in MySQL, so this is unavailable.
=item I<default>
A column name to default value hash reference
=item I<fields>
A column name to field position (integer) hash reference
( run in 1.886 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )