Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

system/Database/BaseConnection.php Change in getFieldNames() method #164

Closed
Portaflex opened this issue Jul 14, 2016 · 7 comments
Closed

Comments

@Portaflex
Copy link
Contributor

After this:

public function getFieldNames($table)
    {
        // Is there a cached result?
        if (isset($this->dataCache['field_names'][$table]))
        {
            return $this->dataCache['field_names'][$table];
        }
        //... rest of the funcion ...//

We have to call $this->initialize() again:

public function getFieldNames($table)
    {
        // Is there a cached result?
        if (isset($this->dataCache['field_names'][$table]))
        {
            return $this->dataCache['field_names'][$table];
        }
        if (empty($this->connID))
        {
            $this->initialize();
        }
               //... rest of the function ...//

As you know, I'm not proficient in making pullrequest. ;-)

@lonnieezell
Copy link
Member

Could you describe what you're seeing that makes you think this is needed? How can I repeat the issue?

@Portaflex
Copy link
Contributor Author

This code is at line 239 in DS_tablax.php

$this->db = \Config\Database::connect($this->base_datos);
$this->builder = $this->db->table($this->db_tabla);
$this->db_columnas = $this->db->getFieldNames($this->db_tabla);

which is a class I use to generate a complete html table. I pass a configuration array from controller Home.php.

I need to get table columns names before doing the final query to populate the html table and, unless changing getFieldNames() method, $this->connID would be lost.

Thanks you.

@lonnieezell
Copy link
Member

lonnieezell commented Jul 16, 2016

I'm not seeing an issue with that code working for me with the latest develop branch.

I ran those same three queries in my Home controller, and tried several different combinations of queries after those three, and everything seemed to work as expected. The database is always initialized during a query() or simpleQuery() so I can't really see a need for it here. Especially since I'm not able to replicate any issues.

Are you using MySQL or PostgreSQL?

I'm also confused how $this->connID gets lost? I don't see anything in getFieldNames() that would destroy the connection. Am I missing something?

@Portaflex
Copy link
Contributor Author

Yes, in fact I'm using Postgre. The php function that fails is pg_escape_literal(). It needs connID as first paramenter and fails with error message "expecting $connID to be object, boolean given".

Maybe the issue happens because I'm calling getFieldNames() before any query, and It calls $this->_listColumns() before initializing the connection.

I'm connecting to database not in localhost but to another computer. Don't know why MySQL is working. :-(

@Portaflex
Copy link
Contributor Author

We have two getFieldNames() methods, one in BaseConnection.php and another in Postgre/Result.php.

The second gets the field name of each query-result row number using pg_field_name() once the query has been executed.

The first executes a query itself independent of any other query. Therefore, in my case, no initialization has yet happened. Moreorver, this method invokes _listColums() which, in turn, also needs $this->connID to pass to pg_escape_literal, before calling $this->query().

Regards.

@lonnieezell
Copy link
Member

ok, cool. That makes sense then. I'll add that check. Just trying to make sure we were fixing the right problem. :)

@Portaflex
Copy link
Contributor Author

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants