[eluser]lsousa[/eluser]
Hi,
In a ODBC db, when using $this->db->field_data(), the primary key is not defined.
I've searched in odbc_result.php and I've found out that primary_key is always set to 0.
Code:
function field_data()
{
$retval = array();
for ($i = 1; $i <= $this->num_fields(); $i++)
{
$F = new stdClass();
$F->name = odbc_field_name($this->result_id, $i);
$F->type = odbc_field_type($this->result_id, $i);
$F->max_length = odbc_field_len($this->result_id, $i);
$F->primary_key = 0;
$F->default = '';
$retval[] = $F;
}
return $retval;
}
But there is a method to find out which is the primary key using ODBC.
I've wrote the following function on odbc_driver.php
Code:
function primary_key($table = '')
{
if ($table == '')
{
return 0;
}
$result = @odbc_primarykeys($this->conn_id,$this->database,"dbo",$table);
return (odbc_result($result,"COLUMN_NAME"));
}
Using this, if I call $this->db->field_data('table_name') from the controller I get the correct primary_key name, so far so good. But now I've a problem, I don't know how to set the primary_key correctly when calling $this->db->field_data().
My idea was to do something such as this on odbc_result.php/field_data:
Code:
function field_data()
{
$retval = array();
for ($i = 1; $i <= $this->num_fields(); $i++)
{
$F = new stdClass();
$F->name = odbc_field_name($this->result_id, $i);
$F->type = odbc_field_type($this->result_id, $i);
$F->max_length = odbc_field_len($this->result_id, $i);
$F->primary_key = odbc_field_name($this->result_id, $i) === $primary_key ? 1 : 0;
$F->default = '';
$retval[] = $F;
}
return $retval;
}
Where $primary_key is set using my primary_key() function.
Can anyone help?
I don't really need this, I'm just trying to improve field_data() when using ODBC so it could be added to codeigniter source.
PS: I'm sorry for any mistake, but english is not my primary language
Thanks in advance,
LS