Difference between revisions of "API:EPrints/Database/mysql"

From EPrints Documentation
Jump to: navigation, search
Line 1: Line 1:
 
<!-- Pod2Wiki=_preamble_  
 
<!-- Pod2Wiki=_preamble_  
This page has been automatically generated from the EPrints 3.2 source. Any wiki changes made between the 'Pod2Wiki=*' and 'Edit below this comment' comments will be lost.
+
This page has been automatically generated from the EPrints 3.4 source. Any wiki changes made between the 'Pod2Wiki=*' and 'Edit below this comment' comments will be lost.
  -->{{API}}{{Pod2Wiki}}{{API:Source|file=perl_lib/EPrints/Database/mysql.pm|package_name=EPrints::Database::mysql}}[[Category:API|MYSQL]][[Category:API:EPrints/Database|MYSQL]][[Category:API:EPrints/Database/mysql|MYSQL]]<div><!-- Edit below this comment -->
+
  -->{{API}}{{Pod2Wiki}}{{API:Source|file=EPrints/Database/mysql.pm|package_name=EPrints::Database::mysql}}[[Category:API|MYSQL]][[Category:API:EPrints/Database|MYSQL]]<div><!-- Edit below this comment -->
  
  
Line 8: Line 8:
 
'''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 -->
 
<!-- Edit below this comment -->
  
  
 
<!-- Pod2Wiki= -->
 
<!-- Pod2Wiki= -->
 +
</div>
 
<!-- Pod2Wiki=head_synopsis -->
 
<!-- Pod2Wiki=head_synopsis -->
 
==SYNOPSIS==
 
==SYNOPSIS==
<source lang="perl">$c->{dbdriver} = 'mysql';
+
  $c-&gt;{dbdriver} = 'mysql';
# $c->{dbhost} = 'localhost';
+
  # $c-&gt;{dbhost} = 'localhost';
# $c->{dbport} = '3316';
+
  # $c-&gt;{dbport} = '3316';
$c->{dbname} = 'myrepo';
+
  $c-&gt;{dbname} = 'myrepo';
$c->{dbuser} = 'bob';
+
  $c-&gt;{dbuser} = 'bob';
$c->{dbpass} = 'asecret';
+
  $c-&gt;{dbpass} = 'asecret';
# $c->{dbengine} = 'InnoDB';</source>
+
  # $c-&gt;{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%; '>
 +
<span style='display:none'>User Comments</span>
 
<!-- Edit below this comment -->
 
<!-- Edit below this comment -->
  
  
 
<!-- Pod2Wiki= -->
 
<!-- Pod2Wiki= -->
 +
</div>
 
<!-- Pod2Wiki=head_description -->
 
<!-- Pod2Wiki=head_description -->
 
==DESCRIPTION==
 
==DESCRIPTION==
Line 32: Line 38:
 
Foreign keys will be defined if you use a DB engine that supports them (e.g. InnoDB).
 
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%; '>
 +
<span style='display:none'>User Comments</span>
 
<!-- Edit below this comment -->
 
<!-- Edit below this comment -->
  
  
 
<!-- Pod2Wiki= -->
 
<!-- Pod2Wiki= -->
 +
</div>
 
<!-- Pod2Wiki=head_mysql_specific_annoyances -->
 
<!-- Pod2Wiki=head_mysql_specific_annoyances -->
 
===MySQL-specific Annoyances===
 
===MySQL-specific Annoyances===
Line 42: Line 51:
 
MySQL is (by default) lax about truncation.
 
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%; '>
 +
<span style='display:none'>User Comments</span>
 
<!-- Edit below this comment -->
 
<!-- Edit below this comment -->
  
  
 
<!-- Pod2Wiki= -->
 
<!-- Pod2Wiki= -->
 +
</div>
 
<!-- Pod2Wiki=head_methods -->
 
<!-- Pod2Wiki=head_methods -->
 
==METHODS==
 
==METHODS==
<!-- Pod2Wiki=head_get_server_version -->
+
<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=item_get_server_version -->
 
===get_server_version===
 
===get_server_version===
  
<source lang="perl">$version = $db->get_server_version
+
$version = $db-&gt;get_server_version
 +
Returns the database server version.
 +
 
 +
<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=item_mysql_version_from_dbh -->
 +
===mysql_version_from_dbh===
 +
 
 +
$version = $db-&gt;mysql_version_from_dbh
 +
Returns the MySQL database server version from handle <tt>$dbh</tt>.
 +
 
 +
<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=item_create -->
 +
===create===
  
</source>
+
$version = $db-&gt;create( $username, $password )
Return the database server version.
+
Creates EPrints database as user with <tt>$username</tt> and <tt>$password</tt>.
  
 +
<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 -->
 
<!-- Edit below this comment -->
  
  
 
<!-- Pod2Wiki= -->
 
<!-- Pod2Wiki= -->
<!-- Pod2Wiki=head_create_counters -->
+
</div>
 +
<!-- Pod2Wiki=item_create_counters -->
 
===create_counters===
 
===create_counters===
  
<source lang="perl">$n = $db->create_counters()
+
$n = $db-&gt;create_counters()
 
+
Creates and initialises the counters.
</source>
 
Create and initialise the counters.
 
  
 +
<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 -->
 
<!-- Edit below this comment -->
  
  
 
<!-- Pod2Wiki= -->
 
<!-- Pod2Wiki= -->
<!-- Pod2Wiki=head_has_table -->
+
</div>
 +
<!-- Pod2Wiki=item_has_table -->
 
===has_table===
 
===has_table===
  
<source lang="perl">$boolean = $db->has_table( $tablename )
+
$boolean = $db-&gt;has_table( $tablename )
 
+
Returns <tt>true</tt> if the table with <tt>$tablename</tt> exists in the database.
</source>
 
Return true if the a table of the given name exists in the 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 -->
 
<!-- Edit below this comment -->
  
  
 
<!-- Pod2Wiki= -->
 
<!-- Pod2Wiki= -->
<!-- Pod2Wiki=head_has_column -->
+
</div>
 +
<!-- Pod2Wiki=item_has_column -->
 
===has_column===
 
===has_column===
  
<source lang="perl">$boolean = $db->has_column( $tablename, $columnname )
+
$boolean = $db-&gt;has_column( $table, $column )
 +
Returns <tt>true</tt> if named <tt>$table</tt> has named <tt>$column</tt> in the  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=item_connect -->
 +
===connect===
  
</source>
+
$db-&gt;connect()
Return true if the a table of the given name has a column named $columnname in the database.
+
Connects to the 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 -->
 
<!-- Edit below this comment -->
  
  
 
<!-- Pod2Wiki= -->
 
<!-- Pod2Wiki= -->
<!-- Pod2Wiki=head_has_counter -->
+
</div>
 +
<!-- Pod2Wiki=item_has_counter -->
 
===has_counter===
 
===has_counter===
  
<source lang="perl">$success = $db->has_counter( $counter )
+
$success = $db-&gt;has_counter( $counter )
 +
Returns <tt>true</tt> if <tt>$counter</tt> exists.
 +
 
 +
<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=item_create_counter -->
 +
===create_counter===
 +
 
 +
$success = $db-&gt;create_counter( $name )
 +
Create and initialise to zero a new counter with <tt>$name</tt>.
 +
 
 +
<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=item_drop_counter -->
 +
===drop_counter===
 +
 
 +
$success = $db-&gt;drop_counter( $name )
 +
Destroy the counter named <tt>$name</tt>.
 +
 
 +
<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=item_remove_counters -->
 +
===remove_counters===
  
</source>
+
$success = $db-&gt;remove_counters
Returns true if $counter exists.
+
Destroy all counters.
  
 +
<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 -->
 
<!-- Edit below this comment -->
  
  
 
<!-- Pod2Wiki= -->
 
<!-- Pod2Wiki= -->
<!-- Pod2Wiki=head_counter_next -->
+
</div>
 +
<!-- Pod2Wiki=item_counter_next -->
 
===counter_next===
 
===counter_next===
  
<source lang="perl">$n = $db->counter_next( $counter )
+
$n = $db-&gt;counter_next( $counter )
 
 
</source>
 
 
Return the next unused value for the named counter. Returns undef if  the counter doesn't exist.
 
Return the next unused value for the named counter. Returns undef if  the counter doesn't exist.
  
 +
<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 -->
 
<!-- Edit below this comment -->
  
  
 
<!-- Pod2Wiki= -->
 
<!-- Pod2Wiki= -->
<!-- Pod2Wiki=head_counter_minimum -->
+
</div>
 +
<!-- Pod2Wiki=item_counter_minimum -->
 
===counter_minimum===
 
===counter_minimum===
  
<source lang="perl">$db->counter_minimum( $counter, $value )
+
$db-&gt;counter_minimum( $counter, $value )
 
 
</source>
 
 
Ensure that the counter is set no lower that $value. This is used when importing eprints which may not be in scrict sequence.
 
Ensure that the counter is set no lower that $value. This is used when importing eprints which may not be in scrict sequence.
  
 +
<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 -->
 
<!-- Edit below this comment -->
  
  
 
<!-- Pod2Wiki= -->
 
<!-- Pod2Wiki= -->
<!-- Pod2Wiki=head_counter_reset -->
+
</div>
 +
<!-- Pod2Wiki=item_counter_reset -->
 
===counter_reset===
 
===counter_reset===
  
<source lang="perl">$db->counter_reset( $counter )
+
$db-&gt;counter_reset( $counter )
 +
Return the counter. Use with cautiuon.
 +
 
 +
<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=item_get_default_charset -->
 +
===get_default_charset===
 +
 
 +
$charset = $db-&gt;get_default_charset
 +
Return the character set to use.  Always <tt>utf8</tt>.
 +
 
 +
<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=item_get_default_collation -->
 +
===get_default_collation===
 +
 
 +
$collation = $db-&gt;get_default_collation( $lang )
 +
Return the collation to use for language <tt>$lang</tt>. Always <tt>utf8_bin</tt>.
 +
 
 +
<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=item_get_primary_key -->
 +
===get_primary_key===
 +
 
 +
@columns = $db-&gt;get_primary_key( $table )
 +
Returns a list of column names that comprise the primary key for named named <tt>$table</tt>.
 +
 
 +
Returns an empty list if no primary key exists.
 +
 
 +
<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=item_get_number_of_keys -->
 +
===get_number_of_keys===
 +
 
 +
$num_keys = $db-&gt;get_number_of_keys( $table )
 +
Returns the number of columns which are keys (<tt>PRI</tt>, <tt>MUL</tt> or  <tt>UNI</tt>) for named <tt>$table</tt>.
 +
 
 +
<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=item_get_column_colation -->
 +
===get_column_colation===
 +
 
 +
$collation = $db-&gt;get_column_colation( $table, $column )
 +
Returns the collation for the named <tt>$column</tt> in the named <tt>$table</tt>.
 +
 
 +
<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=item_quote_identifier -->
 +
===quote_identifier===
 +
 
 +
$str = $db-&gt;quote_identifier( @parts )
 +
Quote a database identifier (e.g. table names). Multiple <tt>@parts</tt> will be joined by dots (<tt>.</tt>).
 +
 
 +
We'll do quote here, because {{API:PodLink|file=DBD/mysql#quote_identifier|package_name=DBD::mysql#quote_identifier|section=|text=DBD::mysql#quote_identifier}} is really  slow.
 +
 
 +
<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=item_prepare_regexp -->
 +
===prepare_regexp===
 +
 
 +
$sql = $db-&gt;prepare_regexp( $col, $value )
 +
The syntax used for regular expressions varies across databases. This method takes two quoted string and returns a SQL expression that will apply the quoted regexp <tt>$val</tt> to the quoted column <tt>$column</tt>.
 +
 
 +
<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=item_sql_like -->
 +
===sql_like===
 +
 
 +
$sql = $db-&gt;sql_LIKE()
 +
Returns the syntactic glue to use when making a case-insensitive <tt>LIKE</tt> using <tt>utf8_general_ci</tt> collation.
 +
 
 +
<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=item_ci_lookup -->
 +
===ci_lookup===
 +
 
 +
$value = $db-&gt;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 <tt>$value</tt> if there is a case-insensitive match for the <tt>$field</tt>.
 +
 
 +
<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=item_duplicate_error -->
 +
===duplicate_error===
 +
 
 +
$boolean = $db-&gt;duplicate_error()
 +
Returns a boolean for whether the database error is a duplicate error. Based on whether the {{API:PodLink|file=DBI#err|package_name=DBI#err|section=|text=DBI#err}} code is <tt>1062</tt>.
 +
 
 +
<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 -->
 +
 
  
</source>
+
<!-- Pod2Wiki= -->
Return the counter. Use with cautiuon.
+
</div>
 +
<!-- Pod2Wiki=item_duplicate_error -->
 +
===duplicate_error===
 +
 
 +
$boolean = $db-&gt;duplicate_error()
 +
Returns a boolean for whether the database error is a retry error. Based on whether the {{API:PodLink|file=DBI#err|package_name=DBI#err|section=|text=DBI#err}} code is <tt>2006</tt>.
 +
 
 +
<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=item_type_info -->
 +
===type_info===
 +
 
 +
$type_info = $db-&gt;type_info( $data_type )
 +
See {{API:PodLink|file=DBI|package_name=DBI|section=type_info|text=DBI/type_info}}.
  
 +
<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 -->
 
<!-- Edit below this comment -->
  
  
 
<!-- Pod2Wiki= -->
 
<!-- Pod2Wiki= -->
<!-- Pod2Wiki=head_copyright -->
+
</div>
==COPYRIGHT==
+
<!-- Pod2Wiki=item_index_name -->
Copyright 2000-2011 University of Southampton.
+
===index_name===
  
This file is part of EPrints http://www.eprints.org/.
+
$name = $db-&gt;index_name( $table, @cols )
 +
Returns the name of the first index that starts with named columns <tt>@cols</tt> in the named <tt>$table</tt>.
  
EPrints is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+
Returns <tt>undef</tt> if no index exists.
  
EPrints 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.
+
Uses MySQL 4.0+ compatible <tt>SHOW INDEX</tt>.
  
You should have received a copy of the GNU Lesser General Public License along with EPrintsIf not, see http://www.gnu.org/licenses/.
+
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 -->
 
<!-- Edit below this comment -->
  
  
 
<!-- Pod2Wiki= -->
 
<!-- Pod2Wiki= -->
<!-- Pod2Wiki=_postamble_ -->
+
</div>
 +
<!-- Pod2Wiki=head_copyright -->
 +
==COPYRIGHT==
 +
{{API:Copyright}}
 +
<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 -->
 
<!-- Edit below this comment -->
 +
 +
 +
<!-- Pod2Wiki= -->
 +
</div>
 +
<!-- Pod2Wiki=_postamble_ --><!-- Edit below this comment -->

Revision as of 14:15, 25 December 2021

EPrints 3 Reference: Directory Structure - Metadata Fields - Repository Configuration - XML Config Files - XML Export Format - EPrints data structure - Core API - Data Objects


API: Core API

Latest Source Code (3.4, 3.3) | Revision Log | Before editing this page please read Pod2Wiki


NAME

EPrints::Database::mysql - custom database methods for MySQL DB

User Comments


SYNOPSIS

 $c->{dbdriver} = 'mysql';
 # $c->{dbhost} = 'localhost';
 # $c->{dbport} = '3316';
 $c->{dbname} = 'myrepo';
 $c->{dbuser} = 'bob';
 $c->{dbpass} = 'asecret';
 # $c->{dbengine} = 'InnoDB';
 

User Comments


DESCRIPTION

MySQL database wrapper.

Foreign keys will be defined if you use a DB engine that supports them (e.g. InnoDB).

User Comments


MySQL-specific Annoyances

MySQL does not support sequences.

MySQL is (by default) lax about truncation.

User Comments


METHODS

User Comments


get_server_version

$version = $db->get_server_version

Returns the database server version.

User Comments


mysql_version_from_dbh

$version = $db->mysql_version_from_dbh

Returns the MySQL database server version from handle $dbh.

User Comments


create

$version = $db->create( $username, $password )

Creates EPrints database as user with $username and $password.

User Comments


create_counters

$n = $db->create_counters()

Creates and initialises the counters.

User Comments


has_table

$boolean = $db->has_table( $tablename )

Returns true if the table with $tablename exists in the database.

User Comments


has_column

$boolean = $db->has_column( $table, $column )

Returns true if named $table has named $column in the database.

User Comments


connect

$db->connect()

Connects to the database.

User Comments


has_counter

$success = $db->has_counter( $counter )

Returns true if $counter exists.

User Comments


create_counter

$success = $db->create_counter( $name )

Create and initialise to zero a new counter with $name.

User Comments


drop_counter

$success = $db->drop_counter( $name )

Destroy the counter named $name.

User Comments


remove_counters

$success = $db->remove_counters

Destroy all counters.

User Comments


counter_next

$n = $db->counter_next( $counter )

Return the next unused value for the named counter. Returns undef if the counter doesn't exist.

User Comments


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.

User Comments


counter_reset

$db->counter_reset( $counter )

Return the counter. Use with cautiuon.

User Comments


get_default_charset

$charset = $db->get_default_charset

Return the character set to use. Always utf8.

User Comments


get_default_collation

$collation = $db->get_default_collation( $lang )

Return the collation to use for language $lang. Always utf8_bin.

User Comments


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.

User Comments


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.

User Comments


get_column_colation

$collation = $db->get_column_colation( $table, $column )

Returns the collation for the named $column in the named $table.

User Comments


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.

User Comments


prepare_regexp

$sql = $db->prepare_regexp( $col, $value )

The syntax used for regular expressions varies across databases. This method takes two quoted string and returns a SQL expression that will apply the quoted regexp $val to the quoted column $column.

User Comments


sql_like

$sql = $db->sql_LIKE()

Returns the syntactic glue to use when making a case-insensitive LIKE using utf8_general_ci collation.

User Comments


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.

User Comments


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.

User Comments


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.

User Comments


type_info

$type_info = $db->type_info( $data_type )

See DBI/type_info.

User Comments


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.

User Comments


COPYRIGHT

© Copyright 2022 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/.

User Comments