class SqlPgsql extends SqlBase (View source)

Traits

Note: when using this trait, also implement ConfigAwareInterface/ConfigAwareTrait.

ConfigAwareTrait

Properties

string $queryExtra
string $queryFile
protected Process $process from  SqlBase

Methods

array
getExpandedTableSelection(array $options, array $all_tables)

Given a list of all tables, expand the convert the wildcards in the option-provided lists into a list of actual table names.

array
expandAndFilterTables(array $tables, array $db_tables)

Given the table names in the input array that may contain wildcards (*), expand the table names so that the array returned only contains table names that exist in the database.

array
expandWildcardTables(array $tables, array $db_tables)

Expand wildcard tables.

array
filterTables(array $tables, array $db_tables)

Filters tables.

array
getTableSelection(array $options)

Construct an array that places table names in appropriate buckets based on whether the table is to be skipped, included for structure only, or have structure and data dumped.

array
getRawTableList(string $option_name, array $options)

Consult the specified options and return the list of tables specified.

getConfig()

Replaces same method in ConfigAwareTrait in order to provide a DrushConfig as return type. Helps with IDE completion.

__construct(array $dbSpec, array $options)

Typically, SqlBase instances are constructed via SqlBase::create($options).

from  SqlBase
array
getEnv()

Get environment variables to pass to Process.

Process
getProcess()

Get the last used Process.

from  SqlBase
void
setProcess(Process $process)

No description

from  SqlBase
static SqlBase|null
create(array $options = [])

Get a driver specific instance of this class.

from  SqlBase
static SqlBase|null
getInstance($db_spec, $options)

No description

from  SqlBase
array
getDbSpec()

No description

from  SqlBase
void
setDbSpec(array $dbSpec)

Set the current db spec.

from  SqlBase
string
command()

The unix command used to connect to the database.

string
connect(bool $hide_password = true)

A string for connecting to a database.

from  SqlBase
string|bool|null
dump()

No description

from  SqlBase
string
addPipeFail(string $cmd, string $pipefail)

Handle 'pipefail' option for the specified command.

from  SqlBase
string
dumpCmd($table_selection)

No description

string|null
dumpFile($file)

No description

from  SqlBase
bool|null
query(string $query, $input_file = null, $result_file = '')

Execute a SQL query. Respect simulate mode.

from  SqlBase
bool
alwaysQuery(string $query, $input_file = null, string|null $result_file = '')

Execute a SQL query. Always execute regardless of simulate mode.

from  SqlBase
void
logQueryInDebugMode($query, $input_file_original)

Show the query in debug mode and simulate mode

from  SqlBase
string|null
silent()

No description

from  SqlBase
string|null
queryPrefix($query)

No description

from  SqlBase
queryFormat($query)

No description

bool|null
drop(array $tables)

Drop specified database.

string
createdbSql($dbname, bool $quoted = false)

Build a SQL string for dropping and creating a database.

bool|null
createdb(bool $quoted = false)

Create a new database.

bool
dropOrCreate()

Drop all tables (if DB exists) or CREATE target database.

from  SqlBase
bool
dbExists()

No description

string
creds(bool $hide_password = true)

Build a string containing connection credentials.

string
scheme()

The active database driver.

from  SqlBase
array
listTables()

Extract the name of all existing tables in the given database.

array
listTablesQuoted()

Extract the name of all existing tables in the given database.

from  SqlBase
string
paramsToOptions($parameters)

No description

from  SqlBase
void
su()

Adjust DB connection with superuser credentials if provided.

from  SqlBase
array
getOptions()

No description

from  SqlBase
getOption($name, $default = null)

No description

from  SqlBase
static array
dbSpecFromDbUrl($db_url)

Convert from an old-style database URL to an array of database settings.

from  SqlBase
array
alwaysQueryCommand($input_file)

Start building the command to run a query.

from  SqlBase
string|null
getPasswordFile()

No description

Details

array getExpandedTableSelection(array $options, array $all_tables)

Given a list of all tables, expand the convert the wildcards in the option-provided lists into a list of actual table names.

Parameters

array $options

An options array as passed to an Annotated Command.

array $all_tables

A list of all eligible tables.

Return Value

array

array of tables with each table name in the appropriate element of the array.

array expandAndFilterTables(array $tables, array $db_tables)

Given the table names in the input array that may contain wildcards (*), expand the table names so that the array returned only contains table names that exist in the database.

Parameters

array $tables

An array of table names where the table names may contain the * wildcard character.

array $db_tables

The list of tables present in a database.

Return Value

array

array of tables with non-existant tables removed.

array expandWildcardTables(array $tables, array $db_tables)

Expand wildcard tables.

Parameters

array $tables

An array of table names, some of which may contain wildcards (*).

array $db_tables

An array with all the existing table names in the current database.

Return Value

array

array filterTables(array $tables, array $db_tables)

Filters tables.

Parameters

array $tables

An array of table names to filter.

array $db_tables

An array with all the existing table names in the current database.

Return Value

array

array with only valid table names (i.e. all of which actually exist in the database).

array getTableSelection(array $options)

Construct an array that places table names in appropriate buckets based on whether the table is to be skipped, included for structure only, or have structure and data dumped.

The keys of the array are:

  • skip: tables to be skipped completed in the dump
  • structure: tables to only have their structure i.e. DDL dumped
  • tables: tables to have structure and data dumped

Parameters

array $options

Return Value

array

array of table names with each table name in the appropriate element of the array.

array getRawTableList(string $option_name, array $options)

Consult the specified options and return the list of tables specified.

Parameters

string $option_name
array $options

