class SqlSqlite extends SqlBase (View source)

Traits

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

Properties

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

expandWildcardTables($tables, $db_tables)

No description

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
bool
query(string $query, string $input_file = null, string $result_file = '')

Execute a SQL query. Respect simulate mode.

from  SqlBase
bool
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

from  SqlBase
queryPrefix($query)

No description

from  SqlBase
queryFormat($query)

No description

from  SqlBase
bool
drop(array $tables)

Drop specified database.

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

Build a SQL string for dropping and creating a database.

bool
createdb(bool $quoted = false)

Create a new database.

dropOrCreate()

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

from  SqlBase
dbExists()

No description

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.

array|null
listTablesQuoted()

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

from  SqlBase
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
array
alwaysQueryCommand($input_file)

Start building the command to run a query.

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.

expandWildcardTables($tables, $db_tables)

Parameters

$tables
$db_tables

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

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

bool 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

bool TRUE on success, FALSE on failure

bool 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

bool 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

bool drop(array $tables)

Drop specified database.

Parameters

array $tables An array of table names

Return Value

bool True if successful, FALSE if failed.

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

Build a SQL string for dropping and creating a database.

Parameters

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

Return Value

bool 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()

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.

array|null listTablesQuoted()

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, appropriately quoted for the RDMS.

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.

array alwaysQueryCommand($input_file)

Start building the command to run a query.

Parameters

$input_file

Return Value

array