aliroAbstractDatabase Class Reference

Inheritance diagram for aliroAbstractDatabase:

aliroDatabaseHandler database

List of all members.

Public Member Functions

 __construct ($host='localhost', $user, $pass, $db, $table_prefix, $return_on_error=false)
 __destruct ()
 getName ()
 getAllFieldInfo ($tablename)
 getAllFieldNames ($tablename)
 addFieldIfMissing ($tablename, $fieldname, $fieldspec, $alterIfPresent=false)
 alterField ($tablename, $fieldname, $fieldspec)
 getFieldInfo ($tablename, $fieldname)
 setFieldValue ($value)
 tableExists ($tablename)
 getErrorNum ()
 getErrorMsg ()
 getEscaped ($text)
 Quote ($text)
 setQuery ($sql, $cached=false, $prefix='#__')
 replacePrefix ($sql, $prefix='#__')
 restoreOnePrefix ($tablename)
 getQuery ($sql='')
 query ($sql='')
 doSQL ($sql)
 doSQLget ($sql, $classname='stdClass', $key='', $max=0)
 query_batch ()
 getNumRows ($cur=null)
 getAffectedRows ()
 loadResult ()
 loadResultArray ($numinarray=0)
 loadAssocList ($key='')
 mosBindArrayToObject ($array, $obj, $ignore='', $prefix=NULL, $checkSlashes=true)
 mosStripslashes ($value)
 loadObject (&$object)
 loadObjectList ($key='')
 loadRow ()
 loadRowList ($key='')
 insertObject ($table, $object, $keyName=NULL)
 updateObject ($table, $object, $keyName, $updateNulls=true)
 stderr ($showSQL=false)
 insertid ()
 getVersion ()
 GenID ()
 getTableList ()
 getTableCreate ($tables)
 getTableFields ($tables)
 getCount ()
 getLogged ()

Protected Member Functions

 forceOffline ($error_number)
 setBareQuery ($sql)
 retrieveResults ($key='', $max=0, $result_type='row')

Protected Attributes

 $_sql = ''
 $_cached = false
 $_errorNum = 0
 $_errorMsg = ''
 $_table_prefix = ''
 $_resource = ''
 $_cursor = null
 $_log = array()
 $DBname = ''
 $DBInfo = null
 $cache = null
 $interface = null

Static Protected Attributes

static $stats = array()

Private Member Functions

 clearCache ()
 getTableInfo ()
 storeFields ($tablename)
 nonzeromin ($x, $y)
 findMatchingQuote ($text, $quote)
 doInsertion ($table, $fields, $values)
 doUpdate ($table, $setters, $conditions)
 saveStats ()


Detailed Description

Definition at line 99 of file aliroDatabase.php.


Constructor & Destructor Documentation

aliroAbstractDatabase::__construct ( host = 'localhost',
user,
pass,
db,
table_prefix,
return_on_error = false 
)

Definition at line 114 of file aliroDatabase.php.

References forceOffline(), databaseInterfaceFactory::getInterface(), and getTableInfo().

00114                                                                                                                {
00115         // perform a number of fatality checks, then die gracefully if necessary
00116         $this->DBname = $db;
00117         if (!$this->interface = databaseInterfaceFactory::getInterface()) {
00118             if ($return_on_error) {
00119                 $this->_errorNum = _ALIRO_DB_NO_INTERFACE;
00120                 return;
00121             }
00122             $this->forceOffline(_ALIRO_DB_NO_INTERFACE);
00123         }
00124         if (!($this->_resource = $this->interface->connect($host, $user, $pass, $db))) {
00125             $this->_errorMsg = $this->interface->connectError();
00126             if ($return_on_error) {
00127                 $this->_errorNum = _ALIRO_DB_CONNECT_FAILED;
00128                 return;
00129             }
00130             $this->forceOffline(_ALIRO_DB_CONNECT_FAILED);
00131         }
00132         $this->interface->setCharset('utf8');
00133         $this->cache = new aliroSimpleCache('aliroAbstractDatabase', true);
00134         $this->DBInfo = $this->cache->get($host.$db.$user.$table_prefix, _ALIRO_DATABASE_CACHE_TIME);
00135         if (!$this->DBInfo) {
00136             $this->DBinfo = new stdClass();
00137             $this->DBInfo->DBTables = array();
00138             $this->DBInfo->DBFields = array();
00139             $this->DBInfo->DBFieldsByName = array();
00140         }
00141         $this->_table_prefix = $table_prefix;
00142         $this->getTableInfo();
00143     }

