class SqlMysql extends SqlBase (View source)

Traits

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

Properties

$dbSpec from SqlBase
$queryExtra
$queryFile from SqlBase
$options from SqlBase
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.

$tables
expandWildcardTables(array $tables, array $db_tables)

Expand wildcard tables.

An
filterTables(array $tables, array $db_tables)

Filters tables.

array
getTableSelection($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(option_name $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($db_spec, $options)

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

from SqlBase
getEnv()

Get environment variables to pass to Process.

from SqlBase
Process
getProcess()

Get the last used Process.

from SqlBase
setProcess(Process $process)

No description

from SqlBase
static SqlBase
create($options = [])

Get a driver specific instance of this class.

from SqlBase
static 
getInstance($db_spec, $options)

No description

from SqlBase
getDbSpec()

No description

from SqlBase
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
dump()

No description

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

Handle 'pipefail' option for the specified command.

from SqlBase
dumpCmd($table_selection)

No description

dumpFile($file)

No description

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

Execute a SQL query. Respect simulate mode.

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

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

from SqlBase
logQueryInDebugMode($query, $input_file_original)

Show the query in debug mode and simulate mode

from SqlBase
silent()

No description

queryPrefix($query)

No description

from SqlBase
queryFormat($query)

No description

from SqlBase
boolean
drop(array $tables)

Drop specified database.

from SqlBase
string
createdbSql(string $dbname, boolean $quoted = false)

Build a SQL string for dropping and creating a database.

boolean
createdb(boolean $quoted = false)

Create a new database.

from SqlBase
dropOrCreate()

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

from SqlBase
dbExists()

No description

delete()

No description

from SqlBase
string
creds(bool $hide_password = true)

Build a fragment connection parameters.

string
scheme()

The active database driver.

from SqlBase
array|null
listTables()

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

paramsToOptions($parameters)

No description

from SqlBase
null
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
db_spec() deprecated

No description

from SqlBase
static array
dbSpecFromDbUrl(db_url $db_url)

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

from SqlBase

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 An 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 An array of tables with non-existant tables removed.

$tables 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

$tables array with wildcards resolved to real table names.

An 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

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

array getTableSelection($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

$options

Return Value

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

array getRawTableList(option_name $option_name, array $options)

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

Parameters

option_name $option_name The option name to check: skip-tables, structure-tables or tables. This function will check both *-key and *-list.
array $options An options array as passed to an Annotated Command.

Return Value

array Returns 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($db_spec, $options)

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

Parameters

$db_spec
$options

getEnv()

Get environment variables to pass to Process.

Process getProcess()

Get the last used Process.

Return Value

Process

setProcess(Process $process)

Parameters

Process $process

static SqlBase create($options = [])

Get a driver specific instance of this class.

Parameters

$options An options array as handed to a command callback.

Return Value

SqlBase

static getInstance($db_spec, $options)

Parameters

$db_spec
$options

getDbSpec()

setDbSpec(array $dbSpec)

Set the current db spec.

Parameters

array $dbSpec

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

dump()

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.

dumpCmd($table_selection)

Parameters

$table_selection

dumpFile($file)

Parameters

$file

boolean query(string $query, string $input_file = null, string $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.
string $input_file A path to a file containing the SQL to be executed.
string $result_file A path to save query results to. Can be drush_bit_bucket() if desired.

Return Value

boolean TRUE on success, FALSE on failure

boolean alwaysQuery(string $query, string $input_file = null, string $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.
string $input_file A path to a file containing the SQL to be executed.
string $result_file A path to save query results to. Can be drush_bit_bucket() if desired.

Return Value

boolean TRUE on success, FALSE on failure

protected logQueryInDebugMode($query, $input_file_original)

Show the query in debug mode and simulate mode

Parameters

$query
$input_file_original

silent()

queryPrefix($query)

Parameters

$query

queryFormat($query)

Parameters

$query

boolean drop(array $tables)

Drop specified database.

Parameters

array $tables An array of table names

Return Value

boolean True if successful, FALSE if failed.

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

Build a SQL string for dropping and creating a database.

Parameters

string $dbname dbname The database name.
boolean $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

boolean createdb(boolean $quoted = false)

Create a new database.

Parameters

boolean $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

boolean True if successful, FALSE otherwise.

dropOrCreate()

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

return boolean TRUE or FALSE depending on success.

dbExists()

delete()

string creds(bool $hide_password = true)

Build a fragment connection parameters.

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|null listTables()

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

Return Value

array|null An array of table names which exist in the current database.

paramsToOptions($parameters)

Parameters

$parameters

null su()

Adjust DB connection with superuser credentials if provided.

The options 'db-su' and 'db-su-pw' will be retrieved from the specified site alias record.

Return Value

null

array getOptions()

Return Value

array

getOption($name, $default = null)

Parameters

$name
$default

db_spec() deprecated

deprecated .

static array dbSpecFromDbUrl(db_url $db_url)

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

Parameters

db_url $db_url A Drupal 6 db url string to convert, or an array with a 'default' element.

Return Value

array An array of database values containing only the 'default' element of the db url. If the parse fails the array is empty.