An options array as passed to an Annotated Command.

Return Value

array

an array of tables based on the first option found, or an empty array if there were no matches.

DrushConfig getConfig()

Replaces same method in ConfigAwareTrait in order to provide a DrushConfig as return type. Helps with IDE completion.

__construct(array $dbSpec, array $options)

Typically, SqlBase instances are constructed via SqlBase::create($options).

Parameters

array $dbSpec
array $options

array getEnv()

Get environment variables to pass to Process.

Return Value

array

Process getProcess()

Get the last used Process.

Return Value

Process

void setProcess(Process $process)

No description

Parameters

Process $process

Return Value

void

static SqlBase|null create(array $options = [])

Get a driver specific instance of this class.

Parameters

array $options

An options array as handed to a command callback.

Return Value

SqlBase|null

static SqlBase|null getInstance($db_spec, $options)

No description

Parameters

$db_spec
$options

Return Value

SqlBase|null

array getDbSpec()

No description

Return Value

array

void setDbSpec(array $dbSpec)

Set the current db spec.

Parameters

array $dbSpec

Return Value

void

string command()

The unix command used to connect to the database.

Return Value

string

string connect(bool $hide_password = true)

A string for connecting to a database.

Parameters

bool $hide_password

If TRUE, DBMS should try to hide password from process list. On mysql, that means using --defaults-file to supply the user+password.

Return Value

string

string|bool|null dump()

No description

Return Value

string|bool|null

protected string addPipeFail(string $cmd, string $pipefail)

Handle 'pipefail' option for the specified command.

Parameters

string $cmd

Script command to execute; should contain a pipe command

string $pipefail

Script statements to insert into / wrap around $cmd

Return Value

string

Result varies based on value of $pipefail

  • empty: Return $cmd unmodified
  • simple string: Return $cmd appended to $pipefail
  • interpolated: Add slashes to $cmd and insert in $pipefail

Interpolation is particularly for environments such as Ubuntu that use something other than bash as the default shell. To make pipefail work right in this instance, we must wrap it in 'bash -c', since pipefail is a bash feature.

string dumpCmd($table_selection)

No description

Parameters

$table_selection

Return Value

string

string|null dumpFile($file)

No description

Parameters

$file

Return Value

string|null

bool|null query(string $query, $input_file = null, $result_file = '')

Execute a SQL query. Respect simulate mode.

If you don't want to query results to print during --debug then provide a $result_file whose value can be drush_bit_bucket().

Parameters

string $query

The SQL to be executed. Should be NULL if $input_file is provided.

$input_file

A path to a file containing the SQL to be executed.

$result_file

A path to save query results to. Can be drush_bit_bucket() if desired.

Return Value

bool|null

TRUE on success, FALSE on failure

bool alwaysQuery(string $query, $input_file = null, string|null $result_file = '')

Execute a SQL query. Always execute regardless of simulate mode.

If you don't want results to print during --debug then provide a $result_file whose value can be drush_bit_bucket().

Parameters

string $query

The SQL to be executed. Should be null if $input_file is provided.

$input_file

A path to a file containing the SQL to be executed.

string|null $result_file

A path to save query results to. Can be drush_bit_bucket() if desired.

Return Value

bool

on success, FALSE on failure.

protected void logQueryInDebugMode($query, $input_file_original)

Show the query in debug mode and simulate mode

Parameters

$query
$input_file_original

Return Value

void

string|null silent()

No description

Return Value

string|null

string|null queryPrefix($query)

No description

Parameters

$query

Return Value

string|null

queryFormat($query)

No description

Parameters

$query

bool|null drop(array $tables)

Drop specified database.

Parameters

array $tables

An array of table names True if successful, FALSE if failed.

Return Value

bool|null

string createdbSql($dbname, bool $quoted = false)

Build a SQL string for dropping and creating a database.

Parameters

$dbname
bool $quoted

Quote the database name. Mysql uses backticks to quote which can cause problems in a Windows shell. Set TRUE if the CREATE is not running on the bash command line.

Return Value

string

bool|null createdb(bool $quoted = false)

Create a new database.

Parameters

bool $quoted

Quote the database name. Mysql uses backticks to quote which can cause problems in a Windows shell. Set TRUE if the CREATE is not running on the bash command line. True if successful, FALSE otherwise.

Return Value

bool|null

bool dropOrCreate()

Drop all tables (if DB exists) or CREATE target database.

return TRUE or FALSE depending on success.

Return Value

bool

bool dbExists()

No description

Return Value

bool

string creds(bool $hide_password = true)

Build a string containing connection credentials.

Parameters

bool $hide_password

If TRUE, DBMS should try to hide password from process list. On mysql, that means using --defaults-file to supply the user+password.

Return Value

string

string scheme()

The active database driver.

Return Value

string

array listTables()

Extract the name of all existing tables in the given database.

Return Value

array

array listTablesQuoted()

Extract the name of all existing tables in the given database.

Return Value

array

array of table names which exist in the current database, appropriately quoted for the RDMS.

string paramsToOptions($parameters)

No description

Parameters

$parameters

Return Value

string

void su()

Adjust DB connection with superuser credentials if provided.

Return Value

void

array getOptions()

No description

Return Value

array

getOption($name, $default = null)

No description

Parameters

$name
$default

static array dbSpecFromDbUrl($db_url)

Convert from an old-style database URL to an array of database settings.

Parameters

$db_url

Return Value

array

array alwaysQueryCommand($input_file)

Start building the command to run a query.

Parameters

$input_file

Return Value

array

string|null getPasswordFile()

No description

Return Value

string|null