Difference between revisions of "API:EPrints/Database"

From EPrints Documentation
Jump to: navigation, search
(New page: <!-- Pod2Wiki=_preamble_ This page has been automatically generated from the EPrints source. Any wiki changes made between the 'Pod2Wiki=*' and 'End of Pod2Wiki' comments will be lost. -...)
 
(Removing all content from page)
Line 1: Line 1:
<!-- Pod2Wiki=_preamble_
 
This page has been automatically generated from the EPrints source. Any wiki changes made between the 'Pod2Wiki=*' and 'End of Pod2Wiki' comments will be lost.
 
-->{{Pod2Wiki}}{{API:Source|file=EPrints/Database.pm|package_name=EPrints::Database}}[[Category:API|Database]]<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=head_name -->=NAME=
 
'''EPrints::Database''' - a connection to the SQL database for an eprints session.
 
  
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=head_description -->=DESCRIPTION=
 
EPrints Database Access Module
 
 
Provides access to the backend database. All database access done via this module, in the hope that the backend can be replaced as easily as possible.
 
 
The database object is created automatically when you start a new eprints session. To get a handle on it use:
 
 
$db = $session-&gt;get_repository
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=head_cross_database_support -->==Cross-database Support==
 
Any use of SQL must use quote_identifier to quote database tables and columns. The only exception to this are the Database::* modules which provide database-driver specific extensions.
 
 
Variables that are database quoted are prefixed with 'Q_'.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_build_connection_string -->===build_connection_string===
 
 
  $dbstr = EPrints::Database::build_connection_string( %params )
 
 
Build the string to use to connect to the database via DBI. %params  must contain dbname, and may also contain dbport, dbhost and dbsock.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_new -->===new===
 
 
  $db = EPrints::Database-&gt;new( $session )
 
 
Create a connection to the database.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_connect -->===connect===
 
 
  $foo = $db-&gt;connect
 
 
Connects to the database.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_disconnect -->===disconnect===
 
 
  $foo = $db-&gt;disconnect
 
 
Disconnects from the EPrints database. Should always be done before any script exits.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_error -->===error===
 
 
  $errstr = $db-&gt;error
 
 
Return a string describing the last SQL error.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_begin -->===begin===
 
 
  $db-&gt;begin
 
 
Begin a transaction.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_commit -->===commit===
 
 
  $db-&gt;commit
 
 
Commit the previous begun transaction.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_rollback -->===rollback===
 
 
  $db-&gt;rollback
 
 
Rollback the partially completed transaction.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_create_archive_tables -->===create_archive_tables===
 
 
  $success = $db-&gt;create_archive_tables
 
 
Create all the SQL tables for each dataset.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_create_dataset_tables -->===create_dataset_tables===
 
 
  $success = $db-&gt;create_dataset_tables( $dataset )
 
 
Create all the SQL tables for a single dataset.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_drop_dataset_tables -->===drop_dataset_tables===
 
 
  $db-&gt;drop_dataset_tables( $dataset )
 
 
Drop all the SQL tables for a single dataset.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_create_dataset_index_tables -->===create_dataset_index_tables===
 
 
  $success = $db-&gt;create_dataset_index_tables( $dataset )
 
 
Create all the index tables for a single dataset.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_create_dataset_ordervalues_tables -->===create_dataset_ordervalues_tables===
 
 
  $success = $db-&gt;create_dataset_ordervalues_tables( $dataset )
 
 
Create all the ordervalues tables for a single dataset.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_get_column_type -->===get_column_type===
 
 
  $real_type = $db-&gt;get_column_type( NAME, TYPE, NOT_NULL, [, LENGTH ] )
 
 
Returns a column definition for NAME of type TYPE. If NOT_NULL is true the column will be created NOT NULL. For column types that require a length use LENGTH.
 
 
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.
 
 
Binary data: SQL_VARBINARY(n), SQL_LONGVARBINARY.
 
 
Integer data: SQL_TINYINT, SQL_SMALLINT, SQL_INTEGER.
 
 
Floating-point data: SQL_REAL, SQL_DOUBLE.
 
 
Time data: SQL_DATE, SQL_TIME.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_create_table -->===create_table===
 
 
  $success = $db-&gt;create_table( $tablename, $dataset, $setkey, @fields );
 
 
Create the tables used to store metadata for this dataset: the main table and any required for multiple or mulitlang fields.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_has_sequence -->===has_sequence===
 
 
  $boolean = $db-&gt;has_sequence( $name )
 
 
Return true if a sequence of the given name exists in the database.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_create_sequence -->===create_sequence===
 
 
  $success = $db-&gt;create_sequence( $seq_name )
 
 
