Difference between revisions of "API:EPrints/Database"

From EPrints Documentation
Jump to: navigation, search
Line 8: Line 8:
 
'''EPrints::Database''' - a connection to the SQL database for an eprints session
 
'''EPrints::Database''' - a connection to the SQL database for an eprints session
  
<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 -->
  
Line 22: Line 20:
 
   print $sth-&gt;fetchrow_arrayref-&gt;[0], "\n";
 
   print $sth-&gt;fetchrow_arrayref-&gt;[0], "\n";
 
    
 
    
<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 -->
  
Line 37: Line 33:
 
In most use-cases it should not be necessary to use the database module directly. Instead you should use [[API:EPrints/DataSet|EPrints::DataSet]] or [[API:EPrints/MetaField|EPrints::MetaField]] accessor methods to access objects and field values respectively.
 
In most use-cases it should not be necessary to use the database module directly. Instead you should use [[API:EPrints/DataSet|EPrints::DataSet]] or [[API:EPrints/MetaField|EPrints::MetaField]] accessor methods to access objects and field values respectively.
  
<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 -->
  
Line 48: Line 42:
 
Any use of SQL statements must use [[API:EPrints/Database#quote_identifier|quote_identifier]] to quote database tables and columns and [[API:EPrints/Database#quote_value|quote_value]] to quote values. The only exception to this are the EPrints::Database::* modules which provide database-driver specific extensions.
 
Any use of SQL statements must use [[API:EPrints/Database#quote_identifier|quote_identifier]] to quote database tables and columns and [[API:EPrints/Database#quote_value|quote_value]] to quote values. The only exception to this are the EPrints::Database::* modules which provide database-driver specific extensions.
  
<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 -->
  
Line 64: Line 56:
 
Where possible you should avoid quoting values yourself, instead use a method that accepts unquoted values which will (safely) do the work for you.
 
Where possible you should avoid quoting values yourself, instead use a method that accepts unquoted values which will (safely) do the work for you.
  
<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 -->
  
Line 73: Line 63:
 
<!-- Pod2Wiki=head_methods -->
 
<!-- Pod2Wiki=head_methods -->
 
==METHODS==
 
==METHODS==
<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 -->
  
Line 82: Line 70:
 
<!-- Pod2Wiki=head_database -->
 
<!-- Pod2Wiki=head_database -->
 
===Database===
 
===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 -->
  
Line 95: Line 81:
 
Create a connection to the database.
 
Create a connection 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 -->
  
Line 108: Line 92:
 
Create and connect to a new database using super user account $username and $password.
 
Create and connect to a new database using super user account $username and $password.
  
<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 -->
  
Line 121: Line 103:
 
Connects to 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 -->
  
Line 134: Line 114:
 
Disconnects from the EPrints database.
 
Disconnects from the 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 -->
 
<!-- Edit below this comment -->
  
Line 147: Line 125:
 
Set the SQL debug mode to true or false.
 
Set the SQL debug mode to true or false.
  
<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 -->
  
Line 160: Line 136:
 
Set the version id table in the SQL database to the given value (used by the upgrade script).
 
Set the version id table in the SQL database to the given value (used by the upgrade script).
  
<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 -->
  
Line 173: Line 147:
 
Returns the current database schema version.
 
Returns the current database schema 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 -->
 
<!-- Edit below this comment -->
  
Line 186: Line 158:
 
Return true if the database schema is in the correct configuration for this version of eprints. Otherwise false.
 
Return true if the database schema is in the correct configuration for this version of eprints. Otherwise false.
  
<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 -->
  
Line 199: Line 169:
 
Return the database server version.
 
Return 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 -->
 
<!-- Edit below this comment -->
  
Line 214: Line 182:
 
Returns undef if character sets are unsupported.
 
Returns undef if character sets are unsupported.
  
<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 -->
  
Line 229: Line 195:
 
Returns undef if collation is unsupported.
 
Returns undef if collation is unsupported.
  
<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 -->
  
Line 242: Line 206:
 
Return the database driver name.
 
Return the database driver name.
  
<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 -->
  
Line 255: Line 217:
 
Return a string describing the last SQL error.
 
Return a string describing the last SQL error.
  
<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 -->
  
Line 268: Line 228:
 
Returns true if the current error is a retry error.
 
Returns true if the current error is a retry error.
  
<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 -->
  
Line 281: Line 239:
 
Returns true if the current error is a PRIMARY KEY or UNIQUE error.
 
Returns true if the current error is a PRIMARY KEY or UNIQUE error.
  
<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 -->
  
Line 294: Line 250:
 
Begin a transaction.
 
Begin a transaction.
  
<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 -->
  
Line 307: Line 261:
 
Commit the previously begun transaction.
 
Commit the previously begun transaction.
  
<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 -->
  
Line 320: Line 272:
 
Roll-back the current transaction.
 
Roll-back the current transaction.
  
<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 -->
  
Line 333: Line 283:
 
See {{API:PodLink|file=DBI|package_name=DBI|section=type_info|text=DBI/type_info}}.
 
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 -->
  
Line 377: Line 325:
 
The actual column types used will be database-specific.
 
The actual column types used will be database-specific.
  
<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 -->
  
Line 386: Line 332:
 
<!-- Pod2Wiki=head_schema_manipulation -->
 
<!-- Pod2Wiki=head_schema_manipulation -->
 
===Schema Manipulation===
 
===Schema Manipulation===
<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 -->
  
Line 399: Line 343:
 
Create all the SQL tables for each dataset.
 
Create all the SQL tables for each dataset.
  
<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 -->
  
Line 412: Line 354:
 
Destroy all tables used by eprints in the database.
 
Destroy all tables used by eprints 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 -->
  
Line 425: Line 365:
 
Make the version table (and set the only value to be the current version of eprints).
 
Make the version table (and set the only value to be the current version of eprints).
  
<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 -->
  
Line 438: Line 376:
 
Drop the version table.
 
Drop the version table.
  
<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 -->
  
Line 451: Line 387:
 
Create all the SQL tables for a single dataset.
 
Create all the SQL tables for a single dataset.
  
<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 -->
  
Line 464: Line 398:
 
Drop all the SQL tables for a single dataset.
 
Drop all the SQL tables for a single dataset.
  
<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 -->
  
Line 477: Line 409:
 
Create all the index tables for a single dataset.
 
Create all the index tables for a single dataset.
  
<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 -->
  
Line 490: Line 420:
 
Create all the ordervalues tables for a single dataset.
 
Create all the ordervalues tables for a single dataset.
  
<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 -->
  
Line 505: Line 433:
 
This does not check that all fields are configured - see has_field().
 
This does not check that all fields are configured - see has_field().
  
<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 -->
  
Line 518: Line 444:
 
Returns true if $field is in the database for $dataset.
 
Returns true if $field is in the database for $dataset.
  
<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 -->
  
Line 533: Line 457:
 
If $force is true will modify/replace an existing column (use with care!).
 
If $force is true will modify/replace an existing column (use with care!).
  
<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 -->
  
Line 546: Line 468:
 
Remove $field from $dataset's tables.
 
Remove $field from $dataset's tables.
  
<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 -->
  
Line 561: Line 481:
 
Returns true if the field was successfully renamed.
 
Returns true if the field was successfully renamed.
  
<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 -->
  
Line 576: Line 494:
 
The first $setkey number of fields are used for a primary key.
 
The first $setkey number of fields are used for a primary key.
  
<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 -->
  
Line 591: Line 507:
 
This will cause records in $aux_table to be deleted if the equivalent record is deleted from $main_table.
 
This will cause records in $aux_table to be deleted if the equivalent record is deleted from $main_table.
  
<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 -->
  
Line 604: Line 518:
 
Create the counters used to store the highest current id of eprints, users etc.
 
Create the counters used to store the highest current id of eprints, users etc.
  
<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 -->
  
Line 617: Line 529:
 
Returns true if $counter exists.
 
Returns true if $counter 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 -->
 
<!-- Edit below this comment -->
  
Line 630: Line 540:
 
Create and initialise to zero a new counter called $name.
 
Create and initialise to zero a new counter called $name.
  
<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 -->
  
Line 643: Line 551:
 
Destroy all counters.
 
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 -->
  
Line 656: Line 562:
 
Destroy the counter named $name.
 
Destroy the counter named $name.
  
<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 -->
  
Line 669: Line 573:
 
Return the value of the previous counter_next on $counter.
 
Return the value of the previous counter_next on $counter.
  
<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 -->
  
Line 682: Line 584:
 
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 -->
  
Line 695: Line 595:
 
Ensure that the counter is set no lower than $value. This is used when importing eprints which may not be in scrict sequence.
 
Ensure that the counter is set no lower than $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 -->
  
Line 708: Line 606:
 
Reset the counter. Use with caution.
 
Reset the counter. Use with caution.
  
<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 -->
  
Line 721: Line 617:
 
Return the next unused document pos for the given eprintid.
 
Return the next unused document pos for the given eprintid.
  
<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 -->
  
Line 730: Line 624:
 
<!-- Pod2Wiki=head_sql_utility_methods -->
 
<!-- Pod2Wiki=head_sql_utility_methods -->
 
===SQL utility methods===
 
===SQL utility methods===
<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 -->
  
Line 743: Line 635:
 
Execute the given SQL.
 
Execute the given SQL.
  
<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 -->
  
Line 761: Line 651:
 
   $sth-&gt;execute;
 
   $sth-&gt;execute;
 
    
 
    
<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 -->
  
Line 783: Line 671:
 
   offset - return '''limit''' number of rows after offset
 
   offset - return '''limit''' number of rows after offset
 
    
 
    
<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 -->
  
Line 796: Line 682:
 
Return true if a sequence of the given name exists in the database.
 
Return true if a sequence 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 -->
  
Line 809: Line 693:
 
Creates a new sequence object initialised to zero.
 
Creates a new sequence object initialised to zero.
  
<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 -->
  
Line 822: Line 704:
 
Deletes a sequence object.
 
Deletes a sequence object.
  
<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 -->
  
Line 835: Line 715:
 
Drops a column from a table.
 
Drops a column from a table.
  
<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 -->
  
Line 850: Line 728:
 
Returns empty list if no primary key exists.
 
Returns 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 -->
 
<!-- Edit below this comment -->
  
Line 863: Line 739:
 
Create a PRIMARY KEY on $tablename over @cols.
 
Create a PRIMARY KEY on $tablename over @cols.
  
<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 -->
  
Line 876: Line 750:
 
Creates an index over @columns for $tablename. Returns true on success.
 
Creates an index over @columns for $tablename. Returns true on success.
  
<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 -->
  
Line 889: Line 761:
 
Creates a unique index over @columns for $tablename. Returns true on success.
 
Creates a unique index over @columns for $tablename. Returns true on success.
  
<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 -->
  
Line 904: Line 774:
 
Returns undef if no index exists.
 
Returns undef if no index 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 -->
 
<!-- Edit below this comment -->
  
Line 921: Line 789:
 
This method is internal.
 
This method is internal.
  
<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 -->
  
Line 936: Line 802:
 
Values will be quoted before insertion.
 
Values will be quoted before insertion.
  
<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 -->
  
Line 951: Line 815:
 
Values will NOT be quoted before insertion - care must be exercised!
 
Values will NOT be quoted before insertion - care must be exercised!
  
<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 -->
  
Line 966: Line 828:
 
If you want to clear a table completely use clear_table().
 
If you want to clear a table completely use clear_table().
  
<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 -->
  
Line 979: Line 839:
 
Return the number of rows in the specified SQL table.
 
Return the number of rows in the specified SQL table.
  
<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 -->
  
Line 992: Line 850:
 
Return true if a table of the given name exists in the database.
 
Return true if 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 -->
  
Line 1,005: Line 861:
 
Return true if the a table of the given name has a column named $columnname in the database.
 
Return true if the a table of the given name has a column named $columnname 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 -->
  
Line 1,018: Line 872:
 
Delete the named table(s). Use with caution!
 
Delete the named table(s). Use with caution!
  
<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 -->
  
Line 1,031: Line 883:
 
Clears all records from the given table, use with caution!
 
Clears all records from the given table, use with caution!
  
<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 -->
  
Line 1,044: Line 894:
 
Renames the table from the old name to the new one.
 
Renames the table from the old name to the new one.
  
<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 -->
  
Line 1,057: Line 905:
 
Swap table a and table b.  
 
Swap table a and table b.  
  
<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 -->
  
Line 1,070: Line 916:
 
Return a list of all the tables in the database.
 
Return a list of all the tables 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 -->
  
Line 1,079: Line 923:
 
<!-- Pod2Wiki=head_quoting_values -->
 
<!-- Pod2Wiki=head_quoting_values -->
 
===Quoting Values===
 
===Quoting Values===
<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 -->
  
Line 1,092: Line 934:
 
Escape a numerical value for SQL. undef becomes NULL. Anything else becomes a number (zero if needed).
 
Escape a numerical value for SQL. undef becomes NULL. Anything else becomes a number (zero if needed).
  
<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 -->
  
Line 1,105: Line 945:
 
Escape a value for SQL. Modify value such that " becomes \" and \  becomes \\ and ' becomes \'
 
Escape a value for SQL. Modify value such that " becomes \" and \  becomes \\ and ' becomes \'
  
<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 -->
  
Line 1,118: Line 956:
 
Escape an value for an SQL like field. In addition to ' " and \ also  escapes % and _
 
Escape an value for an SQL like field. In addition to ' " and \ also  escapes % and _
  
<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 -->
  
Line 1,133: Line 969:
 
  my $str = $database-&gt;quote_value( EPrints::Database::prep_like_value( $foo ) . '%' );
 
  my $str = $database-&gt;quote_value( EPrints::Database::prep_like_value( $foo ) . '%' );
 
    
 
    
<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 -->
  
Line 1,146: Line 980:
 
Return a quoted integer value
 
Return a quoted integer value
  
<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 -->
  
Line 1,161: Line 993:
 
This method should be called on data containing nul bytes or back-slashes before being passed on [[API:EPrints/Database#quote_value|quote_value]].
 
This method should be called on data containing nul bytes or back-slashes before being passed on [[API:EPrints/Database#quote_value|quote_value]].
  
<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 -->
  
Line 1,174: Line 1,004:
 
Some databases (Oracle) can't order by CLOBS so need special treatment when creating the ordervalues tables. This method allows any fixing-up required for string data before it's inserted.
 
Some databases (Oracle) can't order by CLOBS so need special treatment when creating the ordervalues tables. This method allows any fixing-up required for string data before it's inserted.
  
<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 -->
  
Line 1,187: Line 1,015:
 
Quote a database identifier (e.g. table names). Multiple @parts will be joined by dot.
 
Quote a database identifier (e.g. table names). Multiple @parts will be joined by dot.
  
<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 -->
  
Line 1,200: Line 1,026:
 
The syntax used for regular expressions varies across databases. This method takes two '''quoted''' values and returns a SQL expression that will apply the regexp ($quoted_value) to the column ($quoted_column).
 
The syntax used for regular expressions varies across databases. This method takes two '''quoted''' values and returns a SQL expression that will apply the regexp ($quoted_value) to the column ($quoted_column).
  
<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 -->
  
Line 1,213: Line 1,037:
 
Returns the syntactic glue to use when aliasing. SQL 92 DBs will happilly use " AS " but some DBs (Oracle!) won't accept it.
 
Returns the syntactic glue to use when aliasing. SQL 92 DBs will happilly use " AS " but some DBs (Oracle!) won't accept it.
  
<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 -->
  
Line 1,226: Line 1,048:
 
Returns the syntactic glue to use when making a case-insensitive LIKE. PostgreSQL requires "ILIKE" while everything else uses "LIKE" and the column collation.
 
Returns the syntactic glue to use when making a case-insensitive LIKE. PostgreSQL requires "ILIKE" while everything else uses "LIKE" and the column 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 -->
 
<!-- Edit below this comment -->
  
Line 1,235: Line 1,055:
 
<!-- Pod2Wiki=head_dataset_data -->
 
<!-- Pod2Wiki=head_dataset_data -->
 
===Dataset Data===
 
===Dataset Data===
<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 -->
  
Line 1,252: Line 1,070:
 
Inserts ordervalues if the dataset is {{API:PodLink|file=EPrints/DataSet|package_name=EPrints::DataSet|section=ordered|text=ordered}}.
 
Inserts ordervalues if the dataset is {{API:PodLink|file=EPrints/DataSet|package_name=EPrints::DataSet|section=ordered|text=ordered}}.
  
<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 -->
  
Line 1,269: Line 1,085:
 
Updates ordervalues if the dataset is {{API:PodLink|file=EPrints/DataSet|package_name=EPrints::DataSet|section=ordered|text=ordered}}.
 
Updates ordervalues if the dataset is {{API:PodLink|file=EPrints/DataSet|package_name=EPrints::DataSet|section=ordered|text=ordered}}.
  
<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 -->
  
Line 1,282: Line 1,096:
 
Return true if a record with the given primary key exists in the dataset, otherwise false.
 
Return true if a record with the given primary key exists in the dataset, otherwise false.
  
<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 -->
  
Line 1,297: Line 1,109:
 
Returns true on success.
 
Returns true on success.
  
<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 -->
  
Line 1,306: Line 1,116:
 
<!-- Pod2Wiki=head_searching_caching_and_retrieval -->
 
<!-- Pod2Wiki=head_searching_caching_and_retrieval -->
 
===Searching, Caching and Retrieval===
 
===Searching, Caching and Retrieval===
<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 -->
  
Line 1,319: Line 1,127:
 
Return the serialised Search of a the cached search with id $cacheid. Return undef if the id is invalid or expired.
 
Return the serialised Search of a the cached search with id $cacheid. Return undef if the id is invalid or expired.
  
<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 -->
  
Line 1,338: Line 1,144:
 
If $srctable is set to "ALL" every matching record from $dataset is added to the cache, optionally ordered by $order.
 
If $srctable is set to "ALL" every matching record from $dataset is added to the cache, optionally ordered by $order.
  
<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 -->
  
Line 1,351: Line 1,155:
 
Return the SQL table used to store the cache with id $id.
 
Return the SQL table used to store the cache with id $id.
  
<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 -->
  
Line 1,366: Line 1,168:
 
If no table alias is passed then M is assumed.  
 
If no table alias is passed then M is assumed.  
  
<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 -->
  
Line 1,379: Line 1,179:
 
Remove the cached search with the given id.
 
Remove the cached search with the given id.
  
<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 -->
  
Line 1,396: Line 1,194:
 
If $justids is true then it returns just an ref to an array of the record ids, not the objects.
 
If $justids is true then it returns just an ref to an array of the record ids, not the objects.
  
<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 -->
  
Line 1,409: Line 1,205:
 
Drop tables called "cacheXXX" where XXX is an integer. Returns the number of tables dropped.
 
Drop tables called "cacheXXX" where XXX is an integer. Returns the number of tables dropped.
  
<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 -->
  
Line 1,422: Line 1,216:
 
Return a single item from the given dataset. The one with the specified id.
 
Return a single item from the given dataset. The one with the specified id.
  
<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 -->
  
Line 1,435: Line 1,227:
 
Returns a reference to an array with all the items from the given dataset.
 
Returns a reference to an array with all the items from the given dataset.
  
<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 -->
  
Line 1,448: Line 1,238:
 
Returns a list of $count ids from $cache_id starting at $offset and in the order in the cachemap.
 
Returns a list of $count ids from $cache_id starting at $offset and in the order in the cachemap.
  
<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 -->
  
Line 1,461: Line 1,249:
 
Retrieves the records in $dataset with the given $id(s). If an $id doesn't exist in the database it will be ignored.
 
Retrieves the records in $dataset with the given $id(s). If an $id doesn't exist in the database it will be ignored.
  
<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 -->
  
Line 1,474: Line 1,260:
 
Return a reference to an array of all the distinct values of the  [[API:EPrints/MetaField|EPrints::MetaField]] specified.
 
Return a reference to an array of all the distinct values of the  [[API:EPrints/MetaField|EPrints::MetaField]] specified.
  
<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 -->
  
Line 1,487: Line 1,271:
 
Return a reference to a hash table where the keys are field value ids and the value is a reference to an array of ids.
 
Return a reference to a hash table where the keys are field value ids and the value is a reference to an array of ids.
  
<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 -->
  
Line 1,500: Line 1,282:
 
Attempt to dequeue upto $n events. May return between 0 and $n events depending on parallel processes and how many events are remaining on the queue.
 
Attempt to dequeue upto $n events. May return between 0 and $n events depending on parallel processes and how many events are remaining on the queue.
  
<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 -->
  
Line 1,509: Line 1,289:
 
<!-- Pod2Wiki=head_password_validation -->
 
<!-- Pod2Wiki=head_password_validation -->
 
===Password Validation===
 
===Password Validation===
<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 -->
  
Line 1,524: Line 1,302:
 
Returns the user's real (case-sensitive) username or undef if the passwords don't match.
 
Returns the user's real (case-sensitive) username or undef if the passwords don't match.
  
<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 -->
  
Line 1,535: Line 1,311:
 
To access database-stored objects use the methods provided by the following modules: [[API:EPrints/Repository|EPrints::Repository]], [[API:EPrints/DataSet|EPrints::DataSet]].
 
To access database-stored objects use the methods provided by the following modules: [[API:EPrints/Repository|EPrints::Repository]], [[API:EPrints/DataSet|EPrints::DataSet]].
  
<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 -->
  
Line 1,544: Line 1,318:
 
<!-- Pod2Wiki=head_copyright -->
 
<!-- Pod2Wiki=head_copyright -->
 
==COPYRIGHT==
 
==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 -->
  

Revision as of 08:54, 2 March 2012

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


Contents

NAME

EPrints::Database - a connection to the SQL database for an eprints session


SYNOPSIS

 $db = $repo->database
 $sth = $db->prepare("SELECT 'hello, world!'");
 $sth->execute;
 print $sth->fetchrow_arrayref->[0], "\n";
 


DESCRIPTION

EPrints Database Access Module

Provides access to the backend database. All database access is performed via this module to 1) provide cross-database support and 2) improve security through enforcing proper quoting of SQL values.

In most use-cases it should not be necessary to use the database module directly. Instead you should use EPrints::DataSet or EPrints::MetaField accessor methods to access objects and field values respectively.


Cross-database Support

Any use of SQL statements must use quote_identifier to quote database tables and columns and quote_value to quote values. The only exception to this are the EPrints::Database::* modules which provide database-driver specific extensions.


Quoting SQL Values

By convention variables that contain already quoted values are prefixed with 'Q_' so they can be easily recognised when used in string interpolation:

 my $Q_value = $db->quote_value( "Hello, World!" );
 $db->do("SELECT $Q_value");
 

Where possible you should avoid quoting values yourself, instead use a method that accepts unquoted values which will (safely) do the work for you.


METHODS

Database

new

$db = EPrints::Database->new( $repo )

Create a connection to the database.


create

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

Create and connect to a new database using super user account $username and $password.


connect

$ok = $db->connect

Connects to the database.


disconnect

$db->disconnect

Disconnects from the EPrints database.


set_debug

$db->set_debug( $boolean )

Set the SQL debug mode to true or false.


set_version

$db->set_version( $versionid );

Set the version id table in the SQL database to the given value (used by the upgrade script).


get_version

$version = $db->get_version

Returns the current database schema version.


is_latest_version

$boolean = $db->is_latest_version

Return true if the database schema is in the correct configuration for this version of eprints. Otherwise false.


get_server_version

$version = $db->get_server_version

Return the database server version.


get_default_charset

$charset = $db->get_default_charset( LANGUAGE )

Return the character set to use for LANGUAGE.

Returns undef if character sets are unsupported.


get_default_collation

$collation = $db->get_default_collation( LANGUAGE )

Return the collation to use for LANGUAGE.

Returns undef if collation is unsupported.


get_driver_name

$driver = $db->get_driver_name

Return the database driver name.


error

$errstr = $db->error

Return a string describing the last SQL error.


retry_error

$bool = $db->retry_error

Returns true if the current error is a retry error.


duplicate_error

$bool = $db->duplicate_error

Returns true if the current error is a PRIMARY KEY or UNIQUE error.


begin

$db->begin

Begin a transaction.


commit

$db->commit

Commit the previously begun transaction.


rollback

$db->rollback

Roll-back the current transaction.


type_info

$type_info = $db->type_info( DATA_TYPE )

See DBI/type_info.


get_column_type

$real_type = $db->get_column_type( NAME, TYPE, NOT_NULL, [ LENGTH/PRECISION ], [ SCALE ], %opts )

Returns a SQL column definition for NAME of type TYPE, usually something like:

 $name $type($length,$scale) [ NOT NULL ]
 

If NOT_NULL is true column will be set "not null".

LENGTH/PRECISION and SCALE control the maximum lengths of character or decimal types (see below).

Other options available to refine the column definition:

 langid - character set/collation to use
 sorted - whether this column will be used to order by
 

langid is mapped to real database values by the "dblanguages" configuration option. The database may not be able to order the request column type in which case, if sorted is true, the database may use a substitute column type.

TYPE is the SQL type. The types are constants defined by this module, to import them use:

 use EPrints::Database qw( :sql_types );
 

Supported types (n = requires LENGTH argument):

Character data: SQL_VARCHAR(n), SQL_LONGVARCHAR, SQL_CLOB.

Binary data: SQL_VARBINARY(n), SQL_LONGVARBINARY.

Integer data: SQL_TINYINT, SQL_SMALLINT, SQL_INTEGER, SQL_BIGINT.

Floating-point data: SQL_REAL, SQL_DOUBLE.

Time data: SQL_DATE, SQL_TIME.

The actual column types used will be database-specific.


Schema Manipulation

create_archive_tables

$success = $db->create_archive_tables

Create all the SQL tables for each dataset.


drop_archive_tables

$db->drop_archive_tables()

Destroy all tables used by eprints in the database.


create_version_table

$db->create_version_table

Make the version table (and set the only value to be the current version of eprints).


drop_version_table

$db->drop_version_table

Drop the version table.


create_dataset_tables

$success = $db->create_dataset_tables( $dataset )

Create all the SQL tables for a single dataset.


drop_dataset_tables

$db->drop_dataset_tables( $dataset )

Drop all the SQL tables for a single dataset.


create_dataset_index_tables

$success = $db->create_dataset_index_tables( $dataset )

Create all the index tables for a single dataset.


create_dataset_ordervalues_tables

$success = $db->create_dataset_ordervalues_tables( $dataset )

Create all the ordervalues tables for a single dataset.


has_dataset

$db->has_dataset( $dataset )

Returns true if $dataset exists in the database or has no database tables.

This does not check that all fields are configured - see has_field().


has_field

$db->has_field( $dataset, $field )

Returns true if $field is in the database for $dataset.


add_field

$db->add_field( $dataset, $field [, $force ] )

Add $field to $dataset's tables.

If $force is true will modify/replace an existing column (use with care!).


remove_field

$db->remove_field( $dataset, $field )

Remove $field from $dataset's tables.


rename_field

$ok = $db->rename_field( $dataset, $field, $old_name )

Rename a $field in the database from it's old name $old_name.

Returns true if the field was successfully renamed.


create_table

$success = $db->create_table( $tablename, $setkey, @fields );

Creates a new table $tablename based on @fields.

The first $setkey number of fields are used for a primary key.


create_foreign_key

$ok = $db->create_foreign_key( $main_table, $aux_table, $key_field )

Create a foreign key relationship between $main_table and $aux_table using the $key_field.

This will cause records in $aux_table to be deleted if the equivalent record is deleted from $main_table.


create_counters

$success = $db->create_counters

Create the counters used to store the highest current id of eprints, users etc.


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 called $name.


remove_counters

$success = $db->remove_counters

Destroy all counters.


drop_counter

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

Destroy the counter named $name.


counter_current

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

Return the value of the previous counter_next on $counter.


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 than $value. This is used when importing eprints which may not be in scrict sequence.


counter_reset

$db->counter_reset( $counter )

Reset the counter. Use with caution.


next_doc_pos

$n = $db->next_doc_pos( $eprintid )

Return the next unused document pos for the given eprintid.


SQL utility methods

do

$success = $db->do( $sql )

Execute the given SQL.


prepare

$sth = $db->prepare( $sql )

Prepare the SQL statement $sql for execution.

Use the execute method on the returned DBI handle to execute the SQL:

 my $sth = $db->prepare_select( "SELECT 'Hello, World'" );
 $sth->execute;
 


prepare_select

$sth = $db->prepare_select( $sql [, %options ] )

Prepare a SELECT statement $sql for execution.

Returns a DBI statement handle.

The LIMIT SQL keyword is not universally supported, to specify a LIMIT you must use the limit option.

Options:

 limit - limit the number of rows returned
 offset - return limit number of rows after offset
 


has_sequence

$boolean = $db->has_sequence( $name )

Return true if a sequence of the given name exists in the database.


create_sequence

$success = $db->create_sequence( $seq_name )

Creates a new sequence object initialised to zero.


drop_sequence

$success = $db->drop_sequence( $seq_name )

Deletes a sequence object.


drop_column

$success = $db->drop_column( $table, $column )

Drops a column from a table.


get_primary_key

@columns = $db->get_primary_key( $tablename )

Returns the list of column names that comprise the primary key for $tablename.

Returns empty list if no primary key exists.


create_primary_key

$db->create_primary_key( $tablename, @cols )

Create a PRIMARY KEY on $tablename over @cols.


create_index

$success = $db->create_index( $tablename, @columns )

Creates an index over @columns for $tablename. Returns true on success.


create_unique_index

$success = $db->create_unique_index( $tablename, @columns )

Creates a unique index over @columns for $tablename. Returns true on success.


index_name

$name = $db->index_name( $table, @columns )

Returns the name of the first index that starts with @columns on the $table table.

Returns undef if no index exists.


_update

$rows = $db->_update( $tablename, $keycols, $keyvals, $columns, @values )

UPDATES $tablename where $keycols equals $keyvals and returns the number of rows affected.

Note! If no rows are affected the result is still 'true', see DBI's execute() method.

This method is internal.


insert

$success = $db->insert( $table, $columns, @values )

Inserts values into the table $table. If $columns is defined it will be used as a list of columns to insert into. @values is a list of arrays containing values to insert.

Values will be quoted before insertion.


insert_quoted

$success = $db->insert_quoted( $table, $columns, @qvalues )

Inserts values into the table $table. If $columns is defined it will be used as a list of columns to insert into. @qvalues is a list of arrays containing values to insert.

Values will NOT be quoted before insertion - care must be exercised!


delete_from

$success = $db->delete_from( $table, $columns, @values )

Perform a SQL DELETE FROM $table using $columns to build a where clause. @values is a list of array references of values in the same order as $columns.

If you want to clear a table completely use clear_table().


count_table

$n = $db->count_table( $tablename )

Return the number of rows in the specified SQL table.


has_table

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

Return true if a table of the given name exists in the database.


has_column

$boolean = $db->has_column( $tablename, $columnname )

Return true if the a table of the given name has a column named $columnname in the database.


drop_table

$db->drop_table( $tablename [, $tablename2 ] )

Delete the named table(s). Use with caution!


clear_table

$db->clear_table( $tablename )

Clears all records from the given table, use with caution!


rename_table

$db->rename_table( $tablename, $newtablename )

Renames the table from the old name to the new one.


swap_table

$db->swap_table( $table_a, $table_b )

Swap table a and table b.


get_tables

@tables = $db->get_tables

Return a list of all the tables in the database.


Quoting Values

prep_int

$mungedvalue = EPrints::Database::prep_int( $value )

Escape a numerical value for SQL. undef becomes NULL. Anything else becomes a number (zero if needed).


prep_value

$mungedvalue = EPrints::Database::prep_value( $value )

Escape a value for SQL. Modify value such that " becomes \" and \ becomes \\ and ' becomes \'


prep_like_value

$mungedvalue = EPrints::Database::prep_like_value( $value )

Escape an value for an SQL like field. In addition to ' " and \ also escapes % and _


quote_value

$str = $db->quote_value( $value )

Return a quoted value. To quote a 'like' value you should do:

my $str = $database->quote_value( EPrints::Database::prep_like_value( $foo ) . '%' );
 


quote_int

$str = $db->quote_int( $value )

Return a quoted integer value


quote_binary

$str = $db->quote_binary( $bytes )

Some databases (Oracle/PostgreSQL) require transforms of binary data to work correctly.

This method should be called on data containing nul bytes or back-slashes before being passed on quote_value.


quote_ordervalue

$str = $db->quote_ordervalue( $field, $value )

Some databases (Oracle) can't order by CLOBS so need special treatment when creating the ordervalues tables. This method allows any fixing-up required for string data before it's inserted.


quote_identifier

$str = $db->quote_identifier( @parts )

Quote a database identifier (e.g. table names). Multiple @parts will be joined by dot.


prepare_regexp

$sql = $db->prepare_regexp( $quoted_column, $quoted_value )

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


sql_as

$sql = $db->sql_AS()

Returns the syntactic glue to use when aliasing. SQL 92 DBs will happilly use " AS " but some DBs (Oracle!) won't accept it.


sql_like

$sql = $db->sql_LIKE()

Returns the syntactic glue to use when making a case-insensitive LIKE. PostgreSQL requires "ILIKE" while everything else uses "LIKE" and the column collation.


Dataset Data

insert_data

$success = $db->insert_data( $dataset, $data )

Add the given data as a new record in the given dataset. $data is a reference to a hash containing values structured for a record in the that dataset.

Returns undef if a record already exists with the key field value in $data.

Inserts ordervalues if the dataset is ordered.


update_data

$success = $db->update_data( $dataset, $data, $changed )

Updates a record in the given $dataset. $data is a copy of the entire record's data and $changed the values that have changed.

If the record does not already exist or the key field is unset in $data no changes will be written.

Updates ordervalues if the dataset is ordered.


exists

$boolean = $db->exists( $dataset, $id )

Return true if a record with the given primary key exists in the dataset, otherwise false.


remove

$success = $db->remove( $dataset, $id )

Remove the record, index terms and order value with the key field value $id from the specified dataset.

Returns true on success.


Searching, Caching and Retrieval

cache_exp

$searchexp = $db->cache_exp( $cacheid )

Return the serialised Search of a the cached search with id $cacheid. Return undef if the id is invalid or expired.


cache

$cacheid = $db->cache( $searchexp, $dataset, $srctable, [$order], [$list] )

Create a cache of the specified search expression from the SQL table $srctable.

If $order is set then the cache is ordered by the specified fields. For example "-year/title" orders by year (descending). Records with the same year are ordered by title.

If $srctable is set to "LIST" then order is ignored and the list of ids is taken from the array reference $list.

If $srctable is set to "ALL" every matching record from $dataset is added to the cache, optionally ordered by $order.


cache_table

$tablename = $db->cache_table( $id )

Return the SQL table used to store the cache with id $id.


search

$ids = $db->search( $keyfield, $tables, $conditions, [$main_table_alias] )

Return a reference to an array of ids - the results of the search specified by $conditions accross the tables specified in the $tables hash where keys are tables aliases and values are table names.

If no table alias is passed then M is assumed.


drop_cache

$db->drop_cache( $id )

Remove the cached search with the given id.


from_cache

$foo = $db->from_cache( $dataset, $cacheid, [$offset], [$count], [$justids] )

Return a reference to an array containing all the items from the given dataset that have id's in the specified cache. The cache may be specified either by id or serialised search expression.

$offset is an offset from the start of the cache and $count is the number of records to return.

If $justids is true then it returns just an ref to an array of the record ids, not the objects.


drop_orphan_cache_tables

$c = $db->drop_orphan_cache_tables

Drop tables called "cacheXXX" where XXX is an integer. Returns the number of tables dropped.


get_single

$obj = $db->get_single( $dataset, $id )

Return a single item from the given dataset. The one with the specified id.


get_all

$items = $db->get_all( $dataset )

Returns a reference to an array with all the items from the given dataset.


get_cache_ids

@ids = $db->get_cache_ids( $dataset, $cachemap, $offset, $count )

Returns a list of $count ids from $cache_id starting at $offset and in the order in the cachemap.


get_dataobjs

@dataobjs = $db->get_dataobjs( $dataset [, $id [, $id ] ] )

Retrieves the records in $dataset with the given $id(s). If an $id doesn't exist in the database it will be ignored.


get_values

$foo = $db->get_values( $field, $dataset )

Return a reference to an array of all the distinct values of the EPrints::MetaField specified.


get_ids_by_field_values

$ids = $db->get_ids_by_field_values( $field, $dataset [ %opts ] )

Return a reference to a hash table where the keys are field value ids and the value is a reference to an array of ids.


dequeue_events

@events = $db->dequeue_events( $n )

Attempt to dequeue upto $n events. May return between 0 and $n events depending on parallel processes and how many events are remaining on the queue.


Password Validation

valid_login

$real_username = $db->valid_login( $username, $password )

Tests whether the clear-text $password matches the stored encrypted password for $username.

Returns the user's real (case-sensitive) username or undef if the passwords don't match.


SEE ALSO

To access database-stored objects use the methods provided by the following modules: EPrints::Repository, EPrints::DataSet.


COPYRIGHT