aliroAbstractDatabase::__destruct (  ) 

Definition at line 145 of file aliroDatabase.php.

References aliro::getInstance(), and saveStats().

00145                                   {
00146         try {
00147             @session_write_close();
00148             if (aliro::getInstance()->installed) $this->saveStats();
00149         } catch (databaseException $exception) {
00150             exit('DB Error during shutdown');
00151         }
00152     }


Member Function Documentation

aliroAbstractDatabase::clearCache (  )  [private]

Definition at line 154 of file aliroDatabase.php.

Referenced by addFieldIfMissing(), and alterField().

00154                                    {
00155         $this->cache->clean();
00156     }

aliroAbstractDatabase::getTableInfo (  )  [private]

Definition at line 158 of file aliroDatabase.php.

References loadResultArray(), restoreOnePrefix(), and setBareQuery().

Referenced by __construct().

00158                                      {
00159         if (count($this->DBInfo->DBTables) == 0) {
00160             $this->setBareQuery ("SHOW TABLES");
00161             if ($results = $this->loadResultArray()) foreach ($results as $result) $this->DBInfo->DBTables[] = $this->restoreOnePrefix($result);
00162             $this->cache->save($this->DBInfo);
00163         }
00164     }

aliroAbstractDatabase::storeFields ( tablename  )  [private]

Definition at line 166 of file aliroDatabase.php.

References doSQLget().

Referenced by getAllFieldInfo(), getAllFieldNames(), and getFieldInfo().

00166                                               {
00167         if (!isset($this->DBInfo->DBFields[$tablename])) {
00168             $this->DBInfo->DBFields[$tablename] = $this->doSQLget("SHOW FIELDS FROM `$tablename`");
00169             $this->DBInfo->DBFieldsByName[$tablename] = array();
00170             foreach ($this->DBInfo->DBFields[$tablename] as $field) $this->DBInfo->DBFieldsByName[$tablename][$field->Field] = $field;
00171             $this->cache->save($this->DBInfo);
00172         }
00173     }

aliroAbstractDatabase::getName (  ) 

Definition at line 175 of file aliroDatabase.php.

00175                                {
00176         return $this->DBname;
00177     }

aliroAbstractDatabase::getAllFieldInfo ( tablename  ) 

Definition at line 179 of file aliroDatabase.php.

References storeFields().

00179                                                  {
00180         $this->storeFields($tablename);
00181         return $this->DBInfo->DBFields[$tablename];
00182     }

aliroAbstractDatabase::getAllFieldNames ( tablename  ) 

Definition at line 184 of file aliroDatabase.php.

References storeFields().

Referenced by addFieldIfMissing(), alterField(), insertObject(), and updateObject().

00184                                                   {
00185         $this->storeFields($tablename);
00186         return array_keys($this->DBInfo->DBFieldsByName[$tablename]);
00187     }

aliroAbstractDatabase::addFieldIfMissing ( tablename,
fieldname,
fieldspec,
alterIfPresent = false 
)

Definition at line 189 of file aliroDatabase.php.

References alterField(), clearCache(), doSQL(), and getAllFieldNames().

00189                                                                                                   {
00190         if (in_array($fieldname, $this->getAllFieldNames($tablename))) {
00191             if ($alterIfPresent) return $this->alterField($tablename, $fieldname, $fieldspec);
00192             return false;
00193         }
00194         $this->doSQL("ALTER TABLE $tablename ADD `$fieldname` ".$fieldspec);
00195         $this->clearCache();
00196         return true;
00197     }

