⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Connecting Grocery CRUD Enterprise to Postgres database



Loxter

Loxter
  • profile picture
  • Member

Posted 17 November 2017 - 15:22 PM

Hello,

 

I`m having difficulty running Grocery CRUD Enterprise with postgresql database.

 

While using version 2.3.7 I was able to run CRUD on table, but column search (and tbh any ajax operations) was not working.

 

After upgrade to 2.4.1 I am getting Internal Server error:

 

<h4>An uncaught Exception was encountered</h4>

<p>Type: Exception</p>
<p>Message: Table "" does not exist</p>
<p>Filename: MyAppAdress/application/libraries/GroceryCrudEnterprise/zendframework/zend-db/src/Metadata/Source/AbstractSource.php</p>
<p>Line Number: 124</p>

 

 

No data is presented.

 

My sample controller:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

// Add those two lines at the beginning of your controller
include(APPPATH . 'libraries/GroceryCrudEnterprise/autoload.php');
use GroceryCrud\Core\GroceryCrud;

Class Crud_test extends CI_Controller {


private function _getDbData() {
        $db = [];
        include(APPPATH . 'config/database.php');
        return [
            'adapter' => [
                'driver' => 'Pgsql',
                'host'     => $db['default']['hostname'],
                'database' => $db['default']['database'],
                'username' => $db['default']['username'],
                'password' => $db['default']['password'],
                'port' => '5432',
                'charset' => 'utf8'
            ]
        ];
    }
private function _getGroceryCrudEnterprise($bootstrap = true, $jquery = true) {
        $db = $this->_getDbData();
        $config = include(APPPATH . 'config/gcrud-enterprise.php');
        $groceryCrud = new GroceryCrud($config, $db);
        return $groceryCrud;
}

// Your function at your controller
public function demo_set_model()
{
    $crud = $this->_getGroceryCrudEnterprise();   
    $crud->setTable('my_table');
    $crud->setSubject('my_table_subject', 'my_table_subject');
    $crud->columns(['my_column']);    
    $output = $crud->render();
    $this->_example_output($output);
}

function _example_output($output = null) {
    if (isset($output->isJSONResponse) && $output->isJSONResponse) {
                header('Content-Type: application/json; charset=utf-8');
                echo $output->output;
                exit;
    }

    $this->load->view('example.php',$output);    
}
}

 

 

I tried different ways for input table name (including "schema"."my_table" etc) but with no result.

CRUD does connect to the database.

If I input non-existent table name the error message is slightly different (Table "wrong_table_name" does not exist - instead of empty "").

 

Do I have to use different driver? I tried 'Pdo_Pgsql' and 'Pgsql' so far.

 

I would highly appreciate any clues and ideas.

 

Also, I can always downgrade to 2.3.7 if there is any fix for column search errors.

 

 

 


web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 18 November 2017 - 20:33 PM

I did find the issue of your problem. At 2.4.1 I did a small refactoring of DatagridState and I did miss a line of code and this is causing a bug at Postgres database only!

The change however is simple, just go to:
 
application/libraries/GroceryCrudEnterprise/Core/State/DatagridState.php
 
and move the line around 96 to line 93 (more specifically move the line: 
$this->setInitialData();
 to the beginning of the getData() function.
 
Your final file will look something like this:
 
public function getData() {
    $this->setInitialData();

    $stateParameters = $this->getStateParameters();
    $config = $this->getConfigParameters();

    $this->initialize($stateParameters);

    $model = $this->gCrud->getModel();

    $allColumns = $this->getColumns(StateAbstract::WITH_PRIMARY_KEY);
...
 
Please let me know if that worked for you so I can also release it to the version 2.4.1 as a patch fix.
 
Regards
Johnny

web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 22 November 2017 - 05:50 AM

Hello Luke,

 
I was also able to fix this issue with the error that you had on the search.

Basically on: application/libraries/GroceryCrudEnterprise/Core/Model.php at around line 303, change the line:

 $filter_name =  '`' . $this->tableName. '`.`' . $filter_name . '`';

to:

$filter_name =  $this->tableName. '.' . $filter_name;

and it should work for you.
 
Please let me know if that fixed your issue and if you have any further issues. This is now part of version 2.4.1 as a patch fix.
 
Regards
Johnny

Loxter

Loxter
  • profile picture
  • Member

Posted 22 November 2017 - 10:39 AM

Hello John,

 

Thank You very much!

 

Both fixes work perfectly.


antonello

antonello
  • profile picture
  • Member

Posted 23 November 2017 - 09:47 AM

Good morning John Skoumbourdis

and also to the newbie that opend this topic.

I have installed grocery crud enterprise few days ago....i had the same problem in filtering columns.....I have solved with the code software modification indicated....i also confirm it is ok.....


web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 26 November 2017 - 16:58 PM

Very glad that I have 2 confirmations for this fix  :D 

For all the others have in mind that this is a quite release at the 2.4.1 so anyone downloading the latest version the fix will already be there  ^_^ 

Enjoy :)
Johnny


eimiza

eimiza
  • profile picture
  • Member

Posted 21 March 2019 - 10:06 AM

Hi, this is my first time using grocery crud. I already purchased the grocerycrud enterprise for the sake of using it with Postgresql. My project is base on Codeigniter and PostgreSql. I already follow the step to install grocerycrud enterprise to codeigniter but i stuck on configuring the database information. The example show 'driver' => 'Pdo_Mysql', but i already try to change the driver to Pgsql, postgre, Pgsql, Pdo_Pgsql but is still wont work and i show this error:

 

GroceryCrud\Core\Render\RenderAbstract Object ( [output] =>

Ooooops, something went wrong! This is probably a misconfiguration in Grocery CRUD Enterprise!
Please share any documentation or tutorial for grocerycrud+codeigniter+postgresql.. I really2 need this. Thank you very much..  :( 

web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 19 October 2019 - 13:48 PM

Hello all,

 

I am glad to update you that I've created a new tutorial for PostgreSQL database. You can see tutorial documentation here: https://www.grocerycrud.com/enterprise/examples-3/database-connection-postgresql/

Regards

Johnny