Jump to content


GC in postgres 9.1

postgres install codeigniter

  • Please log in to reply
15 replies to this topic

#1 jcasanova

jcasanova

    Advanced Member

  • Members
  • PipPipPip
  • 61 posts

Posted 13 April 2012 - 01:58 PM

Hi all As GC doesn't support Postgres, I made some fixes/changes to the model and I got it working!

TO DO: not too happy with one fix, about the insert_id, maybe someone could help.

If anybody needs it just let me know.

GREAT LIBRARY!!!

#2 Nahum

Nahum

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 16 April 2012 - 10:48 PM

Hi, I would see your change.
I start a new project with Codeigniter 2.1 and PostgreSQL 9.1.

#3 jcasanova

jcasanova

    Advanced Member

  • Members
  • PipPipPip
  • 61 posts

Posted 20 April 2012 - 11:56 AM

Hi, let me packed up and upload it. I need to change some stuff of the new version released the day before yesterday.
I'll keep you up

#4 jcasanova

jcasanova

    Advanced Member

  • Members
  • PipPipPip
  • 61 posts

Posted 26 April 2012 - 02:13 PM

I merged the new version into the model that works with Postgres, maybe doesn't work a 100% , but forme work for almost everything


I attached the model and the library (library has a one little modification) , you could use the load_model function of GC, if you don't want to mess with the core.

You have to do a one modification (I could not fixed from grocery model) to the postgre_driver.php of CI



function insert_id()
{
$v = $this->_version();
$v = $v['server'];

$table = func_num_args() > 0 ? func_get_arg(0) : NULL;
$column = func_num_args() > 1 ? func_get_arg(1) : NULL;

if ($table == NULL && $v >= '8.1')
{
$sql='SELECT LASTVAL() as ins_id';
}
elseif ($table != NULL && $column != NULL && $v >= '8.0')
{
$sql = sprintf("SELECT pg_get_serial_sequence('%s','%s') as seq", $table, $column);
$query = $this->query($sql);
$row = $query->row();
$sql = sprintf("SELECT CURRVAL('%s') as ins_id", $row->seq);
}
elseif ($table != NULL)
{
// seq_name passed in table parameter
$sql = sprintf("SELECT CURRVAL('%s') as ins_id", $table);
}
else
{
return pg_last_oid($this->result_id);
}
$query = $this->query($sql);
$row = $query->row();
return $row->ins_id;
}


#5 jcasanova

jcasanova

    Advanced Member

  • Members
  • PipPipPip
  • 61 posts

Posted 10 May 2012 - 02:06 PM

Here is an updated version, Fixed the relation_n_n, now its working.

this is the link,

http://uploading.com...ltimo+-+PG.rar/

#6 shoieb0101

shoieb0101

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 14 July 2012 - 08:55 PM

Here is an updated version, Fixed the relation_n_n, now its working.

this is the link,

http://uploading.com...ltimo+-+PG.rar/


thanks a lot for this. helped me a lot.

#7 tkalfigo

tkalfigo

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 30 October 2012 - 06:17 AM

Hi web-johnny and jcasanova.

I'm on CodeIgniter 2.1 and Postgres 9.1 and installed jcasanova's modified code for Postgres and after solving first couple of issues I'm stuck.
So far the following are working fine:
- table's contents are displayed
- column sorting
- delete record
- pagination
- refresh [cyclic green arrows next to pagination controls]
- search is not working properly but it has to do with missing explicit cast because LIKE doesn't implicitly cast non-alpha fields to text.