aliroAbstractDatabase::alterField ( tablename,
fieldname,
fieldspec 
)

Definition at line 199 of file aliroDatabase.php.

References clearCache(), doSQL(), and getAllFieldNames().

Referenced by addFieldIfMissing().

00199                                                                     {
00200         if (in_array($fieldname, $this->getAllFieldNames($tablename))) return false;
00201         $this->doSQL("ALTER TABLE $tablename CHANGE COLUMN `$fieldname` ".$fieldspec);
00202         $this->clearCache();
00203         return true;
00204     }

aliroAbstractDatabase::getFieldInfo ( tablename,
fieldname 
)

Definition at line 206 of file aliroDatabase.php.

References storeFields().

00206                                                           {
00207         $this->storeFields($tablename);
00208         return isset($this->DBInfo->DBFieldsByName[$tablename][$fieldname]) ? $this->DBInfo->DBFieldsByName[$tablename][$fieldname] : null;
00209     }

aliroAbstractDatabase::setFieldValue ( value  ) 

Definition at line 211 of file aliroDatabase.php.

References getEscaped().

Referenced by insertObject(), and updateObject().

00211                                            {
00212         if (is_numeric($value)) {
00213             if ((string) $value == (string) (int) $value) return (string) $value;
00214             else return "'".(string) $value."'";
00215         }
00216         $value = $this->getEscaped($value);
00217         return "'".$value."'";
00218     }

aliroAbstractDatabase::tableExists ( tablename  ) 

Definition at line 221 of file aliroDatabase.php.

00221                                              {
00222         return in_array($tablename, $this->DBInfo->DBTables);
00223     }

aliroAbstractDatabase::forceOffline ( error_number  )  [protected]

Definition at line 225 of file aliroDatabase.php.

Referenced by __construct().

00225                                                     {
00226             new aliroOffline ($error_number);
00227             // Uncomment this for more diagnostics
00228             // echo aliroRequest::trace();
00229             exit();
00230     }

aliroAbstractDatabase::getErrorNum (  ) 

Definition at line 233 of file aliroDatabase.php.

00233                                   {
00234         return $this->_errorNum;
00235     }

aliroAbstractDatabase::getErrorMsg (  ) 

Definition at line 238 of file aliroDatabase.php.

00238                                   {
00239         return str_replace( array( "\n", "'" ), array( '\n', "'" ), $this->_errorMsg );
00240     }

aliroAbstractDatabase::getEscaped ( text  ) 

Definition at line 243 of file aliroDatabase.php.

Referenced by saveStats(), and setFieldValue().

00243                                       {
00244         return $this->interface->getEscaped($text);
00245     }

aliroAbstractDatabase::Quote ( text  ) 

Definition at line 248 of file aliroDatabase.php.

00248                                    {
00249         return '\''.$this->getEscaped($text).'\'';
00250     }

aliroAbstractDatabase::setBareQuery ( sql  )  [protected]

Definition at line 253 of file aliroDatabase.php.

Referenced by getTableInfo().

00253                                           {
00254         $this->_sql = $sql;
00255     }

aliroAbstractDatabase::setQuery ( sql,
cached = false,
prefix = '#__' 
)

Definition at line 258 of file aliroDatabase.php.

References replacePrefix().

Referenced by doSQL(), doSQLget(), getTableCreate(), and getTableList().

00258                                                                    {
00259         $this->_sql = $this->replacePrefix($sql, $prefix);
00260         $this->_cached = $cached;
00261     }

aliroAbstractDatabase::replacePrefix ( sql,
prefix = '#__' 
)

Definition at line 264 of file aliroDatabase.php.

References findMatchingQuote(), and nonzeromin().

Referenced by setQuery().

