API:EPrints/Database/Pg

From EPrints Documentation
Jump to: navigation, search

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


API: Core API

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


NAME

EPrints::Database::Pg - custom database methods for PostgreSQL DB

User Comments


DESCRIPTION

PostgreSQL database wrapper.

User Comments


Synopsis

   $c->{dbdriver} = 'Pg';
   # $c->{dbhost} = 'localhost';
   $c->{dbname} = 'myrepo';
   $c->{dbuser} = 'bob';
   $c->{dbpass} = 'asecret';
   $c->{dbschema} = 'eprints';
 

User Comments


PostgreSQL-specific Annoyances

The DBD::Pg SQL_VARCHAR type is mapped to TEXT instead of VARCHAR(n).

User Comments


CONSTANTS

See EPrints::Database.

User Comments


INSTANCE VARIABLES

See EPrints::Database.

User Comments


METHODS

User Comments


connect

$db->connect

Connects to the database.

User Comments


type_info

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

See DBI/type_info.

Uses SMALLINT with column size 3 for SQL_TINYINT.

Uses VARCHAR with column size 255 for SQL_VARCHAR rather than TEXT which is the default for DBD:Pg.

Uses TEXT with column size 2^31 for SQL_LONGVARCHAR and SQL_CLOB.

Uses BYTEA with column size 2^31 for SQL_LONGVARBINARY.

User Comments


create

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

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

User Comments


get_column_type

$real_type = $db->get_column_type( $name, $type, $not_null, [ $length ] )

Returns a SQL column definition for $name of type $type. If $not_null is true the column will be set to 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.

User Comments


has_table

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

Returns boolean dependent on whether the named $table exists in the database.

For PostGres column_info() under DBD::Pg returns reserved identifiers in quotes, so instead we'll query the information_schema.

User Comments


has_column

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

Return true if the named database $table has the named $column.

User Comments


has_sequence

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

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

User Comments


get_tables

@tables = $db->get_tables

Return a list of all the tables in the database.

User Comments


counter_current

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

Return the value of the previous counter_next on $counter.

User Comments


counter_next

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

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

User Comments


quote_binary

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

PostgreSQL requires transforms of binary data to work correctly.

This sets pg_type to DBD::Pg::Pg_BYTEA for returned $bytes.

User Comments


prepare_regexp

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

PostgreSQL use the syntax:

$col ~* $value
 

For the quoted regexp $value and the quoted column $col.

User Comments


index_name

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

Should return the name of the first index that starts with named columns @cols in the named $table. However, this is not supported by PostgreSQL so always returns 1.

User Comments


sql_like

$sql = $db->sql_LIKE()

Returns the syntactic glue to use when making a case-insensitive ILIKE.

User Comments


SEE ALSO

EPrints::Database

User Comments


COPYRIGHT

© Copyright 2023 University of Southampton.

EPrints 3.4 is supplied by EPrints Services.

http://www.eprints.org/eprints-3.4/

LICENSE

This file is part of EPrints 3.4 http://www.eprints.org/.

EPrints 3.4 and this file are released under the terms of the GNU Lesser General Public License version 3 as published by the Free Software Foundation unless otherwise stated.

EPrints 3.4 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with EPrints 3.4. If not, see http://www.gnu.org/licenses/.

User Comments