Commons MariaDB API

A list of functions used with mysql client tool to retrieve data from Mysql/MariaDB server.

API

commons_mariadb_check_client

Check if mysql client program is present on system. If present MARIADB_CLIENT variable with abs path is set. Function check if it is set mysql variable:

  • if it is not set then try to find path through 'which' program
  • if it is set then check if path is correct and program exists.

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_check_vars

Check if are present mandatary mariadb environment variables:

  • MARIADB_USER
  • MARIADB_PWD
  • MARIADB_DB
  • MARIADB_DIR

Returns:

  • 0: all mandatory variables are present.
  • 1: on error (program is interrupter with exit 1 command)
(Show/Hide)

commons_mariadb_check_connection

Check connection to database.

Returns:

  • 0: when connection is ok.
  • 1: on error
(Show/Hide)

commons_mariadb_shell

Enter on command line shell of Mysql/Mariadb server.

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_compile_file

Compile file on database. Output of the compilation is saved on MYSQL_OUTPUT variable.

Parameters:

  • $1: (f) path of the file to compile
  • $2: (msg) message to insert on logging file relative to input file

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_source_file

Compile file on database (with source command). Output of the compilation is saved on MYSQL_OUTPUT variable.

Parameters:

  • $1: (f) path of the file to compile
  • $2: (msg) message to insert on logging file relative to input file

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_compile_fkey

Compile file related with foreign key on database. Output of the compilation is saved on MYSQL_OUTPUT variable.

Parameters:

  • $1: (f) path of the file to compile
  • $2: (msg) message to insert on logging file relative to input file
  • $3: (force) If foreign key is present and force argument is equal to 1, then foreign key is dropped and added again.
  • $4: (fk_table) table of the foreign key

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_compile_idx

Compile file related with index of a table to database. Output of the compilation is saved on MYSQL_OUTPUT variable.

Parameters:

  • $1: (f) path of the file to compile
  • $2: (msg) message to insert on logging file relative to input file
  • $3: (force) if index is present and force is equal to 1, then index is dropped and added again.
  • $4: (idx_table) table of the index

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_compile_all_procedures

Compile all files under MARIADB_DIR/procedures directory.

Parameters:

  • $1: (msg) message to insert on logging file relative to input file.

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_compile_all_triggers

Compile all files under MARIADB_DIR/triggers directory.

Parameters:

  • $1: (msg) message to insert on logging file relative to input file.

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_compile_all_functions

Compile all files under MARIADB_DIR/functions directory.

Parameters:

  • $1: (msg) message to insert on logging file relative to input file.

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_compile_all_views

Compile all files under MARIADB_DIR/views directory.

Parameters:

  • $1: (msg) message to insert on logging file relative to input file.

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_compile_all_fkeys

Compile all files under MARIADB_DIR/foreign_keys directory.

Parameters:

  • $1: (msg) message to insert on logging file relative to input file.
  • $2: (force) if equals to 1, force compilation of all foreign keys also if already present.

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_compile_all_idxs

Compile all files under MARIADB_DIR/indexes directory.

Parameters:

  • $1: (msg) message to insert on logging file relative to input file.
  • $2: (force) if equals to 1, force compilation of all indexes also if already present.

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_compile_all_events

Compile all files under MARIADB_DIR/events directory.

Parameters:

  • $1: (msg) message to insert on logging file relative to input file.

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_compile_all_from_dir

Compile all files from input directory with .sql extension.

Parameters:

  • $1: (directory) Directory where there are files to compile.
  • $2: (msg_head) Title message insert on logfile before compile files.
  • $3: (msg) message insert on logfile before compile files.
  • $4: (type) Identify type of directory: fkey|procedure|function|view. Optional.
  • $5: (closure) custom parameter with a value relative to type.

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_count_fkeys

Count number of foreign keys present on database.

Parameters:

  • $1: (tname) table name to use on count foreign keys. Optional.
  • $2: (mode) if tname is present this field could be used for identify if count must be done for foreign key of the table or foreign keys that reference table. Optional field. Possible values are: "in" (default) | "ref"

Returns:

Number of foreign keys found.

(Show/Hide)

commons_mariadb_count_procedures

Count number of procedures present on database.

Returns:

Number of procedures found.

(Show/Hide)

commons_mariadb_count_functions

Count number of functions present on schema.

Returns:

Number of functions found on schema.

(Show/Hide)

commons_mariadb_count_triggers

Count number of triggers defined on schema.

Returns:

Number of triggers found on schema.

(Show/Hide)

commons_mariadb_count_views

Count number of views present on schema.

Returns:

Number of views available on schema.

(Show/Hide)

commons_mariadb_count_events

Count number of events present on schema.

Returns:

Number of events available on schema.

(Show/Hide)

commons_mariadb_count_indexes

Count number of indexes present on database.

Parameters:

  • $1: (tname) Argument $1 if isn't an empty string identify table name.
  • $2: (idx_types) Argument $2 identify indexes types. Values are: "all" (default), "primary", "not_primary"

Returns:

Number of indexes found.

