Postgres error on Environment.php

Issue #24 resolved
Former user created an issue

i'm trying to use your extension but i can't because i'm getting this error:

An exception occurred while executing 'nnrestapi_sessions': SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "nnrestapi_sessions" LINE 1: nnrestapi_sessions ^

I found this on /nnrestapi/Classes/Utilities/Environment.php:

line 29. if ($connection->fetchAll("SHOW TABLES like '{$tableName}'")) {

but Postgres don't have show tables,

Comments (2)

  1. David Bascom

    Unfortunatly we do not have a testsystem with PostgreSQL installed. Could you try replacing the databaseTableExists() method discribed above with following code?

    Let me know, if it works.
    If not, could you debug $result for me?

    public function databaseTableExists( $tableName = '') 
    {
        $connection = \nn\t3::Db()->getConnection();
    
        $serverVersion = $connection->getServerVersion();
        $isPostgres = stripos($serverVersion, 'PostgreSQL') !== false;
    
        if ($isPostgres) {
            $result = $connection->fetchAll("
                SELECT 
                    COUNT(table_name) 
                FROM 
                    information_schema.tables 
                WHERE 
                    table_schema LIKE 'public' 
                    AND table_type LIKE 'BASE TABLE' 
                    AND table_name = '{$tableName}'
                ");
            return $result > 0;
        }
    
        if ($connection->fetchAll("SHOW TABLES like '{$tableName}'")) {
            return true;
        }
    
        return false;
    }
    

    THX!

  2. David Bascom

    Closing this due to missing feedback. If this error still exists, a new workaround is now to disable the PreCheck in the Extension Configuration of nnrestapi (see Fix Issue #26 Add possibility to deactivate Warnings and Error messages).

  3. Log in to comment