Namespace src/Database
src/Database
Overview
Directory src/Database
file source src/Database/checkDsnFile.sh
Database::checkDsnFile
check if dsn file has all the mandatory variables set Mandatory variables are: HOSTNAME, USER, PASSWORD, PORT
Arguments
- $1 (dsnFileName:String): dsn absolute filename
Variables set
- HOSTNAME (loaded): from dsn file
- PORT (loaded): from dsn file
- USER (loaded): from dsn file
- PASSWORD (loaded): from dsn file
Exit codes
- 0: on valid file
- 1: if one of the properties of the conf file is invalid or if file not found
Output on stderr
- log output if error found in conf file
src/Database/createDb.sh
file source src/Database/createDb.sh
Database::createDb
create database if not already existent
Arguments
- $1 (instanceCreateDb:&Map<String,String>): (passed by reference) database instance to use
- $2 (dbName:String): database name to create
Exit codes
- 0: if success
- 1: if query fails
Output on stderr
- display db creation status
src/Database/dropDb.sh
file source src/Database/dropDb.sh
Database::dropDb
drop database if exists
Arguments
- $1 (instanceDropDb:&Map<String,String>): (passed by reference) database instance to use
- $2 (dbName:String): database name to drop
Exit codes
- 0: if success
- 1: query fails
Output on stderr
- display db deletion status
src/Database/dropTable.sh
file source src/Database/dropTable.sh
Database::dropTable
drop table if exists
Arguments
- $1 (instanceDropTable:&Map<String,String>): (passed by reference) database instance to use
- $2 (dbName:String): database name on which the table will be dropped
- $3 (tableName:String): table name to drop
Exit codes
- 0: if success
- 1: if query fails
Output on stderr
- display db table deletion status
src/Database/dump.sh
file source src/Database/dump.sh
Database::dump
dump db limited to optional table list
Arguments
- $1 (instanceDump:&Map<String,String>): (passed by reference) database instance to use
- $2 (db:String): the db to dump
- $3 (optionalTableList:String): (optional) string containing tables list (can be empty string in order to specify additional options)
- $4 (dumpAdditionalOptions:String[]): (optional)_ … additional dump options
Exit codes
- mysqldump command status code
Output on stderr
- display db sql debug
src/Database/getUserDbList.sh
file source src/Database/getUserDbList.sh
Database::getUserDbList
databases’s list of given mysql server
Example
- information_schema
- mysql
- performance_schema
- sys
Arguments
- $1 (instanceUserDbList:&Map<String,String>): (passed by reference) database instance to use
Exit codes
- the query exit code
Output on stdout
- the list of db except mysql admin ones (see example)
src/Database/ifDbExists.sh
file source src/Database/ifDbExists.sh
Database::ifDbExists
check if given database exists
Arguments
- $1 (instanceIfDbExists:&Map<String,String>): (passed by reference) database instance to use
- $2 (dbName:String): database name
Exit codes
- 1: if db doesn’t exist
Output on stderr
- debug command
src/Database/isTableExists.sh
file source src/Database/isTableExists.sh
Database::isTableExists
check if table exists on given db
Arguments
- $1 (instanceIsTableExists:&Map<String,String>): (passed by reference) database instance to use
- $2 (dbName:String): database name
- $3 (tableThatShouldExists:String): the table that should exists on this db
Exit codes
- 0: if table exists
- 1: if table doesn’t exist
src/Database/newInstance.sh
file source src/Database/newInstance.sh
Database::newInstance
create a new db instance Returns immediately if the instance is already initialized
Example
declare -Agx dbInstance
Database::newInstance dbInstance "default.local"
Arguments
- $1 (instanceNewInstance:&Map<String,String>): (passed by reference) database instance to use
- $2 (dsn:String): dsn profile - load the dsn.env profile deduced using rules defined in Conf::getAbsoluteFile
Exit codes
- 1: if dns file not able to loaded
src/Database/query.sh
file source src/Database/query.sh
Database::query
mysql query on a given db
Example
cat file.sql | Database::query ...
@arg $1 instanceQuery:&Map<String,String> (passed by reference) database instance to use
@arg $2 sqlQuery:String (optional) sql query or sql file to execute. if not provided or empty, the command can be piped
@arg $3 dbName:String (optional) the db name
Exit codes
- mysql command status code
Warnings
- could use QUERY_OPTIONS variable from dsn if defined
src/Database/setDumpOptions.sh
file source src/Database/setDumpOptions.sh
Database::setDumpOptions
set the options to use on mysqldump command
Arguments
- $1 (instanceSetDumpOptions:&Map<String,String>): (passed by reference) database instance to use
- $2 (optionsList:String): dump options list
src/Database/setQueryOptions.sh
file source src/Database/setQueryOptions.sh
Database::setQueryOptions
set the general options to use on mysql command to query the database Differs than setOptions in the way that these options could change each time
Arguments
- $1 (instanceSetQueryOptions:&Map<String,String>): (passed by reference) database instance to use
- $2 (optionsList:String): query options list
src/Database/skipColumnNames.sh
file source src/Database/skipColumnNames.sh
Database::skipColumnNames
by default we skip the column names but sometimes we need column names to display some results disable this option temporarily and then restore it to true
Arguments
- $1 (instanceSetQueryOptions:&Map<String,String>): (passed by reference) database instance to use
- $2 (skipColumnNames:Boolean): 0 to disable, 1 to enable (hide column names)