postgresql and grocery crud
- Single Page
Posted 21 December 2011 - 03:44 AM
thank you for the grocery crud,
but i wonder does it compatible with postgresql since the model uses lot of mysql command
regards
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
[/quote]
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.grocerycrud.com/crud/function_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
at application/models/grocery_model.php
function get_field_types_basic_table(){}
Posted 23 December 2011 - 18:57 PM
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;
}
Posted 31 January 2012 - 04:33 AM
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;
}
Posted 13 April 2012 - 01:13 AM
[quote]
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
[/quote]
Any help?
Posted 22 May 2013 - 14: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 :
- a complex query is needed to find primary keys of a given table (http://postgresql.1045698.n5.nabble.com/how-to-find-primary-key-field-name-td4893701.html)
- I'm not sure that PostgreSQL data types will be compatible with Grocery Crud