Jump to content


Connecting Grocery CRUD Enterprise to Postgres database


  • Please log in to reply
6 replies to this topic

#1 Loxter

Loxter

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 17 November 2017 - 03: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.

 

 

 



#2 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,058 posts
  • LocationLondon

Posted 18 November 2017 - 08: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

Posted Image

#3 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,058 posts
  • LocationLondon

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

Posted Image

#4 Loxter

Loxter

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 22 November 2017 - 10:39 AM

Hello John,

 

Thank You very much!

 

Both fixes work perfectly.



#5 antonello

antonello

    Newbie

  • Members
  • Pip
  • 1 posts

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.....



#6 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,058 posts
  • LocationLondon

Posted 26 November 2017 - 04: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


Posted Image

#7 eimiza

eimiza

    Newbie

  • Members
  • Pip
  • 1 posts

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..  :( 





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users