MAIN ISSUE: The following code does not have the desired result even though no errors are generated (I'm doing full error logging):
$crud = new grocery_CRUD();
$this->grocery_crud->set_table('foo');
$crud->columns('name','price'); /* I still see ALL colums displayed */
$crud->display_as('name','Name');
$crud->display_as('price','Price in $'); /* The column headers are not affected */
$crud->add_fields('name','price'); //when I click "Add record" I see ALL fields e.g. the "Id" field which should be autoincremented and I don't want it user assigned*/

Because of this I get the following problems when I try to "Add record":
(minor problem) it presents the undesired ID field which should normally be autoincremented (it's "serial" in Pg and corresponds to a sequence)
(major problem as a consequence of the minor problem) I have to assign a value to all fields, including the ID, and "Save" is clicked, nothing happens in the frontend (no changes, no errors) even though the record is stored in the DB. The reason is that Firebug shows me that the POST generated a 500 error, and the Pg logs show:

statement: INSERT INTO "foo" ("id", "name", "price") VALUES ('15', 'takis', '10');
LOG: duration: 55.734 ms
LOG: statement: SELECT LASTVAL() as ins_id
ERROR: lastval is not yet defined in this session
STATEMENT: SELECT LASTVAL() as ins_id
LOG: statement: rollback
NOTICE: there is no transaction in progress

The rollback raises a Notice since apparently no BEGIN was issued to start with. But the real problem is the Error that is raised by the call to LASTVAL() because as the Pg manual explains: lastval
... it fetches the value of the last sequence that nextval was used on in the current session. It is an error to call lastval if nextval has not yet been called in the current session.
and given how the INSERT is made (with the ID value planted manually) there is no call to nextval()

To summarize: the problems starts with the "add_field()" call not working properly (tried it with array argument as well). From there, I have to fill in the ID field in the "Add record" form, and from there the INSERT has to plant the value for ID manually which means that Pg's nextval() is not called on the sequence that corresponds to the ID field which in turn results in the call to LASTVAL() not making sense.

So the question is: how do I make the "Add record" form only show the fields that should be user provided and not the ones that are supposed to be autogenerated by the DB?

TIA,
Thalis Kalfigkopoulos

#8 jcasanova

jcasanova

    Advanced Member

  • Members
  • PipPipPip
  • 61 posts

Posted 30 October 2012 - 05:19 PM

Hi tkalfigo,

First of all reading at your code, I think the all the problems about displaying fields is because you are setting wrong the table
you have :
$this->grocery_crud->set_table('foo');

It should be:
$this->crud->set_table('foo');

try that one, let see how it goes.
About the lastval() issue, maybe you installed wrong the model... because it was working for me at the end...

I'm gonna check the project that I was working with CI, and I'll tell you if you need new modifications...

regards!

#9 botas_89

botas_89

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 30 October 2012 - 07:43 PM

Hi jcasanova


Thanks for the code and changes to postgresql ...

I introduced all the appropriate folders but I get an error:

A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 0

Filename: models/grocery_crud_model.php

Line Number: 328



I do not understand :wacko: .. I'm new to CI and Grocery Crud ..

I would appreciate your help in advance.

greetings from VENEZUELA...

#10 tkalfigo

tkalfigo

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 30 October 2012 - 10:12 PM

Thanx for the prompt reply jcasanova. I solved the issue, and it was indeed in my code and not in yours.

From reading this page from the documentation:
http://www.grocerycr...l_basic_methods
I copied this code:
$crud = new grocery_CRUD();
$crud->set_table('foo');


Apparently it works without explicitly instantiating the grocery_CRUD class.

All is set through $this->grocery_crud->crud_method() after of course you've loaded the library with $this->load->library('grocery_CRUD');

Regarding the "Search", it doesn't work for Pg if you search against any non-text field. I'll send the solution to this in a separate topic.

Thanx again,
Thalis K.

#11 tkalfigo

tkalfigo

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 30 October 2012 - 10:14 PM

Hi botas_89

The solution is to always have a primary key in each table. So just add an "id serial" and it'll go away.


Regards,
Thalis K.

#12 jcasanova

jcasanova

    Advanced Member

  • Members
  • PipPipPip
  • 61 posts

Posted 30 October 2012 - 10:29 PM

Hi botas_89

The solution is to always have a primary key in each table. So just add an "id serial" and it'll go away.


Regards,
Thalis K.


Thats an very IMPORTANT point, i wasted so many hour at the begining with that error... I missed the PK. So don't forget and check it very well.


I'm happy that works tkalfigo

#13 botas_89

botas_89

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 09 November 2012 - 05:23 PM

Hello again, thanks for the help .... Now I have another error ...
I try to make a table with grocery crud and link through but I get error ID ... thanks for the help.


This is my Controller:

function offices_management($id_proyecto='0')
{
$codigo=$this->input->post('proyec'); //This is to bring me the ID. And yes, I accept, but when I enter a new record in my table disappears ID
$id_proyecto=$codigo;

try{

/* This is only for the autocompletion */

$this->id_proyecto=$id_proyecto;
$crud = new grocery_CRUD();
$crud->set_theme('datatables');
$crud->set_table('objetivos_especificos');
$crud->where('id_proyecto',$id_proyecto);
$crud->set_subject('objetivos especificos');
$crud->required_fields("nombre_objetivo");
$crud->columns("id_proyecto","nombre_objetivo");
$crud->callback_add_field('id_proyecto',array($this,'add_field_callback_2'));
$crud->callback_before_insert(array($this,'add_proyecto'));
$output = $crud->render();
$this->_example_output($output);

}catch(Exception $e){
show_error($e->getMessage().' --- '.$e->getTraceAsString());
}

function add_proyecto($post_array)

{
$this->id_proyecto=$id_proyecto;
//if(empty($post_array['nro_solicitud']))
//{
// $post_array['nro_solicitud'] = '5';
//}
$post_array['id_proyecto'] = $this->id_proyecto;
return $post_array;
}


function add_field_callback_2()

{


return '<input type="text" disabled="disabled" maxlength="50" value="'.$this->id_proyecto.'" name="id_proyecto" style="width:400px"> ( ID Proyecto )';
}


Alguna sugerencia? ┬┐Se ve que es lo que quiero hacer?

#14 Raio Gmez

Raio Gmez

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 24 July 2013 - 07:29 PM

Here is an updated version, Fixed the relation_n_n, now its working.

this is the link,

http://uploading.com...ltimo+-+PG.rar/

 

Jcasanova Good day, you have a newer version of GC, if not, could you support telling me what functions you modified? thanks



#15 mcf

mcf

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 07 August 2015 - 08:20 PM

Hi everybody!

 

I'm working with Postgres 9.1 and i have trouble to apply the grocerycrud's grid. I read the message that the solution would be the modifications made jcasanova

I try download the jcasanova's file but it's infected... Someone can paste it into a post?

 

Thanks..



#16 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

Posted 10 August 2015 - 11:59 AM

It aint corrupted .. its the way u download it.. uncheck - download the file using their download accelerator - down load using firefox - it goes through smoothly .. i downdloaded it just now - it works smooth.







Also tagged with one or more of these keywords: postgres, install, codeigniter

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users