xpdo icon indicating copy to clipboard operation
xpdo copied to clipboard

[bug] don't work xPDOManager->createObjectContainer() in MySQL > 8

Open catsmeatman opened this issue 4 years ago • 1 comments

In src/xPDO/Om/mysql/xPDOManager.php:117 must check is exist table, but this is not working in MySQL8.

When try $manger->createObjectContainer() result is

Error Code: 1146. Table 'eparket.modx_epshop_payment' doesn't exist because table not created yet.`

Fix

$existsStmt = $this->xpdo->query("SELECT table_name FROM information_schema.tables where table_name = $tableName");

if (count($existsStmt->fetchAll()) > 0) {
    return true;
}

catsmeatman avatar Jul 21 '21 15:07 catsmeatman

That is not a fix. You are actually accessing the Database Management system's internal database - not your table.

I use the following function to create the tables:

  /**
     * Creates the database tables associated with the package.
     *
     * @return bool
     */
    public function createSchemaTables(): bool
    {
        $out = false;
        $schemaObjects = $this->getSchemaObjectNames();
        if (count($schemaObjects) > 0) {
            $manager = $this->modx->getManager();
            if ($manager instanceof xPDOManager) {
                $i = 0;
                foreach ($schemaObjects as $className) {
                    $i += ($manager->createObjectContainer($this->packageNamespace . $className) ? 1 : 0);
                }
                $out = (count($schemaObjects) == $i) ?: false;
            }
        }
        return $out;
    }

This might be a bit dated. There were issues with the namespace being correctly translated to table names. See https://github.com/modxcms/xpdo/issues/161

wshawn avatar Sep 24 '21 14:09 wshawn