Creates a new sequence object initialised to zero.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_drop_sequence -->===drop_sequence===
 
 
  $success = $db-&gt;drop_sequence( $seq_name )
 
 
Deletes a sequence object.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_get_primary_key -->===get_primary_key===
 
 
  @columns = $db-&gt;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.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_create_index -->===create_index===
 
 
  $success = $db-&gt;create_index( $tablename, @columns )
 
 
Creates an index over @columns for $tablename. Returns true on success.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_create_unique_index -->===create_unique_index===
 
 
  $success = $db-&gt;create_unique_index( $tablename, @columns )
 
 
Creates a unique index over @columns for $tablename. Returns true on success.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item__update -->===_update===
 
 
  $success = $db-&gt;_update( $tablename, $keycols, $keyvals, $columns, @values )
 
 
UDATES $tablename where $keycols equals $keyvals.
 
 
This method is internal.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item__update_quoted -->===_update_quoted===
 
 
  $success = $db-&gt;_update_quoted( $tablename, $keycols, $keyvals, $columns, @values )
 
 
UDATES $tablename where $keycols equals $keyvals. Won't quote @keyvals or @values before use - use this method with care!
 
 
This method is internal.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_insert -->===insert===
 
 
  $success = $db-&gt;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.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_insert_quoted -->===insert_quoted===
 
 
  $success = $db-&gt;insert_quoted( $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 NOT be quoted before insertion - care must be exercised!
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_delete_from -->===delete_from===
 
 
  $success = $db-&gt;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().
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_add_record -->===add_record===
 
 
  $success = $db-&gt;add_record( $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.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_prep_int -->===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).
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_prep_value -->===prep_value===
 
 
  $mungedvalue = EPrints::Database::prep_value( $value )
 
 
Escape a value for SQL. Modify value such that " becomes \" and \  becomes \\ and ' becomes \'
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_prep_like_value -->===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 _
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_quote_value -->===quote_value===
 
 
  $str = EPrints::Database::quote_value( $value )
 
 
Return a quoted value. To quote a 'like' value you should do:
 
 
my $str = $database-&gt;quote_value( EPrints::Database::prep_like_value( $foo ) . '%' );
 
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_quote_int -->===quote_int===
 
 
  $str = EPrints::Database::quote_int( $value )
 
 
Return a quoted integer value
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_quote_identifier -->===quote_identifier===
 
 
  $str = EPrints::Database::quote_identifier( @parts )
 
 
Quote a database identifier (e.g. table names). Multiple @parts will be joined by dot.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_update -->===update===
 
 
  $success = $db-&gt;update( $dataset, $data, $insert )
 
 
Updates a record in the database with the given $data. Obviously the value of the primary key must be set.
 
 
This also updates the text indexes and the ordering keys.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_remove -->===remove===
 
 
  $success = $db-&gt;remove( $dataset, $id )
 
 
Attempts to remove the record with the primary key $id from the  specified dataset.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_create_counters -->===create_counters===
 
 
  $success = $db-&gt;create_counters
 
 
Create the counters used to store the highest current id of eprints, users etc.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_has_counter -->===has_counter===
 
 
  $success = $db-&gt;has_counter( $counter )
 
 
Returns true if $counter exists.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_create_counter -->===create_counter===
 
 
  $success = $db-&gt;create_counter( $name )
 
 
Create and initialise to zero a new counter called $name.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_remove_counters -->===remove_counters===
 
 
  $success = $db-&gt;remove_counters
 
 
Destroy all counters.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_drop_counter -->===drop_counter===
 
 
  $success = $db-&gt;drop_counter( $name )
 
 
Destroy the counter named $name.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_next_doc_pos -->===next_doc_pos===
 
 
  $n = $db-&gt;next_doc_pos( $eprintid )
 
 
Return the next unused document pos for the given eprintid.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_counter_current -->===counter_current===
 
 
  $n = $db-&gt;counter_current( $counter )
 
 
Return the value of the previous counter_next on $counter.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_counter_next -->===counter_next===
 
 
  $n = $db-&gt;counter_next( $counter )
 
 
Return the next unused value for the named counter. Returns undef if  the counter doesn't exist.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_counter_minimum -->===counter_minimum===
 
 
  $db-&gt;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.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_counter_reset -->===counter_reset===
 
 
  $db-&gt;counter_reset( $counter )
 
 
Reset the counter. Use with caution.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_cache_exp -->===cache_exp===
 
 
  $searchexp = $db-&gt;cache_exp( $cacheid )
 
 
Return the serialised Search of a the cached search with id $cacheid. Return undef if the id is invalid or expired.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_cache -->===cache===
 
 
  $cacheid = $db-&gt;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.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_cache_table -->===cache_table===
 
 
  $tablename = $db-&gt;cache_table( $id )
 
 
Return the SQL table used to store the cache with id $id.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_create_buffer -->===create_buffer===
 
 
  $tablename = $db-&gt;create_buffer( $keyname )
 
 
Create a temporary table with the given keyname. This table will not be available to other processes and should be disposed of when you've finished with them - MySQL only allows so many temporary tables.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_make_buffer -->===make_buffer===
 
 
  $id = $db-&gt;make_buffer( $keyname, $data )
 
 
Create a temporary table and dump the values from the array reference $data into it.
 
 
Even in debugging mode it does not mention this SQL as it's very dull.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_garbage_collect -->===garbage_collect===
 
 
  $foo = $db-&gt;garbage_collect
 
 
Loop through known temporary tables, and remove them.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_dispose_buffer -->===dispose_buffer===
 
 
  $db-&gt;dispose_buffer( $id )
 
 
Remove temporary table with given id. Won't just remove any old table.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_get_index_ids -->===get_index_ids===
 
 
  $ids = $db-&gt;get_index_ids( $table, $condition )
 
 
Return a reference to an array of the distinct primary keys from the given SQL table which match the specified condition.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_search -->===search===
 
 
  $ids = $db-&gt;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.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_drop_cache -->===drop_cache===
 
 
  $db-&gt;drop_cache( $id )
 
 
Remove the cached search with the given id.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_count_table -->===count_table===
 
 
  $n = $db-&gt;count_table( $tablename )
 
 
Return the number of rows in the specified SQL table.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_from_buffer -->===from_buffer===
 
 
  $items = $db-&gt;from_buffer( $dataset, $buffer, [$offset], [$count], [$justids] )
 
 
Return a reference to an array containing all the items from the given dataset that have id's in the specified buffer.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_from_cache -->===from_cache===
 
 
  $foo = $db-&gt;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.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_drop_old_caches -->===drop_old_caches===
 
 
  $db-&gt;drop_old_caches
 
 
Drop all the expired caches.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_get_single -->===get_single===
 
 
  $obj = $db-&gt;get_single( $dataset, $id )
 
 
Return a single item from the given dataset. The one with the specified id.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_get_all -->===get_all===
 
 
  $items = $db-&gt;get_all( $dataset )
 
 
Returns a reference to an array with all the items from the given dataset.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_get_values -->===get_values===
 
 
  $foo = $db-&gt;get_values( $field, $dataset )
 
 
Return a reference to an array of all the distinct values of the  EPrints::MetaField specified.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_get_ids_by_field_values -->===get_ids_by_field_values===
 
 
  $ids = $db-&gt;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.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_do -->===do===
 
 
  $success = $db-&gt;do( $sql )
 
 
Execute the given SQL.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_prepare -->===prepare===
 
 
  $sth = $db-&gt;prepare( $sql )
 
 
Prepare the given $sql and return a handle on it.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_prepare_select -->===prepare_select===
 
 
  $sth = $db-&gt;prepare_select( $sql [, %options ] )
 
 
Prepare a SELECT statement $sql and return a handle to it. After preparing a statement use execute() to execute it.
 
 
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
 
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_execute -->===execute===
 
 
  $success = $db-&gt;execute( $sth, $sql )
 
 
Execute the SQL prepared earlier. $sql is only passed in for debugging purposes.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_has_dataset -->===has_dataset===
 
 
  $db-&gt;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().
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_has_field -->===has_field===
 
 
  $db-&gt;has_field( $dataset, $field )
 
 
Returns true if $field is in the database for $dataset.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_add_field -->===add_field===
 
 
  $db-&gt;add_field( $dataset, $field )
 
 
Add $field to $dataset's tables.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_remove_field -->===remove_field===
 
 
  $db-&gt;remove_field( $dataset, $field )
 
 
Remove $field from $dataset's tables.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_exists -->===exists===
 
 
  $boolean = $db-&gt;exists( $dataset, $id )
 
 
Return true if a record with the given primary key exists in the dataset, otherwise false.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_set_timer -->===set_timer===
 
 
  $db-&gt;set_timer( $boolean )
 
 
Set the detailed timing option.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_set_debug -->===set_debug===
 
 
  $db-&gt;set_debug( $boolean )
 
 
Set the SQL debug mode to true or false.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_create_version_table -->===create_version_table===
 
 
  $db-&gt;create_version_table
 
 
Make the version table (and set the only value to be the current version of eprints).
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_set_version -->===set_version===
 
 
  $db-&gt;set_version( $versionid );
 
 
Set the version id table in the SQL database to the given value (used by the upgrade script).
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_has_table -->===has_table===
 
 
  $boolean = $db-&gt;has_table( $tablename )
 
 
Return true if the a table of the given name exists in the database.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_has_column -->===has_column===
 
 
  $boolean = $db-&gt;has_column( $tablename, $columnname )
 
 
Return true if the a table of the given name has a column named $columnname in the database.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_install_table -->===install_table===
 
 
  $db-&gt;install_table( $tablename, $newtablename )
 
 
Move table $tablename to $newtablename. Erase $newtablename if it exists.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_drop_table -->===drop_table===
 
 
  $db-&gt;drop_table( $tablename )
 
 
Delete the named table. Use with caution!
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_clear_table -->===clear_table===
 
 
  $db-&gt;clear_table( $tablename )
 
 
Clears all records from the given table, use with caution!
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_rename_table -->===rename_table===
 
 
  $db-&gt;rename_table( $tablename, $newtablename )
 
 
Renames the table from the old name to the new one.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_swap_table -->===swap_table===
 
 
  $db-&gt;swap_table( $table_a, $table_b )
 
 
Swap table a and table b.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_get_tables -->===get_tables===
 
 
  @tables = $db-&gt;get_tables
 
 
Return a list of all the tables in the database.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_get_version -->===get_version===
 
 
  $version = $db-&gt;get_version
 
 
Return the version of eprints which the database is compatable with or undef if unknown (before v2.1).
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_is_latest_version -->===is_latest_version===
 
 
  $boolean = $db-&gt;is_latest_version
 
 
Return true if the SQL tables are in the correct configuration for this edition of eprints. Otherwise false.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_valid_login -->===valid_login===
 
 
  $db-&gt;valid_login( $username, $password )
 
 
Returns whether the clear-text $password matches the stored crypted password for $username.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_index_queue -->===index_queue===
 
 
  $db-&gt;index_queue( $datasetid, $objectid, $fieldname [, $fieldname ] );
 
 
Queues the field of the specified object to be reindexed.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_index_dequeue -->===index_dequeue===
 
 
  ($datasetid, $objectid, $field) = $db-&gt;index_dequeue();
 
 
Pops an item off the queue. Returns empty list if nothing left.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=head_permissions -->==Permissions==
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_add_roles -->===add_roles===
 
 
  $db-&gt;add_roles( $privilege, $ip_from, $ip_to, @roles )
 
 
Add $privilege to @roles, optionally in net space $ip_from to $ip_to.
 
 
If $privilege begins with '@' adds @roles to that group.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_remove_roles -->===remove_roles===
 
 
  $db-&gt;remove_roles( $privilege, $ip_from, $ip_to, @roles )
 
 
Remove $privilege from @roles, $ip_from and $ip_to are currently ignored, but this behaviour may change in future.
 
 
If $privilege beings with '@' removes @roles from that group instead.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_get_privileges -->===get_privileges===
 
 
  %privs = $db-&gt;get_privileges( [$role] )
 
 
Return the privileges granted for $role. If $role is undefined returns all set privileges.
 
 
Returns a hash:
 
 
  role =&gt; {
 
    priv1 =&gt; [ ip_from, ip_to ],
 
    priv2 =&gt; [ ip_from, ip_to ],
 
  }
 
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_get_groups -->===get_groups===
 
 
  %groups = $db-&gt;get_groups( [$role] )
 
 
Returns a list of groups that $role belongs to, or all groups if $role is undefined.
 
 
Returns a hash:
 
 
  role =&gt; [ group1, group2, group3 ]
 
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_get_roles -->===get_roles===
 
 
  @roles = $db-&gt;get_roles( $privilege, $remote_ip, @roles )
 
 
Get the matching roles for @roles that have $privilege, optionally restricted to $remote_ip.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_get_server_version -->===get_server_version===
 
 
  $version = $db-&gt;get_server_version
 
 
Return the database server version.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_get_driver_name -->===get_driver_name===
 
 
  $driver = $db-&gt;get_driver_name
 
 
Return the database driver name.
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=head_undocumented_methods -->=UNDOCUMENTED METHODS=
 
{{API:Undocumented Methods}}<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_add_index_to_indextable -->==add_index_to_indextable==
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_cache_userid -->==cache_userid==
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_clear_user_messages -->==clear_user_messages==
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_create_login_tickets_table -->==create_login_tickets_table==
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_get_ticket_userid -->==get_ticket_userid==
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_get_user_messages -->==get_user_messages==
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_save_user_message -->==save_user_message==
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_swap_tables -->==swap_tables==
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=item_update_ticket_userid -->==update_ticket_userid==
 
 
<!-- End of Pod2Wiki -->
 
<!-- Pod2Wiki=_postamble_ --><!-- End of Pod2Wiki -->
 

Revision as of 15:39, 12 August 2009