/usr/local/miolo2/classes/database/odbc/mquery.class

Go to the documentation of this file.
00001 <?php
00002 
00003 class ODBCQuery extends MQuery
00004 {
00005     var $id_result;
00006 
00007     function __construct()
00008     {
00009         parent::__construct();
00010     }
00011 
00012     function _query()
00013     {
00014         $this->fetched = false;
00015         $this->sql = $this->maxrows ? $this->sql . " LIMIT $this->maxrows" : $this->sql;
00016         $this->sql = $this->offset ? $this->sql . " OFFSET $this->offset" : $this->sql;
00017         $this->id_result = odbc_exec($this->conn->id, $this->sql);
00018         $this->error = $this->_error();
00019 
00020         if (!$this->error)
00021         {
00022             $this->rowCount = odbc_num_rows($this->id_result);
00023 
00024             for ($n = 0; $n < $this->rowCount; $this->result[$n++] = odbc_fetch_array($this->id_result,$n));
00025 
00026             $this->fetched = true;
00027             $this->colCount = odbc_num_fields($this->id_result);
00028         }
00029         else
00030         {
00031             throw new EDatabaseQueryException($this->error);
00032         }
00033 
00034         return (!$this->error);
00035     }
00036 
00037     function _error()
00038     {
00039         return (($error = odbc_error($this->conn->id)) ? odbc_errormsg($this->conn->id) : false);
00040     }
00041 
00042     function _close()
00043     {
00044         if ($this->id_result)
00045         {
00046             odbc_free_result($this->id_result);
00047             unset ($this->id_result);
00048         }
00049     }
00050 
00051     function _setmetadata()
00052     {
00053         $numCols = $this->colCount;
00054         $this->metadata = array();
00055         for ($i = 1; $i <= $numCols; $i++)
00056         {
00057             $name = strtoupper(odbc_field_name($this->id_result, $i));
00058             $name = ($p = strpos($name, '.')) ? substr($name, $p + 1) : $name;
00059             $this->metadata['fieldname'][$i - 1] = $name;
00060             $this->metadata['fieldtype'][$name] = $this->_getmetatype(strtoupper(odbc_field_name($this->id_result, $i)));
00061             $this->metadata['fieldlength'][$name] = odbc_field_len($this->id_result, $i);
00062             $this->metadata['fieldpos'][$name] = $i - 1;
00063         }
00064     }
00065 
00066     function _getmetatype($type)
00067     {
00068         $type = strtoupper($type);
00069         $rType = 'N';
00070 
00071         if ($type == "VARCHAR")
00072         {
00073             $rType = 'C';
00074         }
00075         elseif ($type == "CHAR")
00076         {
00077             $rType = 'C';
00078         }
00079         elseif ($type == "NUMBER")
00080         {
00081             $rType = 'N';
00082         }
00083         elseif ($type == "INTEGER")
00084         {
00085             $rType = 'N';
00086         }
00087         elseif ($type == "DATE")
00088         {
00089             $rType = 'T';
00090         }
00091         elseif ($type == "TIMESTAMP")
00092         {
00093             $rType = 'T';
00094         }
00095 
00096         return $rType;
00097     }
00098 }
00099 ?>
CopyLeft (L) 2001-2006 - [MIOLO Development Team] SOLIS - Cooperativa de Soluções Livres - Lajeado/RS - Brasil