00264                                                         {
00265         $text = $sql;
00266         $result = '';
00267         while ($text) {
00268             $firstquote = $this->nonzeromin(strpos($text, "'"), strpos($text, '"'));
00269             if ($firstquote) {
00270                 $result .= str_replace($prefix, $this->_table_prefix, substr($text,0,$firstquote));
00271                 $text = substr($text, $firstquote);
00272                 $endquote = $this->findMatchingQuote($text, $text[0]);
00273                 $result .= substr($text, 0, $endquote+1);
00274                 $text = substr($text, $endquote+1);
00275             }
00276             else {
00277                 $result .= str_replace($prefix, $this->_table_prefix, $text);
00278                 break;
00279             }
00280         }
00281         return $result;
00282     }

aliroAbstractDatabase::nonzeromin ( x,
y 
) [private]

Definition at line 284 of file aliroDatabase.php.

Referenced by replacePrefix().

00284                                          {
00285         if (false === $x) return $y;
00286         if (false === $y) return $x;
00287         return min($x, $y);
00288     }

aliroAbstractDatabase::findMatchingQuote ( text,
quote 
) [private]

Definition at line 290 of file aliroDatabase.php.

Referenced by replacePrefix().

00290                                                        {
00291         $skip = 1;
00292         do {
00293             $endquote = $quote ? strpos($text, $quote, $skip) : strlen($text) - 1;
00294             if ($endquote) $skip = $endquote+1;
00295         }
00296         while ($endquote AND '\\' == $text[$endquote-1]);
00297         if ($endquote) return $endquote;
00298         else return strlen($text)-1;
00299     }

aliroAbstractDatabase::restoreOnePrefix ( tablename  ) 

Definition at line 301 of file aliroDatabase.php.

Referenced by getTableInfo().

00301                                                   {
00302         if (substr($tablename, 0, strlen($this->_table_prefix)) === $this->_table_prefix) return '#__'.substr($tablename, strlen($this->_table_prefix));
00303         else return $tablename;
00304     }

aliroAbstractDatabase::getQuery ( sql = ''  ) 

Definition at line 307 of file aliroDatabase.php.

00307                                        {
00308         if ($sql == '') $sql = $this->_sql;
00309         return "<pre>" . htmlspecialchars( $sql ) . "</pre>";
00310     }

aliroAbstractDatabase::query ( sql = ''  ) 

Definition at line 312 of file aliroDatabase.php.

References $stats, and aliroRequest::trace().

Referenced by doSQL(), getTableCreate(), and retrieveResults().

00312                                     {
00313         if (empty($sql)) $sql = $this->_sql;
00314         $timer = new aliroProfiler('Database timer');
00315         if ($this->_cursor = $this->interface->query($sql)) {
00316             $this->_errorNum = 0;
00317             $this->_errorMsg = '';
00318             $this->_log[] = htmlspecialchars($sql).'<br />'.$timer->mark('secs for query').'<br />'.aliroRequest::trace();
00319             $stats = new stdClass;
00320             $stats->timer = $timer->getElapsed();
00321             $stats->trace = aliroRequest::trace();
00322             $stats->sql = $sql;
00323             self::$stats[] = $stats;
00324             return $this->_cursor;
00325         }
00326         else {
00327             $this->_errorNum = $this->interface->errno();
00328             $this->_errorMsg = $this->interface->error()." SQL=$sql";
00329             throw new databaseException ($this->DBname, $this->_errorMsg, $this->_sql, $this->_errorNum, aliroRequest::trace());
00330         }
00331     }

aliroAbstractDatabase::doSQL ( sql  ) 

Definition at line 334 of file aliroDatabase.php.

References query(), and setQuery().

Referenced by addFieldIfMissing(), alterField(), doInsertion(), and doUpdate().

00334                                  {
00335         $this->setQuery($sql);
00336         return $this->query();
00337     }

aliroAbstractDatabase::doSQLget ( sql,
classname = 'stdClass',
key = '',
max = 0 
)

Definition at line 340 of file aliroDatabase.php.

References retrieveResults(), and setQuery().

Referenced by getTableFields(), and storeFields().