(Show/Hide)

commons_mariadb_check_if_exist_procedure

Check if exists procedure with name in input on schema.

Returns:

  • 0: if exists.
  • 1: if not exists
(Show/Hide)

commons_mariadb_check_if_exist_function

Check if exists function with name in input on schema.

Returns:

  • 0: if exists.
  • 1: if not exists
(Show/Hide)

commons_mariadb_check_if_exist_view

Check if exists view with name in input on schema.

Returns:

  • 0: if exists.
  • 1: if not exists
(Show/Hide)

commons_mariadb_check_if_exist_fkey

Check if exists foreign keys with name in input on schema.

Returns:

  • 0: if exists.
  • 1: if not exists
  • 2: if argument tname is not present this means that there are two foreign key with same name.
(Show/Hide)

commons_mariadb_check_if_exist_index

Check if exists index with name and table name in input on schema.

Parameters:

  • $1: (index_name) Identify index name.
  • $2: (table_name) Identify table name of the index.

Returns:

  • 0: if exists.
  • 1: if not exists
(Show/Hide)

commons_mariadb_get_triggers_list

Save on _mariadb_ans variable list of triggers defined on schema.

Returns:

  • 0: on success.
  • 1: on error.
(Show/Hide)

commons_mariadb_count_tables

Count tables of the schema.

Returns:

Number of tables found.

(Show/Hide)

commons_mariadb_get_fkeys_list

Save on _mariadb_ans variable list of foreign keys defined on schema.

Parameters:

  • $1: (all) If valorized then list contains columns CONSTRAINT_NAME, TABLE_NAME, COLUMN_NAME, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME, UPDATE_RULE, DELETE_RULE
  • $2: (custom_column) If all paramaeter is empty through this parameter is possible define columns to return.
  • $3: (fkey_name) Foreign key name to filter. Optional.
  • $4: (tname) Table name to use on filter. Optional
  • $5: (mode) if tname is present this field could be used for identify count must be done for count foreign key of the table or foreign keys that reference table. Optional parameter. Possible values are: "in" (default) | "ref"

Returns:

  • 0: on success.
  • 1: on error.
(Show/Hide)

commons_mariadb_get_indexes_list

Save on _mariadb_ans variable list of indexes defined on schema.

Parameters:

  • $1: (idx_types) Identify indexes types. Values are: "all" (default), "primary", "not_primary"
  • $2: (custom_column) If not empty defined list of column returned.
  • $3: (tname) Table name to use on filter. Optional
  • $4: (index_name) Index name to filter. Optional.

Returns:

  • 0: on success.
  • 1: on error.
(Show/Hide)

commons_mariadb_get_tables_list

Save on _mariadb_ans variable list of tables defined on schema.

Parameters:

  • $1: (all) If valorized then list contains columns TABLE_NAME, ENGINE, TABLE_ROWS, DATA_LENGTH, CHARACTER_SET_NAME, CREATE_TIME, UPDATE_TIME
  • $2: (custom_column) If all paramaeter is empty through this parameter is possible define columns to return.
  • $3: (tname) Table name to use on filter. Optional

Returns:

  • 0: on success.
  • 1: on error.
(Show/Hide)

commons_mariadb_desc_table

Save on _mariadb_ans variable list of columns of input table.

Parameters:

  • $1: (tname) Table name to use on filter.
  • $2: (custom_column) If all paramaeter is empty through this parameter is possible define columns to return.
  • $3: (cname) Permit to filter for column name if not empty.

Returns:

  • 0: on success.
  • 1: on error.
(Show/Hide)

commons_mariadb_exist_table

Check if exists table in input.

Parameters:

  • $1: (tname) Table name to search.

Returns:

  • 0: if table exists.
  • 1: on error or if table is not exists.
(Show/Hide)

commons_mariadb_exist_event

Check if exists event in input.

Parameters:

  • $1: (ename) Event name to search.

Returns:

  • 0: if table exists.
  • 1: on error or if table is not exists.
(Show/Hide)

commons_mariadb_get_procedures_list

Save on _mariadb_ans variable list of procedures defined on schema.

Parameters:

  • $1: (all) If valorized then are returned columsn ROUTINE_NAME, DEFINER, CREATED, LAST_ALTERED otherwize only ROUTINE_NAME.

Returns:

  • 0: on success.
  • 1: on error.
(Show/Hide)

commons_mariadb_get_functions_list

Save on _mariadb_ans variable list of functions defined on schema.

Parameters:

  • $1: (all) If valorized then are returned columsn ROUTINE_NAME, DEFINER, CREATED, LAST_ALTERED otherwize only ROUTINE_NAME.

Returns:

  • 0: on success.
  • 1: on error.
(Show/Hide)

commons_mariadb_get_events_list

Save on _mariadb_ans variable list of events defined on schema. Data are returned as a row with pipe (|) separator.

