Hi:
I included some fixes on my zoop downloaded code in order to use Oracle (in my case 10g XE version). I must note that this fixes are not a complete support of Oracle DBs, it's just a start.
Fix 1: Get table info functionality
I extended function database::get_table_info on file db/PDO_database.php:
function get_table_info($table)
{
//FIX: extended to support Oracle
if ($this->db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql')
{
//echo "Running on mysql; doing something mysql specific here\n";
$a = $this->getAll("describe $table");
//echo_r($a);
foreach ($a as $field ) {
$field_info = array();
$field_info['table'] = $table;
$field_info['name'] = $field['Field'];
$field_info['type'] = substr($field['Type'], 0, strpos($field['Type'], "("));
$field_info['len'] = substr($field['Type'], strpos($field['Type'], "(")+1, strpos($field['Type'], ")")+1);
$extra = array();
$extra[] = $field['Extra'];
if ($field['Key'] == 'PRI' ) {
$extra[] = "primary_key";
}
if ($field['Null'] == "NO") {
$extra[] = "not_null";
}
$field_info['flags'] = implode($extra, " ");
$table_info[] = $field_info;
}
return $table_info;
}
else if ($this->db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'oci')
{
$primaryKey = "";
$a = $this->getAll("SELECT * FROM
ALL_CONS_COLUMNS A
JOIN
ALL_CONSTRAINTS C
ON
A.CONSTRAINT_NAME = C.CONSTRAINT_NAME
WHERE
C.TABLE_NAME = '$table' AND
C.CONSTRAINT_TYPE = 'P'");
if (count($a) > 0)
{
$field = $a[0];
$primaryKey = $field['COLUMN_NAME'];
}
$a = $this->getAll("SELECT * FROM USER_TAB_COLUMNS WHERE TABLE_NAME='$table'");
//echo_r($a);
foreach ($a as $field ) {
$field_info = array();
$field_info['table'] = $table;
$field_info['name'] = $field['COLUMN_NAME'];
$field_info['type'] = $field['DATA_TYPE'];
$field_info['len'] = $field['DATA_LENGTH'];
$extra = array();
if ($field['COLUMN_NAME'] == $primaryKey ) {
$extra[] = "primary_key";
}
if ($field['NULLABLE'] == "N") {
$extra[] = "not_null";
}
$field_info['flags'] = implode($extra, " ");
$table_info[] = $field_info;
}
return $table_info;
}
}
Fix 2:
I extended function table::getRecords on file forms/table.php:
function getRecords() # LIMIT OF -1 GIVES YOU ALL THE RECORDS
{
$dbconnname = $this->dbconnname;
global $$dbconnname;
$this->setupRequirements();
$this->records = NULL; # FIRST UNSET ALL THE CURRENT RECORDS
$this->getTotal();
if ($this->cur < 1)
$this->cur = 0;
//FIX: Use ROWNUM in Oracle
if ($$dbconnname->db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'oci')
{
$query = "SELECT $this->name.*, ROWNUM row_num FROM $this->name $this->wherestr";
}
else
{
$query = "SELECT * FROM $this->name $this->wherestr";
}
if (isset($this->sort))
$query .=" ORDER BY $this->sort";
if (isset($this->sort) && isset($this->direction) && ($this->direction == "ASC" || $this->direction == "DESC"))
$query .= " $this->direction";
//FIX: Use ROWNUM in Oracle
if ($$dbconnname->db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'oci')
{
if ($this->limit != -1 && is_numeric($this->limit))
{
$query = "SELECT * FROM (" . $query . ") WHERE row_num BETWEEN $this->cur AND " . ($this->cur + $this->limit);
}
}
else
{
if ($this->limit != -1 && is_numeric($this->limit))
{
$query .= " LIMIT $this->limit OFFSET $this->cur";
}
}
$this->sql = $query;
$results = $$dbconnname->fetch_rows($query);
foreach ($results as $array)
{
$idfield = $this->idfield;
$id = $array[$idfield];
$this->records[$id] = new record($this->name, $id, $idfield, $dbconnname, $array);
}
}
Important: I just proved thoses fixes with forms2 lists.
Fix 3: For properly execution of Zoop db_component generic functions (fetch_one_cell, etc.) when the connection string defined on /config/db.php is like:
define('db_RDBMS', 'oci');
define('db_Username', 'user');
define('db_Password', 'password');
define('db_Server', 'server');
define('db_Port', '1521');
define('db_Database', '');
I also create a copy of file db/mysql.php renamed db/oci.php and change function sql_insert:
function sql_insert($query)
{
sql_connect();
global $defaultdb;
$defaultdb->insert($query);
//TODO: Retrieve last id from Oracle sequence?
return -1;
}
It leaves return value unuseless is better than nothing for the while.
Important: I just proved this fix with the most basic functions:
- fetch_one_cell.
- query
- insert
I hope this helps a bit
Compare to the rest of the
Compare to the rest of the codes that pertains to oracle I have found on the other sites, only this one works with me, thanks for this.
buy silver coins
It's a really great help.
It's a really great help. Thanks for your work and efforts.
Looking for a Turkey vacation ? Visit my holiday guide and get ready to book beach villas online from the owner.
Nice to read your article! I
Nice to read your article! I am looking forward to sharing your adventures and experiences. anime mobile
that's the info i need now
that's the info i need now for my work, it greatly helped me!
iflexion web company