MySQL storage engine compat.

@since 160524 First documented version.

@param string $sql SQL to check.

@return string Output `$sql` with engine modification.
165063
public function engineCompat(string $sql): string
    {
        $sql = $this->c::mbTrim($sql);

        if (!preg_match('/^CREATE\s+TABLE\b/ui', $sql)) {
            return $sql; // Not applicable.
        }
        $sql = preg_replace('/\bENGINE\=[%a-z0-9_\-]*/ui', '', $sql);

        if (!preg_match('/\bFULLTEXT\s+KEY\b/ui', $sql) || version_compare($this->wp->db_version(), '5.6.4', '>=')) {
            // MySQL v5.6.4+ supports fulltext indexes w/ InnoDB. See: <http://bit.ly/ZVeF42>
            $sql = preg_replace('/;$/u', ' ENGINE=InnoDB;', $sql);
        } else {
            $sql = preg_replace('/;$/u', ' ENGINE=MyISAM;', $sql);
        }
        return $sql;
    }
458844
protected function _renderWhere($sql)
    {
        if ($this->_parts[self::FROM] && $this->_parts[self::WHERE]) {
            $sql .= ' ' . self::SQL_WHERE . ' ' .  implode(' ', $this->_parts[self::WHERE]);
        }

        return $sql;
    }
365925
public function prepare($sql)
    {
        $this->_connect();
        $stmtClass = $this->_defaultStmtClass;
        $stmt = new $stmtClass($this, $sql);
        $stmt->setFetchMode($this->_fetchMode);
        return $stmt;
    }
1030536
public function realQuery($sql) {
		BLog::addToLog($this->logsuffix . ' Query: ' . $sql);
		$this->queries_count++;
		$r = $this->mysqli->real_query($sql);
		if ((DEBUG_MODE) && (empty($r))) {
			BLog::addToLog($this->logsuffix . ' query failed!', LL_ERROR);
			BLog::addToLog($this->logsuffix . ' query="' . $sql . '";', LL_ERROR);
			BLog::addToLog($this->logsuffix . ' query error=' . $this->lastError(), LL_ERROR);
		}
		return $r;
	}
535366
public function raw($sql)
    {
        $query = new Query\SqlQuery();

        if ($this->pdo) {
            $query->setPDO($this->pdo);
        }

        return $query->raw($sql);
    }
641110
public function exec($sql)
    {
        if ($sql instanceof Zend_Db_Select) {
            $sql = $sql->assemble();
        }

        try {
            $affected = $this->getConnection()->exec($sql);

            if ($affected === false) {
                $errorInfo = $this->getConnection()->errorInfo();
                /**
                 * @see Zend_Db_Adapter_Exception
                 */
                // require_once 'Zend/Db/Adapter/Exception.php';
                throw new Zend_Db_Adapter_Exception($errorInfo[2]);
            }

            return $affected;
        } catch (PDOException $e) {
            /**
             * @see Zend_Db_Adapter_Exception
             */
            // require_once 'Zend/Db/Adapter/Exception.php';
            throw new Zend_Db_Adapter_Exception($e->getMessage(), $e->getCode(), $e);
        }
    }
975272
public function parseSqlTable($sql)
    {
        if (false !== strpos($sql, '__')) {
            $prefix = $this->prefix;
            $sql    = preg_replace_callback("/__([A-Z0-9_-]+)__/sU", function ($match) use ($prefix) {
                return $prefix . strtolower($match[1]);
            }, $sql);
        }
        return $sql;
    }
760123
protected function _prep_query($sql)
	{
		// mysql_affected_rows() returns 0 for "DELETE FROM TABLE" queries. This hack
		// modifies the query so that it a proper number of affected rows is returned.
		if ($this->delete_hack === TRUE && preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql))
		{
			return trim($sql).' WHERE 1=1';
		}

		return $sql;
	}
354820
function buildQuery( $sql = NULL ) {
		if( !isset( $this->query ) OR empty( $sql ) ) {
			return FALSE;
		}

		$this->query .= $sql;

		return $this->query;
	}
1369982
public function fetch_string($sql)
    {

        if (empty($sql)) return false;

        $res = $this->query($sql);
        $row = @mysql_fetch_array($res);

        return (string)$row[0];
    }
521376
public function isQueryMutable($sql)
    {
        $operations = array_merge(
            Config::inst()->get(static::class, 'write_operations'),
            Config::inst()->get(static::class, 'ddl_operations')
        );
        return $this->isQueryType($sql, $operations);
    }
127503
public static String checkCompatibilityIssues( String sql ) {
        sql = sql.replaceAll("LONG PRIMARY KEY AUTOINCREMENT", "INTEGER PRIMARY KEY AUTOINCREMENT");
        sql = sql.replaceAll("AUTO_INCREMENT", "AUTOINCREMENT");
        return sql;
    }
1366580
public function prepare($sql)
    {
        $connection = ConnectionManager::getConnection();
        $statement = $connection->prepare($sql);
        $statement->setFetchMode(\PDO::FETCH_NUM);
        return $statement;
    }
827376
public function exec($sql)
    {
        $this->useConfiguredDatabase();
        $success = $this->getDbConnection()->exec($sql);
        $this->checkForDatabaseError($sql, 'exec');
        return $success;
    }
112472
public function isQueryWrite($sql)
    {
        $operations = Config::inst()->get(static::class, 'write_operations');
        return $this->isQueryType($sql, $operations);
    }
1179610
public function getTablesFromSQL($sql) {
        $p      = '/CREATE\s+TABLE\s+(IF\s+NOT\s+EXISTS\s+)?([^\(]+)/mi';
        $tables = [];
        $views  = [];
        if (preg_match_all($p, $sql, $ms, PREG_SET_ORDER)) {
            foreach ($ms as $m) {
                if (count($m) == 3) {
                    $table = $m [2];
                } else {
                    $table = $m [1];
                }
                if ($table) {
                    $table     = trim(trim($table, '` '));
                    $tables [] = str_replace('{prefix}', $this->tablePrefix, $table);
                }
            }
        }
        $p = '/CREATE\s+VIEW\s+(IF\s+NOT\s+EXISTS\s+)?(.+?)\s+AS/mi';
        if (preg_match_all($p, $sql, $ms, PREG_SET_ORDER)) {
            foreach ($ms as $m) {
                if (count($m) == 3) {
                    $table = $m [2];
                } else {
                    $table = $m [1];
                }
                if ($table) {
                    $table    = trim(trim($table, '` '));
                    $views [] = str_replace('{prefix}', $this->tablePrefix, $table);
                }
            }
        }

        return ['tables' => $tables, 'views' => $views];
    }
431403
public function exec(string $sql): int
    {
        $generator = $this->__exec($sql);
        if(!$generator->valid())
        {
            return $generator->getReturn();
        }
        $current = $generator->current();
        $generator->next();
        $generator->send($current);
        return $generator->getReturn();
    }