00340                                                                             {
00341         $this->setQuery($sql);
00342         $rows = $this->retrieveResults ($key, 0, 'object');
00343         if ('stdClass' == $classname) return $max ? array_slice($rows, 0, $max) : $rows;
00344         $result = array();
00345         foreach ($rows as $sub=>$row) {
00346             $next = new $classname();
00347             foreach (get_object_vars($row) as $field=>$value) $next->$field = $value;
00348             $result[$sub] = $next;
00349             if ($max AND count($result) >= $max) return $result;
00350         }
00351         return $result;
00352     }

aliroAbstractDatabase::query_batch (  ) 

Definition at line 354 of file aliroDatabase.php.

00354                                   {
00355         $this->_errorNum = 0;
00356         $this->_errorMsg = '';
00357         if ($this->interface->multiQuery($this->_sql)) {
00358             do $result = $this->interface->storeResult();
00359             while ($this->interface->nextResult());
00360         }
00361     }

aliroAbstractDatabase::getNumRows ( cur = null  ) 

Definition at line 363 of file aliroDatabase.php.

00363                                            {
00364         return $this->interface->getNumRows($cur);
00365     }

aliroAbstractDatabase::getAffectedRows (  ) 

Definition at line 367 of file aliroDatabase.php.

00367                                        {
00368         return $this->interface->getAffectedRows();
00369     }

aliroAbstractDatabase::retrieveResults ( key = '',
max = 0,
result_type = 'row' 
) [protected]

Definition at line 371 of file aliroDatabase.php.

References query().

Referenced by doSQLget(), loadAssocList(), loadObject(), loadObjectList(), loadResult(), loadResultArray(), loadRow(), and loadRowList().

00371                                                                              {
00372         $results = array();
00373         if (!in_array($result_type, array ('row', 'object', 'assoc'))) die ('unexpected result type='.$result_type);
00374         $sql_function = $this->interface->getFetchFunc().$result_type;
00375         if ($cur = $this->query()) {
00376             while ($row = $sql_function($cur)) {
00377                 if ($key != '') $results[(is_array($row) ? $row[$key] : $row->$key)] = $row;
00378                 else $results[] = $row;
00379                 if ($max AND count($results) >= $max) break;
00380             }
00381             $this->interface->freeResultSet($cur);
00382         }
00383         return $results;
00384     }

aliroAbstractDatabase::loadResult (  ) 

Definition at line 386 of file aliroDatabase.php.

References retrieveResults().

00386                                  {
00387         $results = $this->retrieveResults('', 1, 'row');
00388         if (count($results)) return $results[0][0];
00389         else return null;
00390     }

aliroAbstractDatabase::loadResultArray ( numinarray = 0  ) 

Definition at line 392 of file aliroDatabase.php.

References retrieveResults().

Referenced by getTableCreate(), getTableInfo(), and getTableList().

00392                                                      {
00393         $results = $this->retrieveResults('', 0, 'row');
00394         foreach ($results as $result) $values[] = $result[$numinarray];
00395         return isset($values) ? $values : null;
00396     }

aliroAbstractDatabase::loadAssocList ( key = ''  ) 

Definition at line 398 of file aliroDatabase.php.

References retrieveResults().

00398                                              {
00399         $results = $this->retrieveResults($key, 0, 'assoc');
00400         if (count($results)) return $results;
00401         else return null;
00402     }

aliroAbstractDatabase::mosBindArrayToObject ( array,
obj,
ignore = '',
prefix = NULL,
checkSlashes = true 
)

Definition at line 405 of file aliroDatabase.php.

References mosStripslashes().

00405                                                                                                        {
00406         if (!is_array($array) OR !is_object($obj)) return false;
00407         if ($prefix == null) $prefix = '';
00408         foreach (get_object_vars($obj) as $k => $v) {
00409             if( substr( $k, 0, 1 ) != '_' AND strpos($ignore, $k) === false) {
00410                 if (isset($array[$prefix.$k])) {
00411                     $obj->$k = ($checkSlashes AND get_magic_quotes_gpc()) ? $this->mosStripslashes( $array[$prefix.$k] ) : $array[$prefix.$k];
00412                 }
00413             }
00414         }
00415         return true;
00416     }

