⚠ 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 forum is read-only and soon will be archived. ⚠


postgresql and grocery crud

postgre

  • Please log in to reply
5 replies to this topic

#1 olivetech

olivetech

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 21 December 2011 - 03:44 AM

hi

thank you for the grocery crud,
but i wonder does it compatible with postgresql since the model uses lot of mysql command

regards

#2 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,166 posts

Posted 21 December 2011 - 07:20 AM

hi

thank you for the grocery crud,
but i wonder does it compatible with postgresql since the model uses lot of mysql command

regards


Actually the first thought it was to use only the active record to have all the queries. After that I realized that the codeigniter drivers are really weak. So it was difficult for me to stay only with the active record. Now it works only with mySQL and mySQLi .

If you like you can have a try with the model. You can use the set_model ( http://www.grocerycr..._name/set_model ), so you don't have to change the core of grocery CRUD , see what the error will be and just create a model for postgresql. For now it will be easy because you will have to change only ONE function, the
function get_field_types_basic_table(){}
at application/models/grocery_model.php

#3 Nicholas

Nicholas

    Member

  • Members
  • PipPip
  • 13 posts

Posted 23 December 2011 - 06:57 PM

Note that the same technique can be used for MSSQL/SQLServer, The get_field_types and get_field_types_basic_table methods must be managed to populate the primary key. Alternatively you can modify the core field_data method at system/database/drivers/mssql/mssql_result.php. This is an ugly hack to use the first field as a primary key. Hope it helps someone :)

function field_data()
{
  $retval = array();
  $counter=1;
  while ($field = mssql_fetch_field($this->result_id))
  {
   $F    = new stdClass();
   $F->name  = $field->name;
   $F->type  = $field->type;
   $F->max_length = $field->max_length;
  
   // hack for primary key
    if ($counter == 1) {
			    $F->primary_key = 1;
			    $counter++;
		    } else {
			    $F->primary_key = 0;
		    }
  
   $F->default  = '';
   $retval[] = $F;
  }
  return $retval;
}


#4 Heden

Heden

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 31 January 2012 - 04:33 AM

On SQL 2000

if you have problem like this below :

A Database Error Occurred
Error Number:
Incorrect syntax near the keyword 'FROM'.
SHOW COLUMNS FROM {table_name}
Filename: D:\xampp\htdocs\NAVY\system\database\DB_driver.php
Line Number: 330




The solution is :

update function get_field_types_basic_table in grocery_model.php


    function get_field_types_basic_table()
    {
  $sql = "select column_name as Field, data_type+'('+convert(varchar(255), character_maximum_length)+')' as Type, is_nullable as [Null], case when ordinal_position = 1 then 'PRI' else '' end as [Key], column_default as [Default], '' as Extra from information_schema.columns where table_name = '{$this->table_name}'";
	 $db_field_types = array();
	 //foreach($this->db->query("SHOW COLUMNS FROM {$this->table_name}")->result() as $db_field_type)
  foreach($this->db->query($sql)->result() as $db_field_type)
	 {
	  $type = explode("(",$db_field_type->Type);
	  $db_type = $type[0];
	 
	  if(isset($type[1]))
	  {
	   $length = substr($type[1],0,-1);
	  }
	  else
	  {
	   $length = '';
	  }
	  $db_field_types[$db_field_type->Field]['db_max_length'] = $length;
	  $db_field_types[$db_field_type->Field]['db_type'] = $db_type;
	  $db_field_types[$db_field_type->Field]['db_null'] = $db_field_type->Null == 'YES' ? true : false;
	  $db_field_types[$db_field_type->Field]['db_extra'] = $db_field_type->Extra;
	 }
	
	 $results = $this->db->field_data($this->table_name);
	 foreach($results as $num => $row)
	 {
	  $row = (array)$row;
	  $results[$num] = (object)( array_merge($row, $db_field_types[$row['name']])  );
	 }
	
	 return $results;
    }


#5 reynierpm

reynierpm

    Member

  • Members
  • PipPip
  • 13 posts

Posted 13 April 2012 - 01:13 AM

I have the same problem and try your solution but get this error instead:

Error Number:
ERROR: syntax error at or near "," LINE 1: ..._name as Field, data_type+'('+convert(varchar(255), characte... ^
select column_name as Field, data_type+'('+convert(varchar(255), character_maximum_length)+')' as Type, is_nullable as [Null], case when ordinal_position = 1 then 'PRI' else '' end as [Key], column_default as [Default], '' as Extra FROM information_schema.columns where table_name = 'tr007_usuarios'
Filename: /var/www/html/sic-auto-gas/models/grocery_crud_model.php
Line Number: 265

Any help?

#6 Juliette F

Juliette F

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 22 May 2013 - 02:50 PM

I have the same problem and try your solution but get this error instead:

Any help?

 

I tried to find the correct query with PostgreSQL but it's really more complicated because :






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users