diff --git a/.docker/docker-compose.yml b/.docker/docker-compose.yml new file mode 100644 index 0000000000000000000000000000000000000000..1a63292b080f182821935cb5b20b7500bfcf8f63 --- /dev/null +++ b/.docker/docker-compose.yml @@ -0,0 +1,23 @@ +version: '3.6' +services: + sqldb: + image: mariadb:10.5 + volumes: + - type: volume + source: "caosdb-sqldata" + target: /var/lib/mysql + environment: + MYSQL_ROOT_PASSWORD: caosdb1234 + networks: + # available on port 3306, host name 'sqldb' + - caosnet + ports: + - 3306:3306 + + +# A well-defined network for caosdb +volumes: + caosdb-sqldata: +networks: + caosnet: + driver: bridge diff --git a/CHANGELOG.md b/CHANGELOG.md index 8076fdd687e3270874b40c9b191cfd10a60c463c..0b45fe17477c70c91037c453c456be958335952a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,27 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] ## + +### Added ### + +### Changed ### + +### Deprecated ### + +### Removed ### + +### Fixed ### + +* make install: Could not connect to MariaDB in local docker + container + [linkahead-mariadbbackend](https://gitlab.com/linkahead/linkahead-mariadbbackend/-/issues/33) +* Wrong ids in data_type table due to a bug in the `linkahead-server < v0.11.0` + which has been fixed but left broken data. This resulted in server errors + [linkahead-mariadbbackend#34](https://gitlab.com/linkahead/linkahead-mariadbbackend/-/issues/34) + +### Security ### + ## [7.0.1] - 2023-11-01 (Timm Fitschen) @@ -87,8 +108,6 @@ This is a major update. Switching from integer ids for internal and external use * Change signature of procedure `retrieveEntityProperties` - `EntityID VARCHAR(255)`, `DomainID VARCHAR(255)` * Change signature of procedure `updateEntity` - `EntityID VARCHAR(255)` -### Deprecated ### - ### Removed ### * Deactivate procedure `delete_all_entity_versions`. This might be used in the @@ -107,18 +126,12 @@ This is a major update. Switching from integer ids for internal and external use * Change signature of procedure `getFileIdByPath` - `FilePath TEXT` - this length is needed for the path column of `file_entities`. -### Security ### - ## [5.0.0] - 2021-10-28 ## ### Added ### * #33 CI pipeline for MySQL (was only MariaDB before). -### Changed ### - -### Deprecated ### - ### Removed ### * `getRules` procedure and the `rules` table. The jobs rules are being @@ -131,8 +144,6 @@ This is a major update. Switching from integer ids for internal and external use * #32 Removed unused `groups` table from installation routines which prevented the installation with MySQL 8. -### Security ### - ## [4.1.0] - 2021-06-11 ## ### Added ### @@ -170,8 +181,6 @@ This is a major update. Switching from integer ids for internal and external use * `createTmpTable` * Added a `direct` column to `archive_isa` table -### Deprecated ### - ### Removed ### * unused procedures: @@ -197,8 +206,6 @@ This is a major update. Switching from integer ids for internal and external use version resultet in an error. See corresponding test in `caosdb-pyinttest` `tests/test_versioning.py::test_datatype_without_name` -### Security ### - ## [3.0.0] - 2020-09-01 ## ### Added ### @@ -252,5 +259,3 @@ This is a major update. Switching from integer ids for internal and external use * Bug in `updateEntity.sql` (when updating the primary name without a prior call to `deleteEntityProperties`). Same thing for `deleteEntity`. * #21 Bug which prevented deletion of deeply inheriting entities, if versioning was enabled. - -### Security ### diff --git a/Makefile b/Makefile index 71fc68012a1c0a8ad136c8f47d804b92176ed6a6..7c1ec3effb5cea166649aedcba188d6974d2cb6f 100644 --- a/Makefile +++ b/Makefile @@ -86,6 +86,7 @@ pipeline-test: echo 'DATABASE_USER_HOST_LIST="%,"' >> .config echo "MYSQL_USER_PASSWORD=$(MYSQL_ROOT_PASSWORD)" >> .config echo "MYSQL_HOST=$(SQL_HOST)" >> .config + echo "MYSQL_OPTS=--protocol=TCP" >> .config sleep 10 make install ./utils/make_db restore_db tests/example.dump.sql diff --git a/README_SETUP.md b/README_SETUP.md index 95f975d031ded904b2656230f5ec72d98447a7b6..581cc31411a6b6e510f10414c21ce6304697cb85 100644 --- a/README_SETUP.md +++ b/README_SETUP.md @@ -87,6 +87,19 @@ with the then current version of the stored entities. * Alternatively, to run the tests in a containerized MariaDB instance, run `make test-docker`, followed by `make test-docker-stop`. + +### Running in a Docker Container + +You can use `.docker/docker-compose.yml` to start a docker container +(`docker-compose -f .docker/docker-compose.yml up -d`) that runs mariadb. You +need appropriate settings in `.config`: +* `MYSQL_OPTS="--protocol=TCP"` and +* `DATABASE_USER_HOST_LIST=%,` +After the first start, you need to install the database: `make install`. +Then, you can connect to it with `mariadb --protocol=TCP -u caosdb -prandom1234 +caosdb`. + + ### Troubleshooting #### MySQL has failing tests diff --git a/config.defaults b/config.defaults index f12278dcf0f5ce772c4cb77e54b149d3f6880921..1860377976c3bf0d9f389570dc0e981f47aa1609 100644 --- a/config.defaults +++ b/config.defaults @@ -40,6 +40,12 @@ MYSQL_PORT=3306 # which will then be used by the CaosDB Server. MYSQL_USER=root MYSQL_USER_PASSWORD=caosdb1234 +# Additional options for the connection +# e.g. if you want to connect a dockerized MariaDB at localhost you need to put +# "--protocol=TCP" here because when host=localhost the connection defaults to +# SOCKET. +# MYSQL_OPTS='--protocol=TCP' +MYSQL_OPTS= # # DATABASE # The name of the SQL database. diff --git a/patches/patch20231211-7.0.2/patch.sh b/patches/patch20231211-7.0.2/patch.sh new file mode 100755 index 0000000000000000000000000000000000000000..422fc00b9083808446d74776b446c072bdfd73bc --- /dev/null +++ b/patches/patch20231211-7.0.2/patch.sh @@ -0,0 +1,41 @@ +#!/bin/bash +# +# This file is a part of the CaosDB Project. +# +# Copyright (C) 2023 IndiScale GmbH <info@indiscale.com> +# Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. +# + +# Update mysql schema to version v7.0.2 +# Patch the broken data_type table (fix id for file references as per +# https://gitlab.com/linkahead/linkahead-server/-/issues/246) + +NEW_VERSION="v7.0.2" +OLD_VERSION="v7.0.1" + +if [ -z "$UTILSPATH" ]; then + UTILSPATH="../utils" +fi + +. $UTILSPATH/patch_header.sh $* + +check_version $OLD_VERSION + +mysql_execute "UPDATE data_type SET datatype=17 WHERE datatype=3" + +update_version $NEW_VERSION + +success diff --git a/procedures/query/applyPOV.sql b/procedures/query/applyPOV.sql index d1d846784a5861237ef710fe90c40f42ef9c6d11..47532bca6b4e8a70ab7f24ba0fc5fa2bf371b76d 100644 --- a/procedures/query/applyPOV.sql +++ b/procedures/query/applyPOV.sql @@ -34,30 +34,31 @@ DELIMITER // * ---------- * * versioned : boolean - * If True, sourceSet and targetSet have an _iversion column, otherwise that column will be -* ignored (or only HEAD will be inserted into targetSet). + * If True, sourceSet and targetSet have an _iversion column, otherwise that column will be ignored + * (or only HEAD will be inserted into targetSet). */ -CREATE PROCEDURE db_5_0.applyPOV(in sourceSet VARCHAR(255), /* (?) Name of the table that the POV will be applied to. This can be a temporary table. */ - in targetSet VARCHAR(255), /* (?) Name of the result table of this POV. */ +CREATE PROCEDURE db_5_0.applyPOV(in sourceSet VARCHAR(255), /* Name of the table that the POV will be applied to. This can be a temporary table or the `entities` table */ + in targetSet VARCHAR(255), /* Name of the result table of this POV. After the filter has been applied this table only contains matching + entity ids. This may be NULL or same as sourceSet. In that case the filter is applied in-place (delete non-matching). Otherwise the filter is applied by copying only the matching ids from the *source* set to the *target* set. */ in propertiesTable VARCHAR(255), - in refIdsTable VARCHAR(255), + in refIdsTable VARCHAR(255), /* Name of a tmp table that contains all ids of children of the value interpreted as entity name or id */ in o CHAR(4), /* The operator for this operation. can be one of: 0 check for "equals NULL" !0 check for "not NULL" -> check whether a reference exists - ( (?) check for datetime intervals - !( (?) check for being outside of datetime intervals - other operators (all SQL operators (?)) + ( check for datetime interval (say "in") + !( check for being outside of datetime intervals (say "not in") + other operators (all valid SQL operators) these other operators can be used either with or without an aggregation to use an aggregation set agg to non-zero all SQL aggregations can be used */ - in vText VARCHAR(255), /* (?) the text value to be checked against using operator o */ + in vText VARCHAR(255), /* the text value to be checked against using operator o */ in vInt INT, /* the integer value to be checked against using operator o */ in vDouble DOUBLE, /* the double value to be checked against using operator o */ - in unit_sig BIGINT, + in unit_sig BIGINT, /* signatur of the unit given by the user. used when we need to convert units. */ in vDoubleStdUnit DOUBLE, /* The numeric value, converted according to the unit rules. */ - in stdUnit_sig BIGINT, + in stdUnit_sig BIGINT, /* signatur of the normalized/standardized unit, e.g when unit_sig is "km/h" this might be "m/s". */ in vDateTime VARCHAR(255), in vDateTimeDotNotation VARCHAR(255), in agg CHAR(3), /* an SQL aggregate function or NULL when no aggregation should be used */ @@ -81,6 +82,10 @@ POV_LABEL: BEGIN DECLARE keepTabl VARCHAR(255) DEFAULT NULL; DECLARE existence_op VARCHAR(255) DEFAULT "EXISTS"; + #-- ######### HINT ############## + #-- first the appropriate statement is created which in the end prepared and executed + #-- ############################# + IF o = '->' THEN #-- special case: pure reference property call applyRefPOV(sourceSet,targetSet, propertiesTable, refIdsTable, versioned); @@ -229,6 +234,8 @@ POV_LABEL: BEGIN IF o = "!=" AND refIdsTable IS NOT NULL THEN SET existence_op = "NOT EXISTS"; END IF; + /* select all entities that reference the entity or a child of the + * value interpreted as ID*/ SET sRefData = IF(vText IS NULL, ' UNION ALL SELECT DISTINCT domain_id, entity_id, property_id FROM `reference_data`', IF(refIdsTable IS NULL, @@ -243,6 +250,7 @@ POV_LABEL: BEGIN END IF; + #-- create array of statement parts (and replace null with empty string) (?) SET data = CONCAT('(',sTextData, IF(sNameData IS NULL, '', sNameData), IF(sEnumData IS NULL, '', sEnumData), @@ -259,6 +267,7 @@ POV_LABEL: BEGIN call createTmpTable(keepTabl, versioned); IF versioned THEN #-- generate statement from statement parts + #-- (versioned section) SET @stmtPOVkeepTblStr = CONCAT( 'INSERT IGNORE INTO `', keepTabl, '` (id, _iversion) SELECT entity_id AS id, _iversion FROM ', data, ' as data', IF(propertiesTable IS NULL, '', CONCAT( @@ -299,7 +308,14 @@ POV_LABEL: BEGIN DEALLOCATE PREPARE stmtPOVkeepTbl; ELSE #-- generate statement from statement parts - SET @stmtPOVkeepTblStr = CONCAT('INSERT IGNORE INTO `', keepTabl, '` (id) SELECT DISTINCT entity_id AS id FROM ', data, ' as data', IF(propertiesTable IS NULL, '', CONCAT(' WHERE EXISTS (Select 1 from `', propertiesTable, '` AS prop WHERE prop.id = data.property_id AND (prop.id2=data.entity_id OR prop.id2=0))'))); + SET @stmtPOVkeepTblStr = CONCAT( + 'INSERT IGNORE INTO `', keepTabl, + '` (id) SELECT DISTINCT entity_id AS id FROM ', data, ' as data', + IF(propertiesTable IS NULL, '', + CONCAT(' WHERE EXISTS (Select 1 from `', propertiesTable, + '` AS prop WHERE prop.id = data.property_id AND + (prop.id2=data.entity_id OR prop.id2=0))'))); + #-- (unversioned section) SET @stmtPOVStr = CONCAT( IF(targetSet IS NULL, diff --git a/procedures/query/initPOV.sql b/procedures/query/initPOV.sql index 31347ba9a7f2cde33e619e50e7721875232b8628..2afdc9cdfc77906725a24ab593151e0ee7834e02 100644 --- a/procedures/query/initPOV.sql +++ b/procedures/query/initPOV.sql @@ -60,7 +60,14 @@ BEGIN SELECT conv( concat( substring(uid,16,3), substring(uid,10,4), substring(uid,1,8)),16,10) div 10000 - (141427 * 24 * 60 * 60 * 1000) as current_mills INTO t1 from (select uuid() uid) as alias; call createTmpTable2(propertiesTable); - -- fill in all properties named "PropertyName" + -- Fill in all properties (plus the domain id and entity id) named + -- "PropertyName", be it their default name or their overridden name. + -- We need *all* properties (mind, the properties of entities not + -- abstract properties) with the given name. If an abstract + -- property has the name "person" it might have the name "author" in + -- the "Article" record type. Now, if I want to collect all properties + -- of the Article named "author" I need to look into the name_overrides + -- table. SET @initPOVPropertiesTableStmt1 = CONCAT('INSERT IGNORE INTO `', propertiesTable, '` (id, id2, domain) SELECT property_id, entity_id, domain_id from name_overrides WHERE name = ? UNION ALL SELECT entity_id, domain_id, 0 FROM name_data WHERE value = ?;'); PREPARE stmt FROM @initPOVPropertiesTableStmt1; SET @PropertyName = PropertyName; diff --git a/procedures/query/initSubEntity.sql b/procedures/query/initSubEntity.sql index c60ddb61df7370f52ae8218720ad69c5d2bf5023..d542b3387a9aa8a1c23c5db74d459a3c51861ccf 100644 --- a/procedures/query/initSubEntity.sql +++ b/procedures/query/initSubEntity.sql @@ -24,10 +24,11 @@ DROP PROCEDURE IF EXISTS db_5_0.initSubEntity; DELIMITER // - /* - * Initialize a new temporary table by loading an entity and all of its children - * into the table (i.e. their internal ids). + * Initialize a new temporary table by loading an entity (by name or by id or + * both) and all of its children into the table (i.e. their internal ids). + * + * The table name has to be provided. * * This is used by initPOVRefidsTable and initBackReference for sub-property filtering. * @@ -45,6 +46,7 @@ BEGIN DECLARE ecount INT DEFAULT 0; DECLARE op VARCHAR(255) DEFAULT '='; + IF LOCATE("%", ename) > 0 THEN SET op = "LIKE"; END IF; diff --git a/utils/backup.sh b/utils/backup.sh index bdc345cfe1e956024fbd8492c6a1a2d65acc2cdd..4d53da3edafd52be32d9f33507664d6971581360 100755 --- a/utils/backup.sh +++ b/utils/backup.sh @@ -56,7 +56,7 @@ function backup() { fi echo "Dumping database $database to $backupfile ..." - $MYSQLDUMP_CMD $(get_mysql_args_nodb) --opt --default-character-set=utf8 \ + $MYSQLDUMP_CMD $(get_db_args_nodb) --opt --default-character-set=utf8 \ --routines "$database" > "$backupfile" success diff --git a/utils/helpers.sh b/utils/helpers.sh index 6adb318503e26061369a1144568dea4f60ef3d46..86f7d5981c7497fe478bccb3f391932585934545 100644 --- a/utils/helpers.sh +++ b/utils/helpers.sh @@ -52,47 +52,25 @@ function mysql_execute_file { fi } - -function get_mysql_args { - echo "$(get_mysql_args_nodb) --database=$DATABASE_NAME" -} - function get_db_args { echo "$(get_db_args_nodb) --database=$DATABASE_NAME" } function get_db_args_nodb { - if [ "$DATABASE_USER" ]; then - mysql_con_arguments="--user=$DATABASE_USER" + if [ -n "$MYSQL_USER" ]; then + mysql_con_arguments="--user=$MYSQL_USER" fi - if [ "$DATABASE_USER_PW" ]; then - mysql_con_arguments="$mysql_con_arguments --password=$DATABASE_USER_PW" + if [ -n "$MYSQL_USER_PASSWORD" ]; then + mysql_con_arguments="$mysql_con_arguments --password=$MYSQL_USER_PASSWORD" fi - if [[ "$MYSQL_HOST" && ( "$MYSQL_HOST" != "localhost" ) ]]; then + if [ -n "$MYSQL_HOST" ] && [ "$MYSQL_HOST" != "localhost" ]; then mysql_con_arguments="$mysql_con_arguments --host=$MYSQL_HOST" - if [ "$MYSQL_PORT" ]; then - mysql_con_arguments="$mysql_con_arguments --port=$MYSQL_PORT" - fi fi - echo $mysql_con_arguments -} - -function get_mysql_args_nodb { - if [ "$LOGIN_PATH" ]; then - mysql_con_arguments="--login-path=$LOGIN_PATH" - else - if [ "$MYSQL_USER" ]; then - mysql_con_arguments="--user=$MYSQL_USER" - fi - if [ "$MYSQL_USER_PASSWORD" ]; then - mysql_con_arguments="$mysql_con_arguments --password=$MYSQL_USER_PASSWORD" - fi - if [[ "$MYSQL_HOST" && ( "$MYSQL_HOST" != "localhost" ) ]]; then - mysql_con_arguments="$mysql_con_arguments --host=$MYSQL_HOST" - if [ "$MYSQL_PORT" ]; then - mysql_con_arguments="$mysql_con_arguments --port=$MYSQL_PORT" - fi - fi + if [ -n "$MYSQL_PORT" ] && [ "$MYSQL_PORT" != "3306" ]; then + mysql_con_arguments="$mysql_con_arguments --port=$MYSQL_PORT" + fi + if [ -n "$MYSQL_OPTS" ] ; then + mysql_con_arguments="$mysql_con_arguments $MYSQL_OPTS" fi echo $mysql_con_arguments } diff --git a/utils/load_settings.sh b/utils/load_settings.sh index c24a0f4baf6e9e15e56e7ffeacb265b0b5f01673..d25dce5b1bf3b7a16ee62c67143ad0cd4e080cf1 100644 --- a/utils/load_settings.sh +++ b/utils/load_settings.sh @@ -65,6 +65,7 @@ export MYSQL_CONFIG_EDITOR_CMD export MYSQL_HOST export MYSQL_PORT export MYSQL_USER +export MYSQL_OPTS export DATABASE_NAME export DATABASE_USER export DATABASE_USER_PW diff --git a/utils/make_db b/utils/make_db index 4a90931708c667d44fc1c021eb3467850b094737..35ed2d933ab3479f88556e08052b977bd2b0507c 100755 --- a/utils/make_db +++ b/utils/make_db @@ -87,7 +87,7 @@ function _install_unit_test_database () { if _db_exists "$DATABASE_NAME"; then echo "using $DATABASE_NAME" else - sed "s/db_5_0/$DATABASE_NAME/g" "$INSTALL_SQL_FILE" | $MYSQL_CMD $(get_mysql_args_nodb) + sed "s/db_5_0/$DATABASE_NAME/g" "$INSTALL_SQL_FILE" | $MYSQL_CMD $(get_db_args_nodb) # create test user grant @@ -113,7 +113,7 @@ function _setup_mytap() { pushd libs > /dev/null unzip -u mytap*.zip > /dev/null pushd mytap*/ > /dev/null - $MYSQL_CMD $(get_mysql_args_nodb) < mytap.sql > /dev/null || exit 1 + $MYSQL_CMD $(get_db_args_nodb) < mytap.sql > /dev/null || exit 1 popd > /dev/null rm -r mytap*/ popd > /dev/null @@ -129,14 +129,14 @@ name in your .config file " exit 0 fi - sed "s/db_5_0/$DATABASE_NAME/g" "$INSTALL_SQL_FILE" | $MYSQL_CMD $(get_mysql_args_nodb) + sed "s/db_5_0/$DATABASE_NAME/g" "$INSTALL_SQL_FILE" | $MYSQL_CMD $(get_db_args_nodb) } function sanity_check() { trap "$(shopt -po errexit)" RETURN set +e echo -n "running sanity checks ..." - msg="$($MYSQL_CMD $(get_mysql_args) < "utils/sanity_check.sql" 2>/dev/null)" + msg="$($MYSQL_CMD $(get_db_args) < "utils/sanity_check.sql" 2>/dev/null)" code="$?" if [ "$code" -eq "0" ] ; then echo " [OK]" @@ -150,7 +150,7 @@ function sanity_check() { # Inserts the dump (arg 1) into the database function restore_db() { SQL_FILE="$1" - $MYSQL_CMD $(get_mysql_args) < "$SQL_FILE" + $MYSQL_CMD $(get_db_args) < "$SQL_FILE" cat <<EOF If this is not the same SQL server where the SQL dump was originally created from, make sure that a user with sufficient permissions exists. Note that you @@ -159,7 +159,7 @@ EOF } function test-connection() { - $MYSQL_CMD $(get_mysql_args_nodb) -e "select 0;" + $MYSQL_CMD $(get_db_args_nodb) -e "select 0;" } # Creates a user and grants it sufficient rights. @@ -183,7 +183,7 @@ function grant() { if [[ $1 = "--strict" ]] ; then for host in ${DATABASE_USER_HOST_LIST//,/ } ; do CMD="SELECT COUNT(*) FROM mysql.user WHERE user='${DATABASE_USER}' AND host='${host}';" - [[ $($MYSQL_CMD $(get_mysql_args_nodb) -s -N -e "$CMD") = 0 ]] || { + [[ $($MYSQL_CMD $(get_db_args_nodb) -s -N -e "$CMD") = 0 ]] || { echo "The user '${DATABASE_USER}@${host}' is already in the database." echo "Please use another user or delete it, e.g. with" echo "'mysql -u ${MYSQL_USER} -p -e \"DROP USER ${DATABASE_USER}@${host};\"'" @@ -197,7 +197,7 @@ function grant() { # FIXME Are all these permissions necessary? See # https://gitlab.indiscale.com/caosdb/src/caosdb-mysqlbackend/-/issues/28 "Default # installation target does not work for existing databases" - $MYSQL_CMD $(get_mysql_args_nodb) <<EOF + $MYSQL_CMD $(get_db_args_nodb) <<EOF CREATE USER IF NOT EXISTS '$DATABASE_USER'@'$host' identified by '$DATABASE_USER_PW'; GRANT USAGE ON *.* TO '$DATABASE_USER'@'$host'; @@ -212,16 +212,16 @@ EOF function drop() { DROPDB="$1" for host in ${DATABASE_USER_HOST_LIST//,/ } ; do - $MYSQL_CMD $(get_mysql_args_nodb) -e "DROP USER '${DATABASE_USER}'@'${host}';" || true + $MYSQL_CMD $(get_db_args_nodb) -e "DROP USER '${DATABASE_USER}'@'${host}';" || true done - "$MYSQLADMIN_CMD" $(get_mysql_args_nodb) -f drop "$DROPDB" + "$MYSQLADMIN_CMD" $(get_db_args_nodb) -f drop "$DROPDB" } # Returns 0 or non-zero, depending on whether the database exists already. # Optional parameter: [DATABASE_NAME], else $DATABASE_NAME is used. function _db_exists() { - $MYSQL_CMD $(get_mysql_args_nodb) -D "${1-${DATABASE_NAME}}" -e "show tables;" > /dev/null 2>&1 \ + $MYSQL_CMD $(get_db_args_nodb) -D "${1-${DATABASE_NAME}}" -e "show tables;" > /dev/null 2>&1 \ && return 0 || return 1 } @@ -250,7 +250,7 @@ function grant-permission() { fi cmd="SELECT COUNT(1) from roles where name='${role}';" - count=$($MYSQL_CMD $(get_mysql_args) -AN -e "$cmd") + count=$($MYSQL_CMD $(get_db_args) -AN -e "$cmd") if [[ $count == "0" ]]; then echo "Role not found!" exit 1 @@ -259,7 +259,7 @@ function grant-permission() { cmd="INSERT INTO permissions (role, permissions) VALUE ('${role}', '${permissions}')" cmd+="ON DUPLICATE KEY UPDATE role='${role}', permissions='${permissions}'" cmd+=";" - $MYSQL_CMD $(get_mysql_args) -e "$cmd" + $MYSQL_CMD $(get_db_args) -e "$cmd" }