public function lockTables($tables)
    {
        /**
         * Unlock any previously locked tables
         * This is done to provide consistency across different modes, as mysql only allows one single lock over multiple tables
         * Also the odbc only allows all locks to be released, not individual tables. So it makes sense to force the batching of lock/unlock operations
         */
        $this->unlockTables();

        $tables = Helper::toArray($tables);

        if ($this->mode == "odbc") {
            foreach ($tables as $table) {
                $table = $this->getTableName($table);
                $query = "LOCK TABLE " . $table . " IN EXCLUSIVE MODE ALLOW READ";
                $this->query($query);
            }

            # If none of the locks failed then report success
            return true;
        }

        foreach ($tables as &$table) {
            $table = $this->getTableName($table);
        }
        unset($table);

        if ($this->mode == "mysql") {
            $query = "LOCK TABLES " . implode(",", $tables) . " WRITE";
            return $this->query($query);
        }

        if (in_array($this->mode, ["postgres", "redshift"], true)) {
            $query = "LOCK TABLE " . implode(",", $tables) . " IN EXCLUSIVE MODE";
            return $this->query($query);
        }

        throw new \Exception("lockTables() not supported in this mode (" . $this->mode . ")");
    }
public function lockTables($tables)
    {
        /**
         * Unlock any previously locked tables
         * This is done to provide consistency across different modes, as mysql only allows one single lock over multiple tables
         * Also the odbc only allows all locks to be released, not individual tables. So it makes sense to force the batching of lock/unlock operations
         */
        $this->unlockTables();

        $tables = Helper::toArray($tables);

        if ($this->mode == "odbc") {
            foreach ($tables as $table) {
                $table = $this->getTableName($table);
                $query = "LOCK TABLE " . $table . " IN EXCLUSIVE MODE ALLOW READ";
                $this->query($query);
            }

            # If none of the locks failed then report success
            return true;
        }

        foreach ($tables as &$table) {
            $table = $this->getTableName($table);
        }
        unset($table);

        if ($this->mode == "mysql") {
            $query = "LOCK TABLES " . implode(",", $tables) . " WRITE";
            return $this->query($query);
        }

        if (in_array($this->mode, ["postgres", "redshift"], true)) {
            $query = "LOCK TABLE " . implode(",", $tables) . " IN EXCLUSIVE MODE";
            return $this->query($query);
        }

        throw new \Exception("lockTables() not supported in this mode (" . $this->mode . ")");
    }
public function lockTables ( $ tables ) { /**
         * Unlock any previously locked tables
         * This is done to provide consistency across different modes, as mysql only allows one single lock over multiple tables
         * Also the odbc only allows all locks to be released, not individual tables. So it makes sense to force the batching of lock/unlock operations
         */ $ this -> unlockTables ( ) ; $ tables = Helper :: toArray ( $ tables ) ; if ( $ this -> mode == "odbc" ) { foreach ( $ tables as $ table ) { $ table = $ this -> getTableName ( $ table ) ; $ query = "LOCK TABLE " . $ table . " IN EXCLUSIVE MODE ALLOW READ" ; $ this -> query ( $ query ) ; } # If none of the locks failed then report success return true ; } foreach ( $ tables as & $ table ) { $ table = $ this -> getTableName ( $ table ) ; } unset ( $ table ) ; if ( $ this -> mode == "mysql" ) { $ query = "LOCK TABLES " . implode ( "," , $ tables ) . " WRITE" ; return $ this -> query ( $ query ) ; } if ( in_array ( $ this -> mode , [ "postgres" , "redshift" ] , true ) ) { $ query = "LOCK TABLE " . implode ( "," , $ tables ) . " IN EXCLUSIVE MODE" ; return $ this -> query ( $ query ) ; } throw new \ Exception ( "lockTables() not supported in this mode (" . $ this -> mode . ")" ) ; }
Lock some tables for exlusive write access
But allow read access to other processes
Lock some tables for exlusive write access But allow read access to other processes