Difference between revisions of "API:EPrints/Database/mysql"
(2 intermediate revisions by the same user not shown) | |||
Line 7: | Line 7: | ||
==NAME== | ==NAME== | ||
'''EPrints::Database::mysql''' - custom database methods for MySQL DB | '''EPrints::Database::mysql''' - custom database methods for MySQL DB | ||
+ | |||
+ | <div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
+ | <span style='display:none'>User Comments</span> | ||
+ | <!-- Edit below this comment --> | ||
+ | |||
+ | |||
+ | <!-- Pod2Wiki= --> | ||
+ | </div> | ||
+ | <!-- Pod2Wiki=head_description --> | ||
+ | ==DESCRIPTION== | ||
+ | MySQL database wrapper. | ||
+ | |||
+ | Foreign keys will be defined if you use a DB engine that supports them (e.g. InnoDB). | ||
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | <div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
Line 16: | Line 29: | ||
</div> | </div> | ||
<!-- Pod2Wiki=head_synopsis --> | <!-- Pod2Wiki=head_synopsis --> | ||
− | == | + | ===Synopsis=== |
− | + | $c->{dbdriver} = 'mysql'; | |
− | + | # $c->{dbhost} = 'localhost'; | |
− | + | # $c->{dbport} = '3316'; | |
− | + | $c->{dbname} = 'myrepo'; | |
− | + | $c->{dbuser} = 'bob'; | |
− | + | $c->{dbpass} = 'asecret'; | |
− | + | # $c->{dbengine} = 'InnoDB'; | |
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | <div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
Line 32: | Line 45: | ||
<!-- Pod2Wiki= --> | <!-- Pod2Wiki= --> | ||
</div> | </div> | ||
− | <!-- Pod2Wiki= | + | <!-- Pod2Wiki=head_mysql_specific_annoyances --> |
− | == | + | ===MySQL-specific Annoyances=== |
− | MySQL | + | MySQL does not support sequences. |
− | + | MySQL is (by default) lax about truncation. | |
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | <div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
Line 45: | Line 58: | ||
<!-- Pod2Wiki= --> | <!-- Pod2Wiki= --> | ||
</div> | </div> | ||
− | <!-- Pod2Wiki= | + | <!-- Pod2Wiki=head_constants --> |
− | === | + | ==CONSTANTS== |
− | + | See [[API:EPrints/Database#CONSTANTS|EPrints::Database]]. | |
+ | |||
+ | <div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
+ | <span style='display:none'>User Comments</span> | ||
+ | <!-- Edit below this comment --> | ||
+ | |||
− | + | <!-- Pod2Wiki= --> | |
+ | </div> | ||
+ | <!-- Pod2Wiki=head_instance_variables --> | ||
+ | ==INSTANCE VARIABLES== | ||
+ | See [[API:EPrints/Database#INSTANCE_VARIABLES|EPrints::Database]]. | ||
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | <div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
Line 426: | Line 448: | ||
This method gets the entire <tt>SHOW INDEX</tt> response and builds a look-up table of keys with their <tt>ordered</tt> columns. This ensures even if MySQL is weird and returns out of order results we won't break. | This method gets the entire <tt>SHOW INDEX</tt> response and builds a look-up table of keys with their <tt>ordered</tt> columns. This ensures even if MySQL is weird and returns out of order results we won't break. | ||
+ | |||
+ | <div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
+ | <span style='display:none'>User Comments</span> | ||
+ | <!-- Edit below this comment --> | ||
+ | |||
+ | |||
+ | <!-- Pod2Wiki= --> | ||
+ | </div> | ||
+ | <!-- Pod2Wiki=head_see_also --> | ||
+ | ==SEE ALSO== | ||
+ | [[API:EPrints/Database|EPrints::Database]] | ||
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | <div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> |
Latest revision as of 23:47, 11 January 2022
EPrints 3 Reference: Directory Structure - Metadata Fields - Repository Configuration - XML Config Files - XML Export Format - EPrints data structure - Core API - Data Objects
Latest Source Code (3.4, 3.3) | Revision Log | Before editing this page please read Pod2Wiki
Contents
- 1 NAME
- 2 DESCRIPTION
- 3 CONSTANTS
- 4 INSTANCE VARIABLES
- 5 METHODS
- 5.1 get_server_version
- 5.2 mysql_version_from_dbh
- 5.3 create
- 5.4 create_counters
- 5.5 has_table
- 5.6 has_column
- 5.7 connect
- 5.8 has_counter
- 5.9 create_counter
- 5.10 drop_counter
- 5.11 remove_counters
- 5.12 counter_next
- 5.13 counter_minimum
- 5.14 counter_reset
- 5.15 get_default_charset
- 5.16 get_default_collation
- 5.17 get_primary_key
- 5.18 get_number_of_keys
- 5.19 get_column_colation
- 5.20 quote_identifier
- 5.21 prepare_regexp
- 5.22 sql_like
- 5.23 ci_lookup
- 5.24 duplicate_error
- 5.25 duplicate_error
- 5.26 type_info
- 5.27 index_name
- 6 SEE ALSO
- 7 COPYRIGHT
NAME
EPrints::Database::mysql - custom database methods for MySQL DB
DESCRIPTION
MySQL database wrapper.
Foreign keys will be defined if you use a DB engine that supports them (e.g. InnoDB).
Synopsis
$c->{dbdriver} = 'mysql'; # $c->{dbhost} = 'localhost'; # $c->{dbport} = '3316'; $c->{dbname} = 'myrepo'; $c->{dbuser} = 'bob'; $c->{dbpass} = 'asecret'; # $c->{dbengine} = 'InnoDB';
MySQL-specific Annoyances
MySQL does not support sequences.
MySQL is (by default) lax about truncation.
CONSTANTS
See EPrints::Database.
INSTANCE VARIABLES
See EPrints::Database.
METHODS
get_server_version
$version = $db->get_server_version
Returns the database server version.
mysql_version_from_dbh
$version = $db->mysql_version_from_dbh
Returns the MySQL database server version from handle $dbh.
create
$version = $db->create( $username, $password )
Creates EPrints database as user with $username and $password.
create_counters
$n = $db->create_counters()
Creates and initialises the counters.
has_table
$boolean = $db->has_table( $tablename )
Returns true if the table with $tablename exists in the database.
has_column
$boolean = $db->has_column( $table, $column )
Returns true if named $table has named $column in the database.
connect
$db->connect()
Connects to the database.
has_counter
$success = $db->has_counter( $counter )
Returns true if $counter exists.
create_counter
$success = $db->create_counter( $name )
Create and initialise to zero a new counter with $name.
drop_counter
$success = $db->drop_counter( $name )
Destroy the counter named $name.
remove_counters
$success = $db->remove_counters
Destroy all counters.
counter_next
$n = $db->counter_next( $counter )
Return the next unused value for the named counter. Returns undef if the counter doesn't exist.
counter_minimum
$db->counter_minimum( $counter, $value )
Ensure that the counter is set no lower that $value. This is used when importing eprints which may not be in scrict sequence.
counter_reset
$db->counter_reset( $counter )
Return the counter. Use with cautiuon.
get_default_charset
$charset = $db->get_default_charset
Return the character set to use. Always utf8.
get_default_collation
$collation = $db->get_default_collation( $lang )
Return the collation to use for language $lang. Always utf8_bin.
get_primary_key
@columns = $db->get_primary_key( $table )
Returns a list of column names that comprise the primary key for named named $table.
Returns an empty list if no primary key exists.
get_number_of_keys
$num_keys = $db->get_number_of_keys( $table )
Returns the number of columns which are keys (PRI, MUL or UNI) for named $table.
get_column_colation
$collation = $db->get_column_colation( $table, $column )
Returns the collation for the named $column in the named $table.
quote_identifier
$str = $db->quote_identifier( @parts )
Quote a database identifier (e.g. table names). Multiple @parts will be joined by dots (.).
We'll do quote here, because DBD::mysql#quote_identifier is really slow.
prepare_regexp
$sql = $db->prepare_regexp( $col, $value )
Oracle use the syntax:
$col REGEXP $value
For the quoted regexp $value and the quoted column $col.
sql_like
$sql = $db->sql_LIKE()
Returns the syntactic glue to use when making a case-insensitive LIKE using utf8_general_ci collation.
ci_lookup
$value = $db->ci_lookup( $field, $value )
This is a hacky method to support case-insensitive lookup for usernames, emails, etc. It returns the actual case-sensitive version of $value if there is a case-insensitive match for the $field.
duplicate_error
$boolean = $db->duplicate_error()
Returns a boolean for whether the database error is a duplicate error. Based on whether the DBI#err code is 1062.
duplicate_error
$boolean = $db->duplicate_error()
Returns a boolean for whether the database error is a retry error. Based on whether the DBI#err code is 2006.
type_info
$type_info = $db->type_info( $data_type )
See DBI/type_info.
Uses LONGTEXT with column size 2^31 for SQL_CLOB.
index_name
$name = $db->index_name( $table, @cols )
Returns the name of the first index that starts with named columns @cols in the named $table.
Returns undef if no index exists.
Uses MySQL 4.0+ compatible SHOW INDEX.
This method gets the entire SHOW INDEX response and builds a look-up table of keys with their ordered columns. This ensures even if MySQL is weird and returns out of order results we won't break.
SEE ALSO
COPYRIGHT
© Copyright 2000-2024 University of Southampton.
EPrints 3.4 is supplied by EPrints Services.
http://www.eprints.org/eprints-3.4/
LICENSE
This file is part of EPrints 3.4 http://www.eprints.org/.
EPrints 3.4 and this file are released under the terms of the GNU Lesser General Public License version 3 as published by the Free Software Foundation unless otherwise stated.
EPrints 3.4 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. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with EPrints 3.4. If not, see http://www.gnu.org/licenses/.