aliroAbstractDatabase::mosStripslashes ( value  ) 

Definition at line 419 of file aliroDatabase.php.

Referenced by mosBindArrayToObject().

00419                                             {
00420         if (is_string($value)) $ret = stripslashes($value);
00421         elseif (is_array($value)) {
00422             $ret = array();
00423             foreach ($value as $key=>$val) $ret[$key] = $this->mosStripslashes($val);
00424         }
00425         else $ret = $value;
00426         return $ret;
00427     } // mosStripSlashes

aliroAbstractDatabase::loadObject ( &$  object  ) 

Definition at line 430 of file aliroDatabase.php.

References retrieveResults().

00430                                          {
00431         if (!is_object($object)) $results = $this->retrieveResults('', 1, 'object');
00432         else $results = $this->retrieveResults('', 1, 'assoc');
00433         if (0 == count($results)) return false;
00434         if (!is_object($object)) $object = $results[0];
00435         else {
00436             if (is_subclass_of($object, 'aliroDBGeneralRow')) $object->bind($results[0], '', false);
00437             else foreach (get_object_vars($object) as $k => $v) {
00438                 if ($k[0] != '_' AND isset($results[0][$k])) $object->$k = $results[0][$k];
00439             }
00440         }
00441         return true;
00442     }

aliroAbstractDatabase::loadObjectList ( key = ''  ) 

Definition at line 444 of file aliroDatabase.php.

References retrieveResults().

00444                                               {
00445         $results = $this->retrieveResults($key, 0, 'object');
00446         if (count($results)) return $results;
00447         else return null;
00448     }

aliroAbstractDatabase::loadRow (  ) 

Definition at line 450 of file aliroDatabase.php.

References retrieveResults().

00450                               {
00451         $results = $this->retrieveResults('', 1, 'row');
00452         if (count($results)) return $results[0];
00453         else return null;
00454     }

aliroAbstractDatabase::loadRowList ( key = ''  ) 

Definition at line 456 of file aliroDatabase.php.

References retrieveResults().

00456                                            {
00457         $results = $this->retrieveResults($key, 0, 'row');
00458         if (count($results)) return $results;
00459         else return null;
00460     }

aliroAbstractDatabase::insertObject ( table,
object,
keyName = NULL 
)

Definition at line 462 of file aliroDatabase.php.

References doInsertion(), getAllFieldNames(), insertid(), setFieldValue(), T_(), and aliroRequest::trace().

00462                                                                   {
00463         $dbfields = $this->getAllFieldNames($table);
00464         foreach ($dbfields as $name) {
00465             if (!isset($object->$name) OR is_array($object->$name) OR is_object($object->$name)) continue;
00466             $fields[] = "`$name`";
00467             $values[] = $this->setFieldValue($object->$name);
00468         }
00469         if (isset($fields)) {
00470             $result = $this->doInsertion ($table, implode( ",", $fields ), implode( ",", $values ));
00471             // insertid() is only meaningful if non-zero
00472             $autoinc = $this->insertid();
00473             if ($autoinc AND $keyName AND !is_array($keyName)) $object->$keyName = $autoinc;
00474             return $result;
00475         }
00476         else {
00477             trigger_error (sprintf(T_('Insert into table %s but no fields'), $this->tableName));
00478             echo aliroRequest::trace();
00479             return false;
00480         }
00481     }

aliroAbstractDatabase::doInsertion ( table,
fields,
values 
) [private]

Definition at line 483 of file aliroDatabase.php.

References doSQL().

Referenced by insertObject().

00483                                                             {
00484         return $this->doSQL("INSERT INTO $table ($fields) VALUES ($values)");
00485     }

aliroAbstractDatabase::updateObject ( table,
object,
keyName,
updateNulls = true 
)

