NAME
App::DBBrowser database plugin documentation.
VERSION
Version 0.993
DESCRIPTION
A database plugin provides the database specific methods. App::DBBrowser considers a module whose name matches the regex pattern /^App::DBBrowser::DB::[\w_]+\z/ and which is located in one of the @INC directories as a database plugin. Plugins with the name App::DBBrowser::DB::$database_driver should be for general use of $database_driver databases.
The user can add an installed database plugin to the available plugins in the option menu (db-browser -h) by selecting DB and then DB Plugins.
A suitable database plugin provides the methods named in this documentation.
Column names passed as arguments are already quoted with the DBI quote_identifier method.
PLUGIN API VERSION
This documentation describes the plugin API version 1.1.
Plugins which comply with the plugin API version 1.0 are still supported partially but the support for these plugins will be removed soon so it is recommended to update these plugins to comply with the plugin API version 1.1.
METHODS
new
The constructor method.
- Arguments
-
A reference to a hash. The hash entries are:
app_dir # path to the application directoriy db_plugin # name of the database plugin metadata # true or false # SQLite only: sqlite_search if true, don't use cached database names db_cache_file path to the file with the cached database names directories_sqlite directories where to search for databases - return
-
The object.
plugin_api_version
- Arguments
-
none
- return
-
The version of the plugin-API to which the plugin refers.
See "PLUGIN API VERSION" for the plugin API version described by this documentation.
db_driver
- Arguments
-
none
- return
-
The name of the
DBIdatabase driver used by the plugin.
driver_prefix
- Arguments
-
none
- return
-
The driver-private prefix.
login_data
- Arguments
-
none
- return
-
A reference to an array of hashes. The hashes have three key-value pairs:
{ name => 'string', prompt => 'string', keep_secret => true/false }nameholds the name of the login data for example like "user" or "host".The value of
promptis used as the prompt string, when the user is asked for the login data.If
keep_secretis true, the user input should not be echoed to the terminal. Also the login data is not stored in the plugin configuration file ifkeep_secretis true.
An example login_data method:
sub login_data {
my ( $self ) = @_;
return [
{ name => 'host', prompt => "Host", keep_secret => 0 },
{ name => 'port', prompt => "Port", keep_secret => 0 },
{ name => 'user', prompt => "User", keep_secret => 0 },
{ name => 'pass', prompt => "Password", keep_secret => 1 },
];
}
The information returned by method login_data is used to build the entries of the db-browser options DB Login Mode and DB Login Data.
connect_attributes
- Arguments
-
none
- return
-
A reference to an array of hashes. The hashes have three key-value pairs:
{ name => 'string', default_index => index, avail_values => [ value_1, value_2, value_3, ... ] }The value of
nameis the name of the database connection attribute.avail_valuesholds the available values for that connection attribute as an array reference.The
avail_valuesarray entry of the index positiondefault_indexis used as default value.
Example form the plugin App::DBBrowser::DB::SQLite:
sub connect_attributes {
my ( $self ) = @_;
return [
{ name => 'sqlite_unicode', default_index => 1, avail_values => [ 0, 1 ] },
{ name => 'sqlite_see_if_its_a_number', default_index => 1, avail_values => [ 0, 1 ] },
];
}
available_databases
- Arguments
-
A reference to a hash. If
available_databasesuses theget_db_handlemethod, the hash reference can be passed toget_db_handleas the second argument. See "get_db_handle" for more info. - return
-
If the option metadata is true,
available_databasesreturns the "user-databases" as an array-reference and the "system-databases" (if any) as an array-reference.If the option metadata is not true,
available_databasesreturns only the "user-databases" as an array-reference.
get_db_handle
- Arguments
-
The database name and a reference to a hash of hashes.
The hash of hashes provides the settings gathered from the option Database settings.
$connect_parameter = { attributes => { connect_attribute => chosen value, connect_attribute => chosen value, ... }, login_mode => { # ask use environment variable don't ask name => 0, 1 or 2, # 0 1 2 name => 0, 1 or 2, # 0 1 2 ... }, login_data => { name => user input, name => user input, ... }, keep_secret = { name => true or false, name => true or false, ... }, };For example for the plugin
mysqlthe hash of hashes held by$connect_parametercould look like this:$connect_parameter = { login_data => { host => undef, pass => undef, user => 'db_user_name', port => undef }, attributes => { mysql_enable_utf8 => 1 }, login_mode => { port => 2, # don't ask user => 1, # use environment variable if available pass => 1, # use environment variable if available host => 2 # don't ask }, keep_secret => { port => 0, host => 0, pass => 1, user => 0 } }; - return
-
Database handle.
get_schema_names
- Arguments
-
The database handle and the database name.
- return
-
If the option metadata is true,
get_schema_namesreturns the "user-schemas" as an array-reference and the "system-schemas" (if any) as an array-reference.If the option metadata is not true,
get_schema_namesreturns only the "user-schemas" as an array-reference.
get_table_names
- Arguments
-
The database handle and the schema name.
- return
-
If the option metadata is true,
get_table_namesreturns the "user-tables" as an array-reference and the "system-tables" (if any) as an array-reference.If the option metadata is not true,
get_table_namesreturns only the "user-tables" as an array-reference.
column_names_and_types
The method column_names_and_types is optional.
- Arguments
-
Database handle, database name, schema name, available tables as an array reference.
- return
-
Two hash references - one for the column names and one for the column types:
$col_names = { table_1 => [ column_1_name, column_2_name, ... ], table_2 => [ column_1_name, column_2_name, ... ], ... } $col_types = { table_1 => [ column_1_type, column_2_type, ... ], table_2 => [ column_1_type, column_2_type, ... ], ... }
primary_and_foreign_keys
The method primary_and_foreign_keys is optional.
- Arguments
-
Database handle, database name, schema name, available tables as an array reference.
- return
-
Two hash references - one for the primary keys and one for the foreign keys:
$primary_keys = { table_1 => [ 'primary_key_col_1' [ , ... ] ], table_2 => [ 'primary_key_col_1' [ , ... ] ], ... }; $foreign_keys = { table_1 => { fk_name_1 => { foreign_key_col => [ 'foreign_key_col_1' [ , ... ] ], reference_table => 'Reference_table', reference_key_col => [ 'reference_key_col_1' [ , ... ] ], fk_name_2 => { ... } table_2 => { ... } };
sql_regexp
- Arguments
-
Column name,
$do_not_match_regexp(true/false),$case_sensitive(true/false).Use the placeholder instead of the string which should match or not match the regexp.
- return
-
The sql regexp substatement.
Example form the plugin App::DBBrowser::DB::mysql:
sub sql_regexp {
my ( $self, $col, $do_not_match_regexp, $case_sensitive ) = @_;
if ( $do_not_match_regexp ) {
return ' '. $col . ' NOT REGEXP ?' if ! $case_sensitive;
return ' '. $col . ' NOT REGEXP BINARY ?' if $case_sensitive;
}
else {
return ' '. $col . ' REGEXP ?' if ! $case_sensitive;
return ' '. $col . ' REGEXP BINARY ?' if $case_sensitive;
}
}
concatenate
- Arguments
-
A reference to an array of strings.
- return
-
The sql substatement which concatenates the passed strings.
Example form the plugin App::DBBrowser::DB::Pg:
sub concatenate {
my ( $self, $arg ) = @_;
return join( ' || ', @$arg );
}
epoch_to_datetime
- Arguments
-
The column name and the interval.
The interval is 1 (seconds), 1000 (milliseconds) or 1000000 (microseconds).
- return
-
The sql epoch to datetime substatement.
Example form the plugin App::DBBrowser::DB::mysql:
sub epoch_to_datetime {
my ( $self, $col, $interval ) = @_;
return "FROM_UNIXTIME($col/$interval,'%Y-%m-%d %H:%i:%s')";
}
epoch_to_date
- Arguments
-
The column name and the interval.
The interval is 1 (seconds), 1000 (milliseconds) or 1000000 (microseconds).
- return
-
The sql epoch to date substatement.
Example form the plugin App::DBBrowser::DB::mysql:
sub epoch_to_date {
my ( $self, $col, $interval ) = @_;
return "FROM_UNIXTIME($col/$interval,'%Y-%m-%d')"; # example MySQL
}
truncate
- Arguments
-
The column name and the precision (int).
- return
-
The sql truncate substatement.
Example form the plugin App::DBBrowser::DB::mysql:
sub truncate {
my ( $self, $col, $precision ) = @_;
return "TRUNCATE($col,$precision)";
}
bit_length
- Arguments
-
The column name.
- return
-
The sql bit length substatement.
Example form the plugin App::DBBrowser::DB::Pg:
The sql bit length substatement.
sub bit_length {
my ( $self, $col ) = @_;
return "BIT_LENGTH($col)";
}
char_length
- Arguments
-
The column name.
- return
-
The sql char length substatement.
Example form the plugin App::DBBrowser::DB::Pg:
sub char_length {
my ( $self, $col ) = @_;
return "CHAR_LENGTH($col)";
}
CREDITS
Thanks to the Perl-Community.de and the people form stackoverflow for the help.
AUTHOR
Matthäus Kiem <cuer2s@gmail.com>
LICENSE AND COPYRIGHT
Copyright 2012-2014 Matthäus Kiem.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl 5.10.0. For details, see the full text of the licenses in the file LICENSE.