Parameters:

  • $1: (opt) If equal to 'all' then are returned columns EVENT_NAME, DEFINER, TIME_ZONE, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STARTS , ENDS, STATUS, ON_COMPLETION, CREATED, LAST_ALTERED, LAST_EXECUTED, EVENT_COMMENT otherwise EVENT_NAME, DEFINED, TIME_ZONE, EVENT_TYPE, STATUS, CREATED end LAST_EXECUTED.
  • $2: (ename) Name of the event.

Returns:

  • 0: on success.
  • 1: on error.
(Show/Hide)

commons_mariadb_get_views_list

Save on _mariadb_ans variable list of views defined on schema.

Returns:

  • 0: on success.
  • 1: on error.
(Show/Hide)

commons_mariadb_check_if_exist_trigger

Check if exists a trigger with name in input on schema.

Parameters:

  • $1: (name) Name of the trigger to search
  • $2: (tname) Name of the table of the trigger to search. Optional paramenter.

Returns:

  • 0: if exists
  • 1: if not exists
(Show/Hide)

commons_mariadb_download_procedure

Download a procedure to MARIADB_DIR/procedures directory.

Parameters:

  • $1: (name) Name of the procedure.

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_download_function

Download a function to MARIADB_DIR/functions directory.

Parameters:

  • $1: (name) Name of the function.

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_download_trigger

Download a trigger to MARIADB_DIR/triggers directory.

Parameters:

  • $1: (name) Name of the trigger to download.

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_download_event

Download an event to MARIADB_DIR/events directory.

Parameters:

  • $1: (name) Name of the event to download.

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_download_view

Download a view to MARIADB_DIR/views directory.

Parameters:

  • $1: (name) Name of the view to download.

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_download_all_views

Download all views to MARIADB_DIR/views directory.

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_download_all_procedures

Download all procedures to MARIADB_DIR/procedures directory.

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_download_all_functions

Download all functions to MARIADB_DIR/functions directory.

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_download_all_triggers

Download all triggers to MARIADB_DIR/triggers directory.

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_download_all_events

Download all events to MARIADB_DIR/schedulers directory.

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_download_fkey

Download a foreign key to MARIADB_DIR/foreign_keys directory.

Parameters:

  • $1: (name) name of the foreign key to download.
  • $2: (tname) table name related with foreign key to download.

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_download_all_fkeys

Download all foreign keys to MARIADB_DIR/foreign_keys directory.

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_drop_fkey

Drop a foreign key from database if exists.

Parameters:

  • $1: (fkey) name of the foreign key to drop.

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_download_index

Download a index key (primary, unique, spatial) to MARIADB_DIR/indexes directory.

Parameters:

  • $1: (name) name of the index key to download.
  • $2: (tname) table name related with index to download.

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_download_all_indexes

Download all indexes to MARIADB_DIR/indexes directory.

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_drop_index

Drop a index from database if exists.

Parameters:

  • $1: (fkey) name of the index key to drop.
  • $2: (tname) Name of the table related with the index to drop.
  • $3: (avoid_warn) If not empty and index doesn't exist no warning message are printed.

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_create_fkey_file

Create foreign key file for compilation.

Parameters:

  • $1: (name) name of the foreign key to create
  • $2: (table) Name of the table where create foreign key
  • $3: (cname) list of columns related with foreign key.
  • $4: (rtable) name of the table reference
  • $5: (rcname) list of the columns reference on foreign key.

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_create_fkey_file

Create index file for compilation.

Parameters:

  • $1: (name) name of the index to create
  • $2: (table) name of the table where create index.
  • $3: (keys) list of columns of the index.
  • $4: (itable) for particolar index could be contains "UNIQUE" | "FULLTEXT" | "SPATIAL"

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_get_table_def

Create table definition syntax and store it on TABLE_DEF variable.

Parameters:

  • $1: (name) name of the table

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_download_all_tables

Extract all tables definition and write its to a target file.

Parameters:

  • $1: (f) file name path where save tables schema.
  • $2: (tname) download only schema of a particular table. Optional parameter.

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_drop_trigger

Drop a trigger from database if exists.

Parameters:

  • $1: (fkey) name of the trigger to drop.
  • $2: (tname) Name of the table related with the trigger to drop.
  • $3: (avoid_warn) If not empty and trigger doesn't exist no warning message are printed.

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_drop_event

Drop a event from database if exists.

Parameters:

  • $1: (ename) name of the event to drop.
  • $2: (avoid_warn) If not empty and event doesn't exist no warning message are printed.

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_show_gvars

Retrieve global variables.

Parameters:

  • $1: (filter) filter apply to SELECT of variables.

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_check_client_dump

Check if mysqldump client program is present on system. If present MARIADB_CLIENT_DUMP variable with abs path is set. Function check if it is set mysqldump variable:

  • if it is not set then try to find path through 'which' program
  • if it is set then check if path is correct and program exists.

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)

commons_mariadb_dump

Execute dump of database.

Parameters:

  • $1: (targetfile) ABS Path of the file where is store dump.
  • $2: (only_db) Optional option define if dump single database (1) or all (0). Default value is 1.
  • $3: (custom_opts) Optional define custom extra options.

Returns:

  • 0: on success
  • 1: on error
(Show/Hide)