Definition at line 487 of file aliroDatabase.php.

References doUpdate(), getAllFieldNames(), setFieldValue(), and T_().

00487                                                                                 {
00488         $dbfields = $this->getAllFieldNames($table);
00489         foreach ($dbfields as $name) {
00490             if (!isset($object->$name) OR is_array($object->$name) OR is_object($object->$name)) {
00491                 if ($updateNulls) $value = "''";
00492                 else continue;
00493             }
00494             else $value = $this->setFieldValue($object->$name);
00495             $setter = "`$name` = $value";
00496             if (is_array($keyName) AND in_array($name, $keyName)) $where[] = $setter;
00497             elseif ($name == $keyName) $where[] = $setter;
00498             else $setters[] = $setter;
00499         }
00500         if (!isset($where)) {
00501             trigger_error (sprintf(T_('Update table %s but no key fields'), $table));
00502             return false;
00503         }
00504         if (isset($setters)) return $this->doUpdate ($table, implode (', ', $setters), implode (' AND ' , $where));
00505         return true;
00506     }

aliroAbstractDatabase::doUpdate ( table,
setters,
conditions 
) [private]

Definition at line 508 of file aliroDatabase.php.

References doSQL().

Referenced by updateObject().

00508                                                               {
00509         return $this->doSQL("UPDATE $table SET $setters WHERE $conditions");
00510     }

aliroAbstractDatabase::stderr ( showSQL = false  ) 

Definition at line 513 of file aliroDatabase.php.

00513                                                {
00514         return "DB function failed with error number $this->_errorNum"
00515         ."<br /><font color=\"red\">$this->_errorMsg</font>"
00516         .($showSQL ? "<br />SQL = <pre>$this->_sql</pre>" : '');
00517     }

aliroAbstractDatabase::insertid (  ) 

Definition at line 519 of file aliroDatabase.php.

Referenced by insertObject(), and saveStats().

00519                                {
00520         return $this->interface->insertid();
00521     }

aliroAbstractDatabase::getVersion (  ) 

Definition at line 523 of file aliroDatabase.php.

00524     {
00525         return $this->interface->getVersion();
00526     }

aliroAbstractDatabase::GenID (  ) 

Fudge method for ADOdb compatibility???? Not used in Aliro

Definition at line 531 of file aliroDatabase.php.

00531                              {
00532         return '0';
00533     }

aliroAbstractDatabase::getTableList (  ) 

Definition at line 537 of file aliroDatabase.php.

References loadResultArray(), and setQuery().

00537                                    {
00538         $this->setQuery('SHOW tables');
00539         return $this->loadResultArray();
00540     }

aliroAbstractDatabase::getTableCreate ( tables  ) 

Definition at line 543 of file aliroDatabase.php.

References loadResultArray(), query(), and setQuery().

00543                                               {
00544         $result = array();
00545 
00546         foreach ($tables as $tblval) {
00547             $this->setQuery( 'SHOW CREATE table ' . $tblval );
00548             $this->query();
00549             $result[$tblval] = $this->loadResultArray( 1 );
00550         }
00551 
00552         return $result;
00553     }

aliroAbstractDatabase::getTableFields ( tables  ) 

Definition at line 557 of file aliroDatabase.php.

References doSQLget().

00557                                               {
00558         $result = array();
00559 
00560         foreach ($tables as $tblval) {
00561             $fields = $this->doSQLget ( 'SHOW FIELDS FROM ' . $tblval );
00562             foreach ($fields as $field) {
00563                 $result[$tblval][$field->Field] = preg_replace("/[(0-9)]/",'', $field->Type );
00564             }
00565         }
00566 
00567         return $result;
00568     }

aliroAbstractDatabase::getCount (  ) 

Definition at line 570 of file aliroDatabase.php.

00570                                 {
00571         return count($this->_log);
00572     }

aliroAbstractDatabase::getLogged (  ) 

Definition at line 574 of file aliroDatabase.php.

00574                                  {
00575         $text = '<h4>'.$this->getCount().' queries executed</h4>';
00576         foreach ($this->_log as $k=>$sql) $text .= "\n".($k+1)."<br />".$sql.'<hr />';
00577         if (count($this->_log)) return $text;
00578         else return '';
00579     }

aliroAbstractDatabase::saveStats (  )  [private]

Definition at line 581 of file aliroDatabase.php.

References $stats, getEscaped(), aliroCoreDatabase::getInstance(), aliro::getInstance(), and insertid().

Referenced by __destruct().

00581                                   {
00582         new aliroObjectSorter(self::$stats, 'timer');
00583         $n = count(self::$stats);
00584         if ($n > 0) {
00585             $median = self::$stats[intval($n/2)]->timer;
00586             $total = 0.0;
00587             foreach (self::$stats as $stat) $total += $stat->timer;
00588             $mean = $total/$n;
00589             $var = 0.0;
00590             foreach (self::$stats as $stat) $var += ($stat->timer - $mean) * ($stat->timer - $mean);
00591             $stdev = sqrt($var);
00592             $best = self::$stats[0]->timer;
00593             $worst = self::$stats[$n-1]->timer;
00594             $elapsed = aliro::getInstance()->getElapsed();
00595             $memory = memory_get_usage();
00596             $uri = htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES, 'UTF-8');
00597             aliroCoreDatabase::getInstance()->doSQL("INSERT INTO #__query_stats (count, mean, median, stdev, best, worst, total, elapsed, memory, uri) VALUES ($n, '$mean', '$median', '$stdev', '$best', '$worst', '$total', '$elapsed', '$memory', '$uri')");
00598             $queryid = $this->insertid();
00599             $stats = self::$stats;
00600             foreach ($stats as $stat) {
00601                 if (0.50 < $stat->timer) {
00602                     $querytext = htmlspecialchars($stat->sql, ENT_QUOTES);
00603                     $tracetext = $this->getEscaped($stat->trace, ENT_QUOTES);
00604                     $sql = "INSERT INTO {$this->_table_prefix}query_slow (queryid, time, trace, querytext) VALUES ($queryid, '$stat->timer', '$tracetext', '$querytext')";
00605                     $this->interface->query($sql);
00606                 }
00607             }
00608         }
00609         self::$stats = array();
00610     }


Member Data Documentation

aliroAbstractDatabase::$stats = array() [static, protected]

Definition at line 100 of file aliroDatabase.php.

Referenced by query(), and saveStats().

aliroAbstractDatabase::$_sql = '' [protected]

Definition at line 101 of file aliroDatabase.php.

aliroAbstractDatabase::$_cached = false [protected]

Definition at line 102 of file aliroDatabase.php.

aliroAbstractDatabase::$_errorNum = 0 [protected]

Definition at line 103 of file aliroDatabase.php.

aliroAbstractDatabase::$_errorMsg = '' [protected]

Definition at line 104 of file aliroDatabase.php.

aliroAbstractDatabase::$_table_prefix = '' [protected]

Definition at line 105 of file aliroDatabase.php.

aliroAbstractDatabase::$_resource = '' [protected]

Definition at line 106 of file aliroDatabase.php.

aliroAbstractDatabase::$_cursor = null [protected]

Definition at line 107 of file aliroDatabase.php.

aliroAbstractDatabase::$_log = array() [protected]

Definition at line 108 of file aliroDatabase.php.

aliroAbstractDatabase::$DBname = '' [protected]

Definition at line 109 of file aliroDatabase.php.

aliroAbstractDatabase::$DBInfo = null [protected]

Definition at line 110 of file aliroDatabase.php.

aliroAbstractDatabase::$cache = null [protected]

Definition at line 111 of file aliroDatabase.php.

aliroAbstractDatabase::$interface = null [protected]

Definition at line 112 of file aliroDatabase.php.


The documentation for this class was generated from the following file:

Generated on Thu Apr 17 13:03:28 2008 for ALIRO by  doxygen 1.5.5