";
}
//****************************************************************************
// displayUserSection -- displays the user section
//****************************************************************************
function displayUserSection()
{
global $cfg, $db;
echo "
";
?>
qstr($user_id);
list($user_id, $hits, $last_visit, $time_created, $user_level, $hide_offline, $theme, $language_file) = $db->GetRow($sql);
$user_type = _NORMALUSER;
if ($user_level == 1)
{
$user_type = _ADMINISTRATOR;
$selected_n = "";
$selected_a = "selected";
$editUserImage = "images/admin_user.gif";
}
if ($user_level >= 2)
{
$user_type = _SUPERADMIN;
$editUserImage = "images/superadmin.gif";
}
if ($hide_offline == 1)
{
$hide_checked = "checked";
}
$user_activity = GetActivityCount($user_id);
if ($user_activity == 0)
{
$user_percent = 0;
}
else
{
$user_percent = number_format(($user_activity/$total_activity)*100);
}
echo "
";
DisplayFoot();
}
//****************************************************************************
// CreateUser -- Create a user
//****************************************************************************
function CreateUser()
{
global $cfg;
DisplayHead(_USERADMIN);
// Admin Menu
displayMenu();
echo "
";
DisplayFoot();
}
//****************************************************************************
// editLinks -- Edit Links
//****************************************************************************
function editLinks()
{
global $cfg;
DisplayHead(_ADMINEDITLINKS);
// Admin Menu
displayMenu();
echo "
";
DisplayFoot();
}
//****************************************************************************
// editRSS -- Edit RSS Feeds
//****************************************************************************
function editRSS()
{
global $cfg;
DisplayHead("Administration - RSS");
// Admin Menu
displayMenu();
echo "
";
DisplayFoot();
}
//****************************************************************************
// editAllow -- displayed IPSec Rules
//****************************************************************************
function editAllow()
{
Global $cfg;
DisplayHead("Administration - IP Security");
// Admin menu
displayMenu();
echo "
";
DisplayFoot();
}
//****************************************************************************
//****************************************************************************
//****************************************************************************
//****************************************************************************
// TRAFFIC CONTROLER
switch ($op) {
default:
showIndex($min);
break;
case "showUserActivity":
showUserActivity($min, $user_id, $srchFile, $srchAction);
break;
case "xfer":
displayXfer();
break;
case "backupDatabase":
backupDatabase();
break;
case "editRSS":
editRSS();
break;
case "addRSS":
addRSS($newRSS);
break;
case "deleteRSS":
deleteRSS($rid);
break;
case "editLink":
editLink($lid,$editLink,$editSite);
break;
case "editLinks":
editLinks();
break;
case "addLink":
addLink($newLink,$newSite);
break;
case "deleteLink":
deleteLink($lid);
break;
case "CreateUser":
CreateUser();
break;
case "addUser":
addUser($newUser, $pass1, $userType);
break;
case "deleteUser":
deleteUser($user_id);
break;
case "editUser":
editUser($user_id);
break;
case "updateUser":
updateUser($user_id, $org_user_id, $pass1, $userType, $hideOffline);
break;
case "config":
config();
break;
case "ipsec":
editAllow();
break;
case "addAllow":
addAllow($ip);
break;
case "deleteAllow":
deleteAllow($aid);
break;
}
//****************************************************************************
//****************************************************************************
//****************************************************************************
//****************************************************************************
?> Neuinstallation/HTML_Code/adodb/adodb-csvlib.inc.php 0100444 0000002 0000002 00000020413 10330414136 0021304 0 ustar root root FieldCount() : 0;
if ($sql) $sql = urlencode($sql);
// metadata setup
if ($max <= 0 || $rs->dataProvider == 'empty') { // is insert/update/delete
if (is_object($conn)) {
$sql .= ','.$conn->Affected_Rows();
$sql .= ','.$conn->Insert_ID();
} else
$sql .= ',,';
$text = "====-1,0,$sql\n";
return $text;
}
$tt = ($rs->timeCreated) ? $rs->timeCreated : time();
## changed format from ====0 to ====1
$line = "====1,$tt,$sql\n";
if ($rs->databaseType == 'array') {
$rows =& $rs->_array;
} else {
$rows = array();
while (!$rs->EOF) {
$rows[] = $rs->fields;
$rs->MoveNext();
}
}
for($i=0; $i < $max; $i++) {
$o =& $rs->FetchField($i);
$flds[] = $o;
}
$savefetch = isset($rs->adodbFetchMode) ? $rs->adodbFetchMode : $rs->fetchMode;
$rs =& new ADORecordSet_array();
$rs->InitArrayFields($rows,$flds);
$rs->fetchMode = $savefetch;
return $line.serialize($rs);
}
/**
* Open CSV file and convert it into Data.
*
* @param url file/ftp/http url
* @param err returns the error message
* @param timeout dispose if recordset has been alive for $timeout secs
*
* @return recordset, or false if error occured. If no
* error occurred in sql INSERT/UPDATE/DELETE,
* empty recordset is returned
*/
function &csv2rs($url,&$err,$timeout=0)
{
$err = false;
$fp = @fopen($url,'rb');
if (!$fp) {
$err = $url.' file/URL not found';
return false;
}
flock($fp, LOCK_SH);
$arr = array();
$ttl = 0;
if ($meta = fgetcsv($fp, 32000, ",")) {
// check if error message
if (strncmp($meta[0],'****',4) === 0) {
$err = trim(substr($meta[0],4,1024));
fclose($fp);
return false;
}
// check for meta data
// $meta[0] is -1 means return an empty recordset
// $meta[1] contains a time
if (strncmp($meta[0], '====',4) === 0) {
if ($meta[0] == "====-1") {
if (sizeof($meta) < 5) {
$err = "Corrupt first line for format -1";
fclose($fp);
return false;
}
fclose($fp);
if ($timeout > 0) {
$err = " Illegal Timeout $timeout ";
return false;
}
$rs->fields = array();
$rs->timeCreated = $meta[1];
$rs =& new ADORecordSet($val=true);
$rs->EOF = true;
$rs->_numOfFields=0;
$rs->sql = urldecode($meta[2]);
$rs->affectedrows = (integer)$meta[3];
$rs->insertid = $meta[4];
return $rs;
}
# Under high volume loads, we want only 1 thread/process to _write_file
# so that we don't have 50 processes queueing to write the same data.
# We use probabilistic timeout, ahead of time.
#
# -4 sec before timeout, give processes 1/32 chance of timing out
# -2 sec before timeout, give processes 1/16 chance of timing out
# -1 sec after timeout give processes 1/4 chance of timing out
# +0 sec after timeout, give processes 100% chance of timing out
if (sizeof($meta) > 1) {
if($timeout >0){
$tdiff = (integer)( $meta[1]+$timeout - time());
if ($tdiff <= 2) {
switch($tdiff) {
case 4:
case 3:
if ((rand() & 31) == 0) {
fclose($fp);
$err = "Timeout 3";
return false;
}
break;
case 2:
if ((rand() & 15) == 0) {
fclose($fp);
$err = "Timeout 2";
return false;
}
break;
case 1:
if ((rand() & 3) == 0) {
fclose($fp);
$err = "Timeout 1";
return false;
}
break;
default:
fclose($fp);
$err = "Timeout 0";
return false;
} // switch
} // if check flush cache
}// (timeout>0)
$ttl = $meta[1];
}
//================================================
// new cache format - use serialize extensively...
if ($meta[0] === '====1') {
// slurp in the data
$MAXSIZE = 128000;
$text = fread($fp,$MAXSIZE);
if (strlen($text)) {
while ($txt = fread($fp,$MAXSIZE)) {
$text .= $txt;
}
}
fclose($fp);
$rs = unserialize($text);
if (is_object($rs)) $rs->timeCreated = $ttl;
else {
$err = "Unable to unserialize recordset";
//echo htmlspecialchars($text),' !--END--!
';
}
return $rs;
}
$meta = false;
$meta = fgetcsv($fp, 32000, ",");
if (!$meta) {
fclose($fp);
$err = "Unexpected EOF 1";
return false;
}
}
// Get Column definitions
$flds = array();
foreach($meta as $o) {
$o2 = explode(':',$o);
if (sizeof($o2)!=3) {
$arr[] = $meta;
$flds = false;
break;
}
$fld =& new ADOFieldObject();
$fld->name = urldecode($o2[0]);
$fld->type = $o2[1];
$fld->max_length = $o2[2];
$flds[] = $fld;
}
} else {
fclose($fp);
$err = "Recordset had unexpected EOF 2";
return false;
}
// slurp in the data
$MAXSIZE = 128000;
$text = '';
while ($txt = fread($fp,$MAXSIZE)) {
$text .= $txt;
}
fclose($fp);
@$arr = unserialize($text);
//var_dump($arr);
if (!is_array($arr)) {
$err = "Recordset had unexpected EOF (in serialized recordset)";
if (get_magic_quotes_runtime()) $err .= ". Magic Quotes Runtime should be disabled!";
return false;
}
$rs =& new ADORecordSet_array();
$rs->timeCreated = $ttl;
$rs->InitArrayFields($arr,$flds);
return $rs;
}
/**
* Save a file $filename and its $contents (normally for caching) with file locking
*/
function adodb_write_file($filename, $contents,$debug=false)
{
# http://www.php.net/bugs.php?id=9203 Bug that flock fails on Windows
# So to simulate locking, we assume that rename is an atomic operation.
# First we delete $filename, then we create a $tempfile write to it and
# rename to the desired $filename. If the rename works, then we successfully
# modified the file exclusively.
# What a stupid need - having to simulate locking.
# Risks:
# 1. $tempfile name is not unique -- very very low
# 2. unlink($filename) fails -- ok, rename will fail
# 3. adodb reads stale file because unlink fails -- ok, $rs timeout occurs
# 4. another process creates $filename between unlink() and rename() -- ok, rename() fails and cache updated
if (strncmp(PHP_OS,'WIN',3) === 0) {
// skip the decimal place
$mtime = substr(str_replace(' ','_',microtime()),2);
// getmypid() actually returns 0 on Win98 - never mind!
$tmpname = $filename.uniqid($mtime).getmypid();
if (!($fd = fopen($tmpname,'a'))) return false;
$ok = ftruncate($fd,0);
if (!fwrite($fd,$contents)) $ok = false;
fclose($fd);
chmod($tmpname,0644);
// the tricky moment
@unlink($filename);
if (!@rename($tmpname,$filename)) {
unlink($tmpname);
$ok = false;
}
if (!$ok) {
if ($debug) ADOConnection::outp( " Rename $tmpname ".($ok? 'ok' : 'failed'));
}
return $ok;
}
if (!($fd = fopen($filename, 'a'))) return false;
if (flock($fd, LOCK_EX) && ftruncate($fd, 0)) {
$ok = fwrite( $fd, $contents );
fclose($fd);
chmod($filename,0644);
}else {
fclose($fd);
if ($debug)ADOConnection::outp( " Failed acquiring lock for $filename
\n");
$ok = false;
}
return $ok;
}
?> Neuinstallation/HTML_Code/adodb/adodb-datadict.inc.php 0100444 0000002 0000002 00000047441 10330414136 0021611 0 ustar root root $str
";
}
if (!function_exists('ctype_alnum')) {
function ctype_alnum($text) {
return preg_match('/^[a-z0-9]*$/i', $text);
}
}
//Lens_ParseTest();
/**
Parse arguments, treat "text" (text) and 'text' as quotation marks.
To escape, use "" or '' or ))
Will read in "abc def" sans quotes, as: abc def
Same with 'abc def'.
However if `abc def`, then will read in as `abc def`
@param endstmtchar Character that indicates end of statement
@param tokenchars Include the following characters in tokens apart from A-Z and 0-9
@returns 2 dimensional array containing parsed tokens.
*/
function Lens_ParseArgs($args,$endstmtchar=',',$tokenchars='_.-')
{
$pos = 0;
$intoken = false;
$stmtno = 0;
$endquote = false;
$tokens = array();
$tokens[$stmtno] = array();
$max = strlen($args);
$quoted = false;
while ($pos < $max) {
$ch = substr($args,$pos,1);
switch($ch) {
case ' ':
case "\t":
case "\n":
case "\r":
if (!$quoted) {
if ($intoken) {
$intoken = false;
$tokens[$stmtno][] = implode('',$tokarr);
}
break;
}
$tokarr[] = $ch;
break;
case '`':
if ($intoken) $tokarr[] = $ch;
case '(':
case ')':
case '"':
case "'":
if ($intoken) {
if (empty($endquote)) {
$tokens[$stmtno][] = implode('',$tokarr);
if ($ch == '(') $endquote = ')';
else $endquote = $ch;
$quoted = true;
$intoken = true;
$tokarr = array();
} else if ($endquote == $ch) {
$ch2 = substr($args,$pos+1,1);
if ($ch2 == $endquote) {
$pos += 1;
$tokarr[] = $ch2;
} else {
$quoted = false;
$intoken = false;
$tokens[$stmtno][] = implode('',$tokarr);
$endquote = '';
}
} else
$tokarr[] = $ch;
}else {
if ($ch == '(') $endquote = ')';
else $endquote = $ch;
$quoted = true;
$intoken = true;
$tokarr = array();
if ($ch == '`') $tokarr[] = '`';
}
break;
default:
if (!$intoken) {
if ($ch == $endstmtchar) {
$stmtno += 1;
$tokens[$stmtno] = array();
break;
}
$intoken = true;
$quoted = false;
$endquote = false;
$tokarr = array();
}
if ($quoted) $tokarr[] = $ch;
else if (ctype_alnum($ch) || strpos($tokenchars,$ch) !== false) $tokarr[] = $ch;
else {
if ($ch == $endstmtchar) {
$tokens[$stmtno][] = implode('',$tokarr);
$stmtno += 1;
$tokens[$stmtno] = array();
$intoken = false;
$tokarr = array();
break;
}
$tokens[$stmtno][] = implode('',$tokarr);
$tokens[$stmtno][] = $ch;
$intoken = false;
}
}
$pos += 1;
}
if ($intoken) $tokens[$stmtno][] = implode('',$tokarr);
return $tokens;
}
class ADODB_DataDict {
var $connection;
var $debug = false;
var $dropTable = 'DROP TABLE %s';
var $renameTable = 'RENAME TABLE %s TO %s';
var $dropIndex = 'DROP INDEX %s';
var $addCol = ' ADD';
var $alterCol = ' ALTER COLUMN';
var $dropCol = ' DROP COLUMN';
var $renameColumn = 'ALTER TABLE %s RENAME COLUMN %s TO %s'; // table, old-column, new-column, column-definitions (not used by default)
var $nameRegex = '\w';
var $schema = false;
var $serverInfo = array();
var $autoIncrement = false;
var $dataProvider;
var $invalidResizeTypes4 = array('CLOB','BLOB','TEXT','DATE','TIME'); // for changetablesql
var $blobSize = 100; /// any varchar/char field this size or greater is treated as a blob
/// in other words, we use a text area for editting.
function GetCommentSQL($table,$col)
{
return false;
}
function SetCommentSQL($table,$col,$cmt)
{
return false;
}
function &MetaTables()
{
if (!$this->connection->IsConnected()) return array();
return $this->connection->MetaTables();
}
function &MetaColumns($tab, $upper=true, $schema=false)
{
if (!$this->connection->IsConnected()) return array();
return $this->connection->MetaColumns($this->TableName($tab), $upper, $schema);
}
function &MetaPrimaryKeys($tab,$owner=false,$intkey=false)
{
if (!$this->connection->IsConnected()) return array();
return $this->connection->MetaPrimaryKeys($this->TableName($tab), $owner, $intkey);
}
function &MetaIndexes($table, $primary = false, $owner = false)
{
if (!$this->connection->IsConnected()) return array();
return $this->connection->MetaIndexes($this->TableName($table), $primary, $owner);
}
function MetaType($t,$len=-1,$fieldobj=false)
{
return ADORecordSet::MetaType($t,$len,$fieldobj);
}
function NameQuote($name = NULL)
{
if (!is_string($name)) {
return FALSE;
}
$name = trim($name);
if ( !is_object($this->connection) ) {
return $name;
}
$quote = $this->connection->nameQuote;
// if name is of the form `name`, quote it
if ( preg_match('/^`(.+)`$/', $name, $matches) ) {
return $quote . $matches[1] . $quote;
}
// if name contains special characters, quote it
if ( !preg_match('/^[' . $this->nameRegex . ']+$/', $name) ) {
return $quote . $name . $quote;
}
return $name;
}
function TableName($name)
{
if ( $this->schema ) {
return $this->NameQuote($this->schema) .'.'. $this->NameQuote($name);
}
return $this->NameQuote($name);
}
// Executes the sql array returned by GetTableSQL and GetIndexSQL
function ExecuteSQLArray($sql, $continueOnError = true)
{
$rez = 2;
$conn = &$this->connection;
$saved = $conn->debug;
foreach($sql as $line) {
if ($this->debug) $conn->debug = true;
$ok = $conn->Execute($line);
$conn->debug = $saved;
if (!$ok) {
if ($this->debug) ADOConnection::outp($conn->ErrorMsg());
if (!$continueOnError) return 0;
$rez = 1;
}
}
return $rez;
}
/*
Returns the actual type given a character code.
C: varchar
X: CLOB (character large object) or largest varchar size if CLOB is not supported
C2: Multibyte varchar
X2: Multibyte CLOB
B: BLOB (binary large object)
D: Date
T: Date-time
L: Integer field suitable for storing booleans (0 or 1)
I: Integer
F: Floating point number
N: Numeric or decimal number
*/
function ActualType($meta)
{
return $meta;
}
function CreateDatabase($dbname,$options=false)
{
$options = $this->_Options($options);
$sql = array();
$s = 'CREATE DATABASE ' . $this->NameQuote($dbname);
if (isset($options[$this->upperName]))
$s .= ' '.$options[$this->upperName];
$sql[] = $s;
return $sql;
}
/*
Generates the SQL to create index. Returns an array of sql strings.
*/
function CreateIndexSQL($idxname, $tabname, $flds, $idxoptions = false)
{
if (!is_array($flds)) {
$flds = explode(',',$flds);
}
foreach($flds as $key => $fld) {
$flds[$key] = $this->NameQuote($fld);
}
return $this->_IndexSQL($this->NameQuote($idxname), $this->TableName($tabname), $flds, $this->_Options($idxoptions));
}
function DropIndexSQL ($idxname, $tabname = NULL)
{
return array(sprintf($this->dropIndex, $this->NameQuote($idxname), $this->TableName($tabname)));
}
function SetSchema($schema)
{
$this->schema = $schema;
}
function AddColumnSQL($tabname, $flds)
{
$tabname = $this->TableName ($tabname);
$sql = array();
list($lines,$pkey) = $this->_GenFields($flds);
$alter = 'ALTER TABLE ' . $tabname . $this->addCol . ' ';
foreach($lines as $v) {
$sql[] = $alter . $v;
}
return $sql;
}
/**
* Change the definition of one column
*
* As some DBM's can't do that on there own, you need to supply the complete defintion of the new table,
* to allow, recreating the table and copying the content over to the new table
* @param string $tabname table-name
* @param string $flds column-name and type for the changed column
* @param string $tableflds='' complete defintion of the new table, eg. for postgres, default ''
* @param array/string $tableoptions='' options for the new table see CreateTableSQL, default ''
* @return array with SQL strings
*/
function AlterColumnSQL($tabname, $flds, $tableflds='',$tableoptions='')
{
$tabname = $this->TableName ($tabname);
$sql = array();
list($lines,$pkey) = $this->_GenFields($flds);
$alter = 'ALTER TABLE ' . $tabname . $this->alterCol . ' ';
foreach($lines as $v) {
$sql[] = $alter . $v;
}
return $sql;
}
/**
* Rename one column
*
* Some DBM's can only do this together with changeing the type of the column (even if that stays the same, eg. mysql)
* @param string $tabname table-name
* @param string $oldcolumn column-name to be renamed
* @param string $newcolumn new column-name
* @param string $flds='' complete column-defintion-string like for AddColumnSQL, only used by mysql atm., default=''
* @return array with SQL strings
*/
function RenameColumnSQL($tabname,$oldcolumn,$newcolumn,$flds='')
{
$tabname = $this->TableName ($tabname);
if ($flds) {
list($lines,$pkey) = $this->_GenFields($flds);
list(,$first) = each($lines);
list(,$column_def) = split("[\t ]+",$first,2);
}
return array(sprintf($this->renameColumn,$tabname,$this->NameQuote($oldcolumn),$this->NameQuote($newcolumn),$column_def));
}
/**
* Drop one column
*
* Some DBM's can't do that on there own, you need to supply the complete defintion of the new table,
* to allow, recreating the table and copying the content over to the new table
* @param string $tabname table-name
* @param string $flds column-name and type for the changed column
* @param string $tableflds='' complete defintion of the new table, eg. for postgres, default ''
* @param array/string $tableoptions='' options for the new table see CreateTableSQL, default ''
* @return array with SQL strings
*/
function DropColumnSQL($tabname, $flds, $tableflds='',$tableoptions='')
{
$tabname = $this->TableName ($tabname);
if (!is_array($flds)) $flds = explode(',',$flds);
$sql = array();
$alter = 'ALTER TABLE ' . $tabname . $this->dropCol . ' ';
foreach($flds as $v) {
$sql[] = $alter . $this->NameQuote($v);
}
return $sql;
}
function DropTableSQL($tabname)
{
return array (sprintf($this->dropTable, $this->TableName($tabname)));
}
function RenameTableSQL($tabname,$newname)
{
return array (sprintf($this->renameTable, $this->TableName($tabname),$this->TableName($newname)));
}
/*
Generate the SQL to create table. Returns an array of sql strings.
*/
function CreateTableSQL($tabname, $flds, $tableoptions=false)
{
if (!$tableoptions) $tableoptions = array();
list($lines,$pkey) = $this->_GenFields($flds, true);
$taboptions = $this->_Options($tableoptions);
$tabname = $this->TableName ($tabname);
$sql = $this->_TableSQL($tabname,$lines,$pkey,$taboptions);
$tsql = $this->_Triggers($tabname,$taboptions);
foreach($tsql as $s) $sql[] = $s;
return $sql;
}
function _GenFields($flds,$widespacing=false)
{
if (is_string($flds)) {
$padding = ' ';
$txt = $flds.$padding;
$flds = array();
$flds0 = Lens_ParseArgs($txt,',');
$hasparam = false;
foreach($flds0 as $f0) {
$f1 = array();
foreach($f0 as $token) {
switch (strtoupper($token)) {
case 'CONSTRAINT':
case 'DEFAULT':
$hasparam = $token;
break;
default:
if ($hasparam) $f1[$hasparam] = $token;
else $f1[] = $token;
$hasparam = false;
break;
}
}
$flds[] = $f1;
}
}
$this->autoIncrement = false;
$lines = array();
$pkey = array();
foreach($flds as $fld) {
$fld = _array_change_key_case($fld);
$fname = false;
$fdefault = false;
$fautoinc = false;
$ftype = false;
$fsize = false;
$fprec = false;
$fprimary = false;
$fnoquote = false;
$fdefts = false;
$fdefdate = false;
$fconstraint = false;
$fnotnull = false;
$funsigned = false;
//-----------------
// Parse attributes
foreach($fld as $attr => $v) {
if ($attr == 2 && is_numeric($v)) $attr = 'SIZE';
else if (is_numeric($attr) && $attr > 1 && !is_numeric($v)) $attr = strtoupper($v);
switch($attr) {
case '0':
case 'NAME': $fname = $v; break;
case '1':
case 'TYPE': $ty = $v; $ftype = $this->ActualType(strtoupper($v)); break;
case 'SIZE':
$dotat = strpos($v,'.'); if ($dotat === false) $dotat = strpos($v,',');
if ($dotat === false) $fsize = $v;
else {
$fsize = substr($v,0,$dotat);
$fprec = substr($v,$dotat+1);
}
break;
case 'UNSIGNED': $funsigned = true; break;
case 'AUTOINCREMENT':
case 'AUTO': $fautoinc = true; $fnotnull = true; break;
case 'KEY':
case 'PRIMARY': $fprimary = $v; $fnotnull = true; break;
case 'DEF':
case 'DEFAULT': $fdefault = $v; break;
case 'NOTNULL': $fnotnull = $v; break;
case 'NOQUOTE': $fnoquote = $v; break;
case 'DEFDATE': $fdefdate = $v; break;
case 'DEFTIMESTAMP': $fdefts = $v; break;
case 'CONSTRAINT': $fconstraint = $v; break;
} //switch
} // foreach $fld
//--------------------
// VALIDATE FIELD INFO
if (!strlen($fname)) {
if ($this->debug) ADOConnection::outp("Undefined NAME");
return false;
}
$fid = strtoupper(preg_replace('/^`(.+)`$/', '$1', $fname));
$fname = $this->NameQuote($fname);
if (!strlen($ftype)) {
if ($this->debug) ADOConnection::outp("Undefined TYPE for field '$fname'");
return false;
} else {
$ftype = strtoupper($ftype);
}
$ftype = $this->_GetSize($ftype, $ty, $fsize, $fprec);
if ($ty == 'X' || $ty == 'X2' || $ty == 'B') $fnotnull = false; // some blob types do not accept nulls
if ($fprimary) $pkey[] = $fname;
// some databases do not allow blobs to have defaults
if ($ty == 'X') $fdefault = false;
//--------------------
// CONSTRUCT FIELD SQL
if ($fdefts) {
if (substr($this->connection->databaseType,0,5) == 'mysql') {
$ftype = 'TIMESTAMP';
} else {
$fdefault = $this->connection->sysTimeStamp;
}
} else if ($fdefdate) {
if (substr($this->connection->databaseType,0,5) == 'mysql') {
$ftype = 'TIMESTAMP';
} else {
$fdefault = $this->connection->sysDate;
}
} else if (strlen($fdefault) && !$fnoquote)
if ($ty == 'C' or $ty == 'X' or
( substr($fdefault,0,1) != "'" && !is_numeric($fdefault)))
if (strlen($fdefault) != 1 && substr($fdefault,0,1) == ' ' && substr($fdefault,strlen($fdefault)-1) == ' ')
$fdefault = trim($fdefault);
else if (strtolower($fdefault) != 'null')
$fdefault = $this->connection->qstr($fdefault);
$suffix = $this->_CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned);
if ($widespacing) $fname = str_pad($fname,24);
$lines[$fid] = $fname.' '.$ftype.$suffix;
if ($fautoinc) $this->autoIncrement = true;
} // foreach $flds
return array($lines,$pkey);
}
/*
GENERATE THE SIZE PART OF THE DATATYPE
$ftype is the actual type
$ty is the type defined originally in the DDL
*/
function _GetSize($ftype, $ty, $fsize, $fprec)
{
if (strlen($fsize) && $ty != 'X' && $ty != 'B' && strpos($ftype,'(') === false) {
$ftype .= "(".$fsize;
if (strlen($fprec)) $ftype .= ",".$fprec;
$ftype .= ')';
}
return $ftype;
}
// return string must begin with space
function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint)
{
$suffix = '';
if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
if ($fnotnull) $suffix .= ' NOT NULL';
if ($fconstraint) $suffix .= ' '.$fconstraint;
return $suffix;
}
function _IndexSQL($idxname, $tabname, $flds, $idxoptions)
{
$sql = array();
if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) {
$sql[] = sprintf ($this->dropIndex, $idxname);
if ( isset($idxoptions['DROP']) )
return $sql;
}
if ( empty ($flds) ) {
return $sql;
}
$unique = isset($idxoptions['UNIQUE']) ? ' UNIQUE' : '';
$s = 'CREATE' . $unique . ' INDEX ' . $idxname . ' ON ' . $tabname . ' ';
if ( isset($idxoptions[$this->upperName]) )
$s .= $idxoptions[$this->upperName];
if ( is_array($flds) )
$flds = implode(', ',$flds);
$s .= '(' . $flds . ')';
$sql[] = $s;
return $sql;
}
function _DropAutoIncrement($tabname)
{
return false;
}
function _TableSQL($tabname,$lines,$pkey,$tableoptions)
{
$sql = array();
if (isset($tableoptions['REPLACE']) || isset ($tableoptions['DROP'])) {
$sql[] = sprintf($this->dropTable,$tabname);
if ($this->autoIncrement) {
$sInc = $this->_DropAutoIncrement($tabname);
if ($sInc) $sql[] = $sInc;
}
if ( isset ($tableoptions['DROP']) ) {
return $sql;
}
}
$s = "CREATE TABLE $tabname (\n";
$s .= implode(",\n", $lines);
if (sizeof($pkey)>0) {
$s .= ",\n PRIMARY KEY (";
$s .= implode(", ",$pkey).")";
}
if (isset($tableoptions['CONSTRAINTS']))
$s .= "\n".$tableoptions['CONSTRAINTS'];
if (isset($tableoptions[$this->upperName.'_CONSTRAINTS']))
$s .= "\n".$tableoptions[$this->upperName.'_CONSTRAINTS'];
$s .= "\n)";
if (isset($tableoptions[$this->upperName])) $s .= $tableoptions[$this->upperName];
$sql[] = $s;
return $sql;
}
/*
GENERATE TRIGGERS IF NEEDED
used when table has auto-incrementing field that is emulated using triggers
*/
function _Triggers($tabname,$taboptions)
{
return array();
}
/*
Sanitize options, so that array elements with no keys are promoted to keys
*/
function _Options($opts)
{
if (!is_array($opts)) return array();
$newopts = array();
foreach($opts as $k => $v) {
if (is_numeric($k)) $newopts[strtoupper($v)] = $v;
else $newopts[strtoupper($k)] = $v;
}
return $newopts;
}
/*
"Florian Buzin [ easywe ]"
This function changes/adds new fields to your table. You don't
have to know if the col is new or not. It will check on its own.
*/
function ChangeTableSQL($tablename, $flds, $tableoptions = false)
{
// check table exists
$cols = &$this->MetaColumns($tablename);
if ( empty($cols)) {
return $this->CreateTableSQL($tablename, $flds, $tableoptions);
}
// already exists, alter table instead
list($lines,$pkey) = $this->_GenFields($flds);
$alter = 'ALTER TABLE ' . $this->TableName($tablename);
foreach ( $lines as $id => $v ) {
if ( isset($cols[$id]) && is_object($cols[$id]) ) {
$flds = Lens_ParseArgs($v,',');
// We are trying to change the size of the field, if not allowed, simply ignore the request.
if ($flds && in_array(strtoupper(substr($flds[0][1],0,4)),$this->invalidResizeTypes4)) continue;
$sql[] = $alter . $this->alterCol . ' ' . $v;
} else {
$sql[] = $alter . $this->addCol . ' ' . $v;
}
}
return $sql;
}
} // class
?> Neuinstallation/HTML_Code/adodb/adodb-error.inc.php 0100444 0000002 0000002 00000021071 10330414140 0021147 0 ustar root root DB_ERROR_NOSUCHTABLE,
'/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*/' => DB_ERROR_ALREADY_EXISTS,
'/divide by zero$/' => DB_ERROR_DIVZERO,
'/pg_atoi: error in .*: can\'t parse /' => DB_ERROR_INVALID_NUMBER,
'/ttribute [\"\'].*[\"\'] not found|Relation [\"\'].*[\"\'] does not have attribute [\"\'].*[\"\']/' => DB_ERROR_NOSUCHFIELD,
'/parser: parse error at or near \"/' => DB_ERROR_SYNTAX,
'/referential integrity violation/' => DB_ERROR_CONSTRAINT,
'/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*|duplicate key violates unique constraint/'
=> DB_ERROR_ALREADY_EXISTS
);
reset($error_regexps);
while (list($regexp,$code) = each($error_regexps)) {
if (preg_match($regexp, $errormsg)) {
return $code;
}
}
// Fall back to DB_ERROR if there was no mapping.
return DB_ERROR;
}
function adodb_error_odbc()
{
static $MAP = array(
'01004' => DB_ERROR_TRUNCATED,
'07001' => DB_ERROR_MISMATCH,
'21S01' => DB_ERROR_MISMATCH,
'21S02' => DB_ERROR_MISMATCH,
'22003' => DB_ERROR_INVALID_NUMBER,
'22008' => DB_ERROR_INVALID_DATE,
'22012' => DB_ERROR_DIVZERO,
'23000' => DB_ERROR_CONSTRAINT,
'24000' => DB_ERROR_INVALID,
'34000' => DB_ERROR_INVALID,
'37000' => DB_ERROR_SYNTAX,
'42000' => DB_ERROR_SYNTAX,
'IM001' => DB_ERROR_UNSUPPORTED,
'S0000' => DB_ERROR_NOSUCHTABLE,
'S0001' => DB_ERROR_NOT_FOUND,
'S0002' => DB_ERROR_NOSUCHTABLE,
'S0011' => DB_ERROR_ALREADY_EXISTS,
'S0012' => DB_ERROR_NOT_FOUND,
'S0021' => DB_ERROR_ALREADY_EXISTS,
'S0022' => DB_ERROR_NOT_FOUND,
'S1000' => DB_ERROR_NOSUCHTABLE,
'S1009' => DB_ERROR_INVALID,
'S1090' => DB_ERROR_INVALID,
'S1C00' => DB_ERROR_NOT_CAPABLE
);
return $MAP;
}
function adodb_error_ibase()
{
static $MAP = array(
-104 => DB_ERROR_SYNTAX,
-150 => DB_ERROR_ACCESS_VIOLATION,
-151 => DB_ERROR_ACCESS_VIOLATION,
-155 => DB_ERROR_NOSUCHTABLE,
-157 => DB_ERROR_NOSUCHFIELD,
-158 => DB_ERROR_VALUE_COUNT_ON_ROW,
-170 => DB_ERROR_MISMATCH,
-171 => DB_ERROR_MISMATCH,
-172 => DB_ERROR_INVALID,
-204 => DB_ERROR_INVALID,
-205 => DB_ERROR_NOSUCHFIELD,
-206 => DB_ERROR_NOSUCHFIELD,
-208 => DB_ERROR_INVALID,
-219 => DB_ERROR_NOSUCHTABLE,
-297 => DB_ERROR_CONSTRAINT,
-530 => DB_ERROR_CONSTRAINT,
-803 => DB_ERROR_CONSTRAINT,
-551 => DB_ERROR_ACCESS_VIOLATION,
-552 => DB_ERROR_ACCESS_VIOLATION,
-922 => DB_ERROR_NOSUCHDB,
-923 => DB_ERROR_CONNECT_FAILED,
-924 => DB_ERROR_CONNECT_FAILED
);
return $MAP;
}
function adodb_error_ifx()
{
static $MAP = array(
'-201' => DB_ERROR_SYNTAX,
'-206' => DB_ERROR_NOSUCHTABLE,
'-217' => DB_ERROR_NOSUCHFIELD,
'-329' => DB_ERROR_NODBSELECTED,
'-1204' => DB_ERROR_INVALID_DATE,
'-1205' => DB_ERROR_INVALID_DATE,
'-1206' => DB_ERROR_INVALID_DATE,
'-1209' => DB_ERROR_INVALID_DATE,
'-1210' => DB_ERROR_INVALID_DATE,
'-1212' => DB_ERROR_INVALID_DATE
);
return $MAP;
}
function adodb_error_oci8()
{
static $MAP = array(
1 => DB_ERROR_ALREADY_EXISTS,
900 => DB_ERROR_SYNTAX,
904 => DB_ERROR_NOSUCHFIELD,
923 => DB_ERROR_SYNTAX,
942 => DB_ERROR_NOSUCHTABLE,
955 => DB_ERROR_ALREADY_EXISTS,
1476 => DB_ERROR_DIVZERO,
1722 => DB_ERROR_INVALID_NUMBER,
2289 => DB_ERROR_NOSUCHTABLE,
2291 => DB_ERROR_CONSTRAINT,
2449 => DB_ERROR_CONSTRAINT
);
return $MAP;
}
function adodb_error_mssql()
{
static $MAP = array(
208 => DB_ERROR_NOSUCHTABLE,
2601 => DB_ERROR_ALREADY_EXISTS
);
return $MAP;
}
function adodb_error_sqlite()
{
static $MAP = array(
1 => DB_ERROR_SYNTAX
);
return $MAP;
}
function adodb_error_mysql()
{
static $MAP = array(
1004 => DB_ERROR_CANNOT_CREATE,
1005 => DB_ERROR_CANNOT_CREATE,
1006 => DB_ERROR_CANNOT_CREATE,
1007 => DB_ERROR_ALREADY_EXISTS,
1008 => DB_ERROR_CANNOT_DROP,
1045 => DB_ERROR_ACCESS_VIOLATION,
1046 => DB_ERROR_NODBSELECTED,
1049 => DB_ERROR_NOSUCHDB,
1050 => DB_ERROR_ALREADY_EXISTS,
1051 => DB_ERROR_NOSUCHTABLE,
1054 => DB_ERROR_NOSUCHFIELD,
1062 => DB_ERROR_ALREADY_EXISTS,
1064 => DB_ERROR_SYNTAX,
1100 => DB_ERROR_NOT_LOCKED,
1136 => DB_ERROR_VALUE_COUNT_ON_ROW,
1146 => DB_ERROR_NOSUCHTABLE,
1048 => DB_ERROR_CONSTRAINT,
2002 => DB_ERROR_CONNECT_FAILED
);
return $MAP;
}
?> Neuinstallation/HTML_Code/adodb/adodb-errorhandler.inc.php 0100444 0000002 0000002 00000005413 10330414140 0022507 0 ustar root root $s";
trigger_error($s,ADODB_ERROR_HANDLER_TYPE);
}
?>
Neuinstallation/HTML_Code/adodb/adodb-errorpear.inc.php 0100444 0000002 0000002 00000004473 10330414142 0022030 0 ustar root root !$s";
}
/**
* Returns last PEAR_Error object. This error might be for an error that
* occured several sql statements ago.
*/
function &ADODB_PEAR_Error()
{
global $ADODB_Last_PEAR_Error;
return $ADODB_Last_PEAR_Error;
}
?> Neuinstallation/HTML_Code/adodb/adodb-exceptions.inc.php 0100444 0000002 0000002 00000004326 10330414142 0022205 0 ustar root root sql = $p1;
$this->params = $p2;
$s = "$dbms error: [$errno: $errmsg] in $fn(\"$p1\")\n";
break;
case 'PCONNECT':
case 'CONNECT':
$user = $thisConnection->user;
$s = "$dbms error: [$errno: $errmsg] in $fn($p1, '$user', '****', $p2)\n";
break;
default:
$s = "$dbms error: [$errno: $errmsg] in $fn($p1, $p2)\n";
break;
}
$this->dbms = $dbms;
$this->host = $thisConnection->host;
$this->database = $thisConnection->database;
$this->fn = $fn;
$this->msg = $errmsg;
if (!is_numeric($errno)) $errno = -1;
parent::__construct($s,$errno);
}
}
/**
* Default Error Handler. This will be called with the following params
*
* @param $dbms the RDBMS you are connecting to
* @param $fn the name of the calling function (in uppercase)
* @param $errno the native error number from the database
* @param $errmsg the native error msg from the database
* @param $p1 $fn specific parameter - see below
* @param $P2 $fn specific parameter - see below
*/
function adodb_throw($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection)
{
global $ADODB_EXCEPTION;
if (error_reporting() == 0) return; // obey @ protocol
if (is_string($ADODB_EXCEPTION)) $errfn = $ADODB_EXCEPTION;
else $errfn = 'ADODB_EXCEPTION';
throw new $errfn($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection);
}
?> Neuinstallation/HTML_Code/adodb/adodb-iterator.inc.php 0100444 0000002 0000002 00000003216 10330414142 0021652 0 ustar root root Execute("select * from adoxyz");
foreach($rs as $k => $v) {
echo $k; print_r($v); echo "
";
}
Iterator code based on http://cvs.php.net/cvs.php/php-src/ext/spl/examples/cachingiterator.inc?login=2
*/
class ADODB_Iterator implements Iterator {
private $rs;
function __construct($rs)
{
$this->rs = $rs;
}
function rewind()
{
$this->rs->MoveFirst();
}
function valid()
{
return !$this->rs->EOF;
}
function key()
{
return $this->rs->_currentRow;
}
function current()
{
return $this->rs->fields;
}
function next()
{
$this->rs->MoveNext();
}
function __call($func, $params)
{
return call_user_func_array(array($this->rs, $func), $params);
}
function hasMore()
{
return !$this->rs->EOF;
}
}
class ADODB_BASE_RS implements IteratorAggregate {
function getIterator() {
return new ADODB_Iterator($this);
}
/* this is experimental - i don't really know what to return... */
function __toString()
{
include_once(ADODB_DIR.'/toexport.inc.php');
return _adodb_export($this,',',',',false,true);
}
}
?> Neuinstallation/HTML_Code/adodb/adodb-lib.inc.php 0100444 0000002 0000002 00000067711 10330414144 0020603 0 ustar root root $value)
$new_array[strtoupper($key)] = $value;
return $new_array;
}
return $an_array;
}
function _adodb_replace(&$zthis, $table, $fieldArray, $keyCol, $autoQuote, $has_autoinc)
{
if (count($fieldArray) == 0) return 0;
$first = true;
$uSet = '';
if (!is_array($keyCol)) {
$keyCol = array($keyCol);
}
foreach($fieldArray as $k => $v) {
if ($autoQuote && !is_numeric($v) and strncmp($v,"'",1) !== 0 and strcasecmp($v,'null')!=0) {
$v = $zthis->qstr($v);
$fieldArray[$k] = $v;
}
if (in_array($k,$keyCol)) continue; // skip UPDATE if is key
if ($first) {
$first = false;
$uSet = "$k=$v";
} else
$uSet .= ",$k=$v";
}
$where = false;
foreach ($keyCol as $v) {
if ($where) $where .= " and $v=$fieldArray[$v]";
else $where = "$v=$fieldArray[$v]";
}
if ($uSet && $where) {
$update = "UPDATE $table SET $uSet WHERE $where";
$rs = $zthis->Execute($update);
if ($rs) {
if ($zthis->poorAffectedRows) {
/*
The Select count(*) wipes out any errors that the update would have returned.
http://phplens.com/lens/lensforum/msgs.php?id=5696
*/
if ($zthis->ErrorNo()<>0) return 0;
# affected_rows == 0 if update field values identical to old values
# for mysql - which is silly.
$cnt = $zthis->GetOne("select count(*) from $table where $where");
if ($cnt > 0) return 1; // record already exists
} else {
if (($zthis->Affected_Rows()>0)) return 1;
}
} else
return 0;
}
// print "Error=".$this->ErrorNo().'
';
$first = true;
foreach($fieldArray as $k => $v) {
if ($has_autoinc && in_array($k,$keyCol)) continue; // skip autoinc col
if ($first) {
$first = false;
$iCols = "$k";
$iVals = "$v";
} else {
$iCols .= ",$k";
$iVals .= ",$v";
}
}
$insert = "INSERT INTO $table ($iCols) VALUES ($iVals)";
$rs = $zthis->Execute($insert);
return ($rs) ? 2 : 0;
}
// Requires $ADODB_FETCH_MODE = ADODB_FETCH_NUM
function _adodb_getmenu(&$zthis, $name,$defstr='',$blank1stItem=true,$multiple=false,
$size=0, $selectAttr='',$compareFields0=true)
{
$hasvalue = false;
if ($multiple or is_array($defstr)) {
if ($size==0) $size=5;
$attr = ' multiple size="'.$size.'"';
if (!strpos($name,'[]')) $name .= '[]';
} else if ($size) $attr = ' size="'.$size.'"';
else $attr ='';
$s = '\n";
}
/*
Count the number of records this sql statement will return by using
query rewriting techniques...
Does not work with UNIONs.
*/
function _adodb_getcount(&$zthis, $sql,$inputarr=false,$secs2cache=0)
{
$qryRecs = 0;
if (preg_match("/^\s*SELECT\s+DISTINCT/is", $sql) || preg_match('/\s+GROUP\s+BY\s+/is',$sql)) {
// ok, has SELECT DISTINCT or GROUP BY so see if we can use a table alias
// but this is only supported by oracle and postgresql...
if ($zthis->dataProvider == 'oci8') {
$rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','',$sql);
$rewritesql = "SELECT COUNT(*) FROM ($rewritesql)";
} else if ( $zthis->databaseType == 'postgres' || $zthis->databaseType == 'postgres7') {
$info = $zthis->ServerInfo();
if (substr($info['version'],0,3) >= 7.1) { // good till version 999
$rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','',$sql);
$rewritesql = "SELECT COUNT(*) FROM ($rewritesql) _ADODB_ALIAS_";
}
}
} else {
// now replace SELECT ... FROM with SELECT COUNT(*) FROM
$rewritesql = preg_replace(
'/^\s*SELECT\s.*\s+FROM\s/Uis','SELECT COUNT(*) FROM ',$sql);
// fix by alexander zhukov, alex#unipack.ru, because count(*) and 'order by' fails
// with mssql, access and postgresql. Also a good speedup optimization - skips sorting!
$rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','',$rewritesql);
}
if (isset($rewritesql) && $rewritesql != $sql) {
if ($secs2cache) {
// we only use half the time of secs2cache because the count can quickly
// become inaccurate if new records are added
$qryRecs = $zthis->CacheGetOne($secs2cache/2,$rewritesql,$inputarr);
} else {
$qryRecs = $zthis->GetOne($rewritesql,$inputarr);
}
if ($qryRecs !== false) return $qryRecs;
}
//--------------------------------------------
// query rewrite failed - so try slower way...
// strip off unneeded ORDER BY if no UNION
if (preg_match('/\s*UNION\s*/is', $sql)) $rewritesql = $sql;
else $rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','',$sql);
$rstest = &$zthis->Execute($rewritesql,$inputarr);
if ($rstest) {
$qryRecs = $rstest->RecordCount();
if ($qryRecs == -1) {
global $ADODB_EXTENSION;
// some databases will return -1 on MoveLast() - change to MoveNext()
if ($ADODB_EXTENSION) {
while(!$rstest->EOF) {
adodb_movenext($rstest);
}
} else {
while(!$rstest->EOF) {
$rstest->MoveNext();
}
}
$qryRecs = $rstest->_currentRow;
}
$rstest->Close();
if ($qryRecs == -1) return 0;
}
return $qryRecs;
}
/*
Code originally from "Cornel G"
This code will not work with SQL that has UNION in it
Also if you are using CachePageExecute(), there is a strong possibility that
data will get out of synch. use CachePageExecute() only with tables that
rarely change.
*/
function &_adodb_pageexecute_all_rows(&$zthis, $sql, $nrows, $page,
$inputarr=false, $secs2cache=0)
{
$atfirstpage = false;
$atlastpage = false;
$lastpageno=1;
// If an invalid nrows is supplied,
// we assume a default value of 10 rows per page
if (!isset($nrows) || $nrows <= 0) $nrows = 10;
$qryRecs = false; //count records for no offset
$qryRecs = _adodb_getcount($zthis,$sql,$inputarr,$secs2cache);
$lastpageno = (int) ceil($qryRecs / $nrows);
$zthis->_maxRecordCount = $qryRecs;
// ***** Here we check whether $page is the last page or
// whether we are trying to retrieve
// a page number greater than the last page number.
if ($page >= $lastpageno) {
$page = $lastpageno;
$atlastpage = true;
}
// If page number <= 1, then we are at the first page
if (empty($page) || $page <= 1) {
$page = 1;
$atfirstpage = true;
}
// We get the data we want
$offset = $nrows * ($page-1);
if ($secs2cache > 0)
$rsreturn = &$zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $offset, $inputarr);
else
$rsreturn = &$zthis->SelectLimit($sql, $nrows, $offset, $inputarr, $secs2cache);
// Before returning the RecordSet, we set the pagination properties we need
if ($rsreturn) {
$rsreturn->_maxRecordCount = $qryRecs;
$rsreturn->rowsPerPage = $nrows;
$rsreturn->AbsolutePage($page);
$rsreturn->AtFirstPage($atfirstpage);
$rsreturn->AtLastPage($atlastpage);
$rsreturn->LastPageNo($lastpageno);
}
return $rsreturn;
}
// Ivn Oliva version
function &_adodb_pageexecute_no_last_page(&$zthis, $sql, $nrows, $page, $inputarr=false, $secs2cache=0)
{
$atfirstpage = false;
$atlastpage = false;
if (!isset($page) || $page <= 1) { // If page number <= 1, then we are at the first page
$page = 1;
$atfirstpage = true;
}
if ($nrows <= 0) $nrows = 10; // If an invalid nrows is supplied, we assume a default value of 10 rows per page
// ***** Here we check whether $page is the last page or whether we are trying to retrieve a page number greater than
// the last page number.
$pagecounter = $page + 1;
$pagecounteroffset = ($pagecounter * $nrows) - $nrows;
if ($secs2cache>0) $rstest = &$zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $pagecounteroffset, $inputarr);
else $rstest = &$zthis->SelectLimit($sql, $nrows, $pagecounteroffset, $inputarr, $secs2cache);
if ($rstest) {
while ($rstest && $rstest->EOF && $pagecounter>0) {
$atlastpage = true;
$pagecounter--;
$pagecounteroffset = $nrows * ($pagecounter - 1);
$rstest->Close();
if ($secs2cache>0) $rstest = &$zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $pagecounteroffset, $inputarr);
else $rstest = &$zthis->SelectLimit($sql, $nrows, $pagecounteroffset, $inputarr, $secs2cache);
}
if ($rstest) $rstest->Close();
}
if ($atlastpage) { // If we are at the last page or beyond it, we are going to retrieve it
$page = $pagecounter;
if ($page == 1) $atfirstpage = true; // We have to do this again in case the last page is the same as the first
//... page, that is, the recordset has only 1 page.
}
// We get the data we want
$offset = $nrows * ($page-1);
if ($secs2cache > 0) $rsreturn = &$zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $offset, $inputarr);
else $rsreturn = &$zthis->SelectLimit($sql, $nrows, $offset, $inputarr, $secs2cache);
// Before returning the RecordSet, we set the pagination properties we need
if ($rsreturn) {
$rsreturn->rowsPerPage = $nrows;
$rsreturn->AbsolutePage($page);
$rsreturn->AtFirstPage($atfirstpage);
$rsreturn->AtLastPage($atlastpage);
}
return $rsreturn;
}
function _adodb_getupdatesql(&$zthis,&$rs, $arrFields,$forceUpdate=false,$magicq=false,$force=2)
{
if (!$rs) {
printf(ADODB_BAD_RS,'GetUpdateSQL');
return false;
}
$fieldUpdatedCount = 0;
$arrFields = _array_change_key_case($arrFields);
$hasnumeric = isset($rs->fields[0]);
$setFields = '';
// Loop through all of the fields in the recordset
for ($i=0, $max=$rs->FieldCount(); $i < $max; $i++) {
// Get the field from the recordset
$field = $rs->FetchField($i);
// If the recordset field is one
// of the fields passed in then process.
$upperfname = strtoupper($field->name);
if (adodb_key_exists($upperfname,$arrFields,$force)) {
// If the existing field value in the recordset
// is different from the value passed in then
// go ahead and append the field name and new value to
// the update query.
if ($hasnumeric) $val = $rs->fields[$i];
else if (isset($rs->fields[$upperfname])) $val = $rs->fields[$upperfname];
else if (isset($rs->fields[$field->name])) $val = $rs->fields[$field->name];
else if (isset($rs->fields[strtolower($upperfname)])) $val = $rs->fields[strtolower($upperfname)];
else $val = '';
if ($forceUpdate || strcmp($val, $arrFields[$upperfname])) {
// Set the counter for the number of fields that will be updated.
$fieldUpdatedCount++;
// Based on the datatype of the field
// Format the value properly for the database
$type = $rs->MetaType($field->type);
if ($type == 'null') {
$type = 'C';
}
if (strpos($upperfname,' ') !== false)
$fnameq = $zthis->nameQuote.$upperfname.$zthis->nameQuote;
else
$fnameq = $upperfname;
// is_null requires php 4.0.4
//********************************************************//
if (is_null($arrFields[$upperfname])
|| (empty($arrFields[$upperfname]) && strlen($arrFields[$upperfname]) == 0)
|| $arrFields[$upperfname] === 'null'
)
{
switch ($force) {
//case 0:
// //Ignore empty values. This is allready handled in "adodb_key_exists" function.
//break;
case 1:
//Set null
$setFields .= $field->name . " = null, ";
break;
case 2:
//Set empty
$arrFields[$upperfname] = "";
$setFields .= _adodb_column_sql($zthis, 'U', $type, $upperfname, $fnameq,$arrFields, $magicq);
break;
default:
case 3:
//Set the value that was given in array, so you can give both null and empty values
if (is_null($arrFields[$upperfname]) || $arrFields[$upperfname] === 'null') {
$setFields .= $field->name . " = null, ";
} else {
$setFields .= _adodb_column_sql($zthis, 'U', $type, $upperfname, $fnameq,$arrFields, $magicq);
}
break;
}
//********************************************************//
} else {
//we do this so each driver can customize the sql for
//DB specific column types.
//Oracle needs BLOB types to be handled with a returning clause
//postgres has special needs as well
$setFields .= _adodb_column_sql($zthis, 'U', $type, $upperfname, $fnameq,
$arrFields, $magicq);
}
}
}
}
// If there were any modified fields then build the rest of the update query.
if ($fieldUpdatedCount > 0 || $forceUpdate) {
// Get the table name from the existing query.
preg_match("/FROM\s+".ADODB_TABLE_REGEX."/is", $rs->sql, $tableName);
// Get the full where clause excluding the word "WHERE" from
// the existing query.
preg_match('/\sWHERE\s(.*)/is', $rs->sql, $whereClause);
$discard = false;
// not a good hack, improvements?
if ($whereClause) {
if (preg_match('/\s(ORDER\s.*)/is', $whereClause[1], $discard));
else if (preg_match('/\s(LIMIT\s.*)/is', $whereClause[1], $discard));
else preg_match('/\s(FOR UPDATE.*)/is', $whereClause[1], $discard);
} else
$whereClause = array(false,false);
if ($discard)
$whereClause[1] = substr($whereClause[1], 0, strlen($whereClause[1]) - strlen($discard[1]));
$sql = 'UPDATE '.$tableName[1].' SET '.substr($setFields, 0, -2);
if (strlen($whereClause[1]) > 0)
$sql .= ' WHERE '.$whereClause[1];
return $sql;
} else {
return false;
}
}
function adodb_key_exists($key, &$arr,$force=2)
{
if ($force<=0) {
// the following is the old behaviour where null or empty fields are ignored
return (!empty($arr[$key])) || (isset($arr[$key]) && strlen($arr[$key])>0);
}
if (isset($arr[$key])) return true;
## null check below
if (ADODB_PHPVER >= 0x4010) return array_key_exists($key,$arr);
return false;
}
/**
* There is a special case of this function for the oci8 driver.
* The proper way to handle an insert w/ a blob in oracle requires
* a returning clause with bind variables and a descriptor blob.
*
*
*/
function _adodb_getinsertsql(&$zthis,&$rs,$arrFields,$magicq=false,$force=2)
{
static $cacheRS = false;
static $cacheSig = 0;
static $cacheCols;
$tableName = '';
$values = '';
$fields = '';
$recordSet = null;
$arrFields = _array_change_key_case($arrFields);
$fieldInsertedCount = 0;
if (is_string($rs)) {
//ok we have a table name
//try and get the column info ourself.
$tableName = $rs;
//we need an object for the recordSet
//because we have to call MetaType.
//php can't do a $rsclass::MetaType()
$rsclass = $zthis->rsPrefix.$zthis->databaseType;
$recordSet =& new $rsclass(-1,$zthis->fetchMode);
$recordSet->connection = &$zthis;
if (is_string($cacheRS) && $cacheRS == $rs) {
$columns =& $cacheCols;
} else {
$columns = $zthis->MetaColumns( $tableName );
$cacheRS = $tableName;
$cacheCols = $columns;
}
} else if (is_subclass_of($rs, 'adorecordset')) {
if (isset($rs->insertSig) && is_integer($cacheRS) && $cacheRS == $rs->insertSig) {
$columns =& $cacheCols;
} else {
for ($i=0, $max=$rs->FieldCount(); $i < $max; $i++)
$columns[] = $rs->FetchField($i);
$cacheRS = $cacheSig;
$cacheCols = $columns;
$rs->insertSig = $cacheSig++;
}
$recordSet =& $rs;
} else {
printf(ADODB_BAD_RS,'GetInsertSQL');
return false;
}
// Loop through all of the fields in the recordset
foreach( $columns as $field ) {
$upperfname = strtoupper($field->name);
if (adodb_key_exists($upperfname,$arrFields,$force)) {
$bad = false;
if (strpos($upperfname,' ') !== false)
$fnameq = $zthis->nameQuote.$upperfname.$zthis->nameQuote;
else
$fnameq = $upperfname;
$type = $recordSet->MetaType($field->type);
/********************************************************/
if (is_null($arrFields[$upperfname])
|| (empty($arrFields[$upperfname]) && strlen($arrFields[$upperfname]) == 0)
|| $arrFields[$upperfname] === 'null'
)
{
switch ($force) {
case 0: // we must always set null if missing
$bad = true;
break;
case 1:
$values .= "null, ";
break;
case 2:
//Set empty
$arrFields[$upperfname] = "";
$values .= _adodb_column_sql($zthis, 'I', $type, $upperfname, $fnameq,$arrFields, $magicq);
break;
default:
case 3:
//Set the value that was given in array, so you can give both null and empty values
if (is_null($arrFields[$upperfname]) || $arrFields[$upperfname] === 'null') {
$values .= "null, ";
} else {
$values .= _adodb_column_sql($zthis, 'I', $type, $upperfname, $fnameq, $arrFields, $magicq);
}
break;
} // switch
/*********************************************************/
} else {
//we do this so each driver can customize the sql for
//DB specific column types.
//Oracle needs BLOB types to be handled with a returning clause
//postgres has special needs as well
$values .= _adodb_column_sql($zthis, 'I', $type, $upperfname, $fnameq,
$arrFields, $magicq);
}
if ($bad) continue;
// Set the counter for the number of fields that will be inserted.
$fieldInsertedCount++;
// Get the name of the fields to insert
$fields .= $fnameq . ", ";
}
}
// If there were any inserted fields then build the rest of the insert query.
if ($fieldInsertedCount <= 0) return false;
// Get the table name from the existing query.
if (!$tableName) {
if (preg_match("/FROM\s+".ADODB_TABLE_REGEX."/is", $rs->sql, $tableName))
$tableName = $tableName[1];
else
return false;
}
// Strip off the comma and space on the end of both the fields
// and their values.
$fields = substr($fields, 0, -2);
$values = substr($values, 0, -2);
// Append the fields and their values to the insert query.
return 'INSERT INTO '.$tableName.' ( '.$fields.' ) VALUES ( '.$values.' )';
}
/**
* This private method is used to help construct
* the update/sql which is generated by GetInsertSQL and GetUpdateSQL.
* It handles the string construction of 1 column -> sql string based on
* the column type. We want to do 'safe' handling of BLOBs
*
* @param string the type of sql we are trying to create
* 'I' or 'U'.
* @param string column data type from the db::MetaType() method
* @param string the column name
* @param array the column value
*
* @return string
*
*/
function _adodb_column_sql_oci8(&$zthis,$action, $type, $fname, $fnameq, $arrFields, $magicq)
{
$sql = '';
// Based on the datatype of the field
// Format the value properly for the database
switch($type) {
case 'B':
//in order to handle Blobs correctly, we need
//to do some magic for Oracle
//we need to create a new descriptor to handle
//this properly
if (!empty($zthis->hasReturningInto)) {
if ($action == 'I') {
$sql = 'empty_blob(), ';
} else {
$sql = $fnameq. '=empty_blob(), ';
}
//add the variable to the returning clause array
//so the user can build this later in
//case they want to add more to it
$zthis->_returningArray[$fname] = ':xx'.$fname.'xx';
} else if (empty($arrFields[$fname])){
if ($action == 'I') {
$sql = 'empty_blob(), ';
} else {
$sql = $fnameq. '=empty_blob(), ';
}
} else {
//this is to maintain compatibility
//with older adodb versions.
$sql = _adodb_column_sql($zthis, $action, $type, $fname, $fnameq, $arrFields, $magicq,false);
}
break;
case "X":
//we need to do some more magic here for long variables
//to handle these correctly in oracle.
//create a safe bind var name
//to avoid conflicts w/ dupes.
if (!empty($zthis->hasReturningInto)) {
if ($action == 'I') {
$sql = ':xx'.$fname.'xx, ';
} else {
$sql = $fnameq.'=:xx'.$fname.'xx, ';
}
//add the variable to the returning clause array
//so the user can build this later in
//case they want to add more to it
$zthis->_returningArray[$fname] = ':xx'.$fname.'xx';
} else {
//this is to maintain compatibility
//with older adodb versions.
$sql = _adodb_column_sql($zthis, $action, $type, $fname, $fnameq, $arrFields, $magicq,false);
}
break;
default:
$sql = _adodb_column_sql($zthis, $action, $type, $fname, $fnameq, $arrFields, $magicq,false);
break;
}
return $sql;
}
function _adodb_column_sql(&$zthis, $action, $type, $fname, $fnameq, $arrFields, $magicq, $recurse=true)
{
if ($recurse) {
switch($zthis->dataProvider) {
case 'postgres':
if ($type == 'L') $type = 'C';
break;
case 'oci8':
return _adodb_column_sql_oci8($zthis, $action, $type, $fname, $fnameq, $arrFields, $magicq);
}
}
$sql = '';
switch($type) {
case "C":
case "X":
case 'B':
if ($action == 'I') {
$sql = $zthis->qstr($arrFields[$fname],$magicq) . ", ";
} else {
$sql .= $fnameq . "=" . $zthis->qstr($arrFields[$fname],$magicq) . ", ";
}
break;
case "D":
if ($action == 'I') {
$sql = $zthis->DBDate($arrFields[$fname]) . ", ";
} else {
$sql .= $fnameq . "=" . $zthis->DBDate($arrFields[$fname]) . ", ";
}
break;
case "T":
if ($action == 'I') {
$sql = $zthis->DBTimeStamp($arrFields[$fname]) . ", ";
} else {
$sql .= $fnameq . "=" . $zthis->DBTimeStamp($arrFields[$fname]) . ", ";
}
break;
default:
$val = $arrFields[$fname];
if (empty($val)) $val = '0';
if ($action == 'I') {
$sql .= $val . ", ";
} else {
$sql .= $fnameq . "=" . $val . ", ";
}
break;
}
return $sql;
}
function _adodb_debug_execute(&$zthis, $sql, $inputarr)
{
global $HTTP_SERVER_VARS;
$ss = '';
if ($inputarr) {
foreach($inputarr as $kk=>$vv) {
if (is_string($vv) && strlen($vv)>64) $vv = substr($vv,0,64).'...';
$ss .= "($kk=>'$vv') ";
}
$ss = "[ $ss ]";
}
$sqlTxt = str_replace(',',', ',is_array($sql) ? $sql[0] : $sql);
// check if running from browser or command-line
$inBrowser = isset($HTTP_SERVER_VARS['HTTP_USER_AGENT']);
if ($inBrowser) {
$ss = htmlspecialchars($ss);
if ($zthis->debug === -1)
ADOConnection::outp( "
\n($zthis->databaseType): ".htmlspecialchars($sqlTxt)." $ss
\n
\n",false);
else
ADOConnection::outp( "
\n($zthis->databaseType): ".htmlspecialchars($sqlTxt)." $ss
\n
\n",false);
} else {
ADOConnection::outp("-----\n($zthis->databaseType): ".$sqlTxt."\n-----\n",false);
}
$qID = $zthis->_query($sql,$inputarr);
/*
Alexios Fakios notes that ErrorMsg() must be called before ErrorNo() for mssql
because ErrorNo() calls Execute('SELECT @ERROR'), causing recursion
*/
if ($zthis->databaseType == 'mssql') {
// ErrorNo is a slow function call in mssql, and not reliable in PHP 4.0.6
if($emsg = $zthis->ErrorMsg()) {
if ($err = $zthis->ErrorNo()) ADOConnection::outp($err.': '.$emsg);
}
} else if (!$qID) {
ADOConnection::outp($zthis->ErrorNo() .': '. $zthis->ErrorMsg());
}
return $qID;
}
function _adodb_backtrace($printOrArr=true,$levels=9999)
{
if (PHPVERSION() < 4.3) return '';
$html = (isset($_SERVER['HTTP_USER_AGENT']));
$fmt = ($html) ? " %% line %4d, file: %s" : "%% line %4d, file: %s";
$MAXSTRLEN = 64;
$s = ($html) ? '' : '';
if (is_array($printOrArr)) $traceArr = $printOrArr;
else $traceArr = debug_backtrace();
array_shift($traceArr);
array_shift($traceArr);
$tabs = sizeof($traceArr)-2;
foreach ($traceArr as $arr) {
$levels -= 1;
if ($levels < 0) break;
$args = array();
for ($i=0; $i < $tabs; $i++) $s .= ($html) ? ' ' : "\t";
$tabs -= 1;
if ($html) $s .= '';
if (isset($arr['class'])) $s .= $arr['class'].'.';
if (isset($arr['args']))
foreach($arr['args'] as $v) {
if (is_null($v)) $args[] = 'null';
else if (is_array($v)) $args[] = 'Array['.sizeof($v).']';
else if (is_object($v)) $args[] = 'Object:'.get_class($v);
else if (is_bool($v)) $args[] = $v ? 'true' : 'false';
else {
$v = (string) @$v;
$str = htmlspecialchars(substr($v,0,$MAXSTRLEN));
if (strlen($v) > $MAXSTRLEN) $str .= '...';
$args[] = $str;
}
}
$s .= $arr['function'].'('.implode(', ',$args).')';
$s .= @sprintf($fmt, $arr['line'],$arr['file'],basename($arr['file']));
$s .= "\n";
}
if ($html) $s .= '
';
if ($printOrArr) print $s;
return $s;
}
?> Neuinstallation/HTML_Code/adodb/adodb-pager.inc.php 0100444 0000002 0000002 00000020246 10330414146 0021125 0 ustar root root implemented Render_PageLinks().
Please note, this class is entirely unsupported,
and no free support requests except for bug reports
will be entertained by the author.
*/
class ADODB_Pager {
var $id; // unique id for pager (defaults to 'adodb')
var $db; // ADODB connection object
var $sql; // sql used
var $rs; // recordset generated
var $curr_page; // current page number before Render() called, calculated in constructor
var $rows; // number of rows per page
var $linksPerPage=10; // number of links per page in navigation bar
var $showPageLinks;
var $gridAttributes = 'width=100% border=1 bgcolor=white';
// Localize text strings here
var $first = '|<
';
var $prev = '<<
';
var $next = '>>
';
var $last = '>|
';
var $moreLinks = '...';
var $startLinks = '...';
var $gridHeader = false;
var $htmlSpecialChars = true;
var $page = 'Page';
var $linkSelectedColor = 'red';
var $cache = 0; #secs to cache with CachePageExecute()
//----------------------------------------------
// constructor
//
// $db adodb connection object
// $sql sql statement
// $id optional id to identify which pager,
// if you have multiple on 1 page.
// $id should be only be [a-z0-9]*
//
function ADODB_Pager(&$db,$sql,$id = 'adodb', $showPageLinks = false)
{
global $HTTP_SERVER_VARS,$PHP_SELF,$HTTP_SESSION_VARS,$HTTP_GET_VARS;
$curr_page = $id.'_curr_page';
if (empty($PHP_SELF)) $PHP_SELF = $HTTP_SERVER_VARS['PHP_SELF'];
$this->sql = $sql;
$this->id = $id;
$this->db = $db;
$this->showPageLinks = $showPageLinks;
$next_page = $id.'_next_page';
if (isset($HTTP_GET_VARS[$next_page])) {
$HTTP_SESSION_VARS[$curr_page] = $HTTP_GET_VARS[$next_page];
}
if (empty($HTTP_SESSION_VARS[$curr_page])) $HTTP_SESSION_VARS[$curr_page] = 1; ## at first page
$this->curr_page = $HTTP_SESSION_VARS[$curr_page];
}
//---------------------------
// Display link to first page
function Render_First($anchor=true)
{
global $PHP_SELF;
if ($anchor) {
?>
first;?>
first ";
}
}
//--------------------------
// Display link to next page
function render_next($anchor=true)
{
global $PHP_SELF;
if ($anchor) {
?>
next;?>
next ";
}
}
//------------------
// Link to last page
//
// for better performance with large recordsets, you can set
// $this->db->pageExecuteCountRows = false, which disables
// last page counting.
function render_last($anchor=true)
{
global $PHP_SELF;
if (!$this->db->pageExecuteCountRows) return;
if ($anchor) {
?>
last;?>
last ";
}
}
//---------------------------------------------------
// original code by "Pablo Costa"
function render_pagelinks()
{
global $PHP_SELF;
$pages = $this->rs->LastPageNo();
$linksperpage = $this->linksPerPage ? $this->linksPerPage : $pages;
for($i=1; $i <= $pages; $i+=$linksperpage)
{
if($this->rs->AbsolutePage() >= $i)
{
$start = $i;
}
}
$numbers = '';
$end = $start+$linksperpage-1;
$link = $this->id . "_next_page";
if($end > $pages) $end = $pages;
if ($this->startLinks && $start > 1) {
$pos = $start - 1;
$numbers .= "$this->startLinks ";
}
for($i=$start; $i <= $end; $i++) {
if ($this->rs->AbsolutePage() == $i)
$numbers .= "linkSelectedColor>$i ";
else
$numbers .= "$i ";
}
if ($this->moreLinks && $end < $pages)
$numbers .= "$this->moreLinks ";
print $numbers . ' ';
}
// Link to previous page
function render_prev($anchor=true)
{
global $PHP_SELF;
if ($anchor) {
?>
prev;?>
prev ";
}
}
//--------------------------------------------------------
// Simply rendering of grid. You should override this for
// better control over the format of the grid
//
// We use output buffering to keep code clean and readable.
function RenderGrid()
{
global $gSQLBlockRows; // used by rs2html to indicate how many rows to display
include_once(ADODB_DIR.'/tohtml.inc.php');
ob_start();
$gSQLBlockRows = $this->rows;
rs2html($this->rs,$this->gridAttributes,$this->gridHeader,$this->htmlSpecialChars);
$s = ob_get_contents();
ob_end_clean();
return $s;
}
//-------------------------------------------------------
// Navigation bar
//
// we use output buffering to keep the code easy to read.
function RenderNav()
{
ob_start();
if (!$this->rs->AtFirstPage()) {
$this->Render_First();
$this->Render_Prev();
} else {
$this->Render_First(false);
$this->Render_Prev(false);
}
if ($this->showPageLinks){
$this->Render_PageLinks();
}
if (!$this->rs->AtLastPage()) {
$this->Render_Next();
$this->Render_Last();
} else {
$this->Render_Next(false);
$this->Render_Last(false);
}
$s = ob_get_contents();
ob_end_clean();
return $s;
}
//-------------------
// This is the footer
function RenderPageCount()
{
if (!$this->db->pageExecuteCountRows) return '';
$lastPage = $this->rs->LastPageNo();
if ($lastPage == -1) $lastPage = 1; // check for empty rs.
if ($this->curr_page > $lastPage) $this->curr_page = 1;
return "$this->page ".$this->curr_page."/".$lastPage."";
}
//-----------------------------------
// Call this class to draw everything.
function Render($rows=10)
{
global $ADODB_COUNTRECS;
$this->rows = $rows;
$savec = $ADODB_COUNTRECS;
if ($this->db->pageExecuteCountRows) $ADODB_COUNTRECS = true;
if ($this->cache)
$rs = &$this->db->CachePageExecute($this->cache,$this->sql,$rows,$this->curr_page);
else
$rs = &$this->db->PageExecute($this->sql,$rows,$this->curr_page);
$ADODB_COUNTRECS = $savec;
$this->rs = &$rs;
if (!$rs) {
print "Query failed: $this->sql
";
return;
}
if (!$rs->EOF && (!$rs->AtFirstPage() || !$rs->AtLastPage()))
$header = $this->RenderNav();
else
$header = " ";
$grid = $this->RenderGrid();
$footer = $this->RenderPageCount();
$rs->Close();
$this->rs = false;
$this->RenderLayout($header,$grid,$footer);
}
//------------------------------------------------------
// override this to control overall layout and formating
function RenderLayout($header,$grid,$footer,$attributes='border=1 bgcolor=beige')
{
echo "",
$header,
" |
",
$grid,
" |
",
$footer,
" |
";
}
}
?> Neuinstallation/HTML_Code/adodb/adodb-pear.inc.php 0100444 0000002 0000002 00000023153 10330414146 0020756 0 ustar root root |
* and Tomas V.V.Cox . Portions (c)1997-2002 The PHP Group.
*/
/*
We support:
DB_Common
---------
query - returns PEAR_Error on error
limitQuery - return PEAR_Error on error
prepare - does not return PEAR_Error on error
execute - does not return PEAR_Error on error
setFetchMode - supports ASSOC and ORDERED
errorNative
quote
nextID
disconnect
getOne
getAssoc
getRow
getCol
getAll
DB_Result
---------
numRows - returns -1 if not supported
numCols
fetchInto - does not support passing of fetchmode
fetchRows - does not support passing of fetchmode
free
*/
define('ADODB_PEAR',dirname(__FILE__));
include_once "PEAR.php";
include_once ADODB_PEAR."/adodb-errorpear.inc.php";
include_once ADODB_PEAR."/adodb.inc.php";
if (!defined('DB_OK')) {
define("DB_OK", 1);
define("DB_ERROR",-1);
/**
* This is a special constant that tells DB the user hasn't specified
* any particular get mode, so the default should be used.
*/
define('DB_FETCHMODE_DEFAULT', 0);
/**
* Column data indexed by numbers, ordered from 0 and up
*/
define('DB_FETCHMODE_ORDERED', 1);
/**
* Column data indexed by column names
*/
define('DB_FETCHMODE_ASSOC', 2);
/* for compatibility */
define('DB_GETMODE_ORDERED', DB_FETCHMODE_ORDERED);
define('DB_GETMODE_ASSOC', DB_FETCHMODE_ASSOC);
/**
* these are constants for the tableInfo-function
* they are bitwised or'ed. so if there are more constants to be defined
* in the future, adjust DB_TABLEINFO_FULL accordingly
*/
define('DB_TABLEINFO_ORDER', 1);
define('DB_TABLEINFO_ORDERTABLE', 2);
define('DB_TABLEINFO_FULL', 3);
}
/**
* The main "DB" class is simply a container class with some static
* methods for creating DB objects as well as some utility functions
* common to all parts of DB.
*
*/
class DB
{
/**
* Create a new DB object for the specified database type
*
* @param $type string database type, for example "mysql"
*
* @return object a newly created DB object, or a DB error code on
* error
*/
function &factory($type)
{
include_once(ADODB_DIR."/drivers/adodb-$type.inc.php");
$obj = &NewADOConnection($type);
if (!is_object($obj)) $obj =& new PEAR_Error('Unknown Database Driver: '.$dsninfo['phptype'],-1);
return $obj;
}
/**
* Create a new DB object and connect to the specified database
*
* @param $dsn mixed "data source name", see the DB::parseDSN
* method for a description of the dsn format. Can also be
* specified as an array of the format returned by DB::parseDSN.
*
* @param $options mixed if boolean (or scalar), tells whether
* this connection should be persistent (for backends that support
* this). This parameter can also be an array of options, see
* DB_common::setOption for more information on connection
* options.
*
* @return object a newly created DB connection object, or a DB
* error object on error
*
* @see DB::parseDSN
* @see DB::isError
*/
function &connect($dsn, $options = false)
{
if (is_array($dsn)) {
$dsninfo = $dsn;
} else {
$dsninfo = DB::parseDSN($dsn);
}
switch ($dsninfo["phptype"]) {
case 'pgsql': $type = 'postgres7'; break;
case 'ifx': $type = 'informix9'; break;
default: $type = $dsninfo["phptype"]; break;
}
if (is_array($options) && isset($options["debug"]) &&
$options["debug"] >= 2) {
// expose php errors with sufficient debug level
@include_once("adodb-$type.inc.php");
} else {
@include_once("adodb-$type.inc.php");
}
@$obj =& NewADOConnection($type);
if (!is_object($obj)) {
$obj =& new PEAR_Error('Unknown Database Driver: '.$dsninfo['phptype'],-1);
return $obj;
}
if (is_array($options)) {
foreach($options as $k => $v) {
switch(strtolower($k)) {
case 'persist':
case 'persistent': $persist = $v; break;
#ibase
case 'dialect': $obj->dialect = $v; break;
case 'charset': $obj->charset = $v; break;
case 'buffers': $obj->buffers = $v; break;
#ado
case 'charpage': $obj->charPage = $v; break;
#mysql
case 'clientflags': $obj->clientFlags = $v; break;
}
}
} else {
$persist = false;
}
if (isset($dsninfo['socket'])) $dsninfo['hostspec'] .= ':'.$dsninfo['socket'];
else if (isset($dsninfo['port'])) $dsninfo['hostspec'] .= ':'.$dsninfo['port'];
if($persist) $ok = $obj->PConnect($dsninfo['hostspec'], $dsninfo['username'],$dsninfo['password'],$dsninfo['database']);
else $ok = $obj->Connect($dsninfo['hostspec'], $dsninfo['username'],$dsninfo['password'],$dsninfo['database']);
if (!$ok) $obj = ADODB_PEAR_Error();
return $obj;
}
/**
* Return the DB API version
*
* @return int the DB API version number
*/
function apiVersion()
{
return 2;
}
/**
* Tell whether a result code from a DB method is an error
*
* @param $value int result code
*
* @return bool whether $value is an error
*/
function isError($value)
{
if (!is_object($value)) return false;
$class = get_class($value);
return $class == 'pear_error' || is_subclass_of($value, 'pear_error') ||
$class == 'db_error' || is_subclass_of($value, 'db_error');
}
/**
* Tell whether a result code from a DB method is a warning.
* Warnings differ from errors in that they are generated by DB,
* and are not fatal.
*
* @param $value mixed result value
*
* @return bool whether $value is a warning
*/
function isWarning($value)
{
return false;
/*
return is_object($value) &&
(get_class( $value ) == "db_warning" ||
is_subclass_of($value, "db_warning"));*/
}
/**
* Parse a data source name
*
* @param $dsn string Data Source Name to be parsed
*
* @return array an associative array with the following keys:
*
* phptype: Database backend used in PHP (mysql, odbc etc.)
* dbsyntax: Database used with regards to SQL syntax etc.
* protocol: Communication protocol to use (tcp, unix etc.)
* hostspec: Host specification (hostname[:port])
* database: Database to use on the DBMS server
* username: User name for login
* password: Password for login
*
* The format of the supplied DSN is in its fullest form:
*
* phptype(dbsyntax)://username:password@protocol+hostspec/database
*
* Most variations are allowed:
*
* phptype://username:password@protocol+hostspec:110//usr/db_file.db
* phptype://username:password@hostspec/database_name
* phptype://username:password@hostspec
* phptype://username@hostspec
* phptype://hostspec/database
* phptype://hostspec
* phptype(dbsyntax)
* phptype
*
* @author Tomas V.V.Cox
*/
function parseDSN($dsn)
{
if (is_array($dsn)) {
return $dsn;
}
$parsed = array(
'phptype' => false,
'dbsyntax' => false,
'protocol' => false,
'hostspec' => false,
'database' => false,
'username' => false,
'password' => false
);
// Find phptype and dbsyntax
if (($pos = strpos($dsn, '://')) !== false) {
$str = substr($dsn, 0, $pos);
$dsn = substr($dsn, $pos + 3);
} else {
$str = $dsn;
$dsn = NULL;
}
// Get phptype and dbsyntax
// $str => phptype(dbsyntax)
if (preg_match('|^(.+?)\((.*?)\)$|', $str, $arr)) {
$parsed['phptype'] = $arr[1];
$parsed['dbsyntax'] = (empty($arr[2])) ? $arr[1] : $arr[2];
} else {
$parsed['phptype'] = $str;
$parsed['dbsyntax'] = $str;
}
if (empty($dsn)) {
return $parsed;
}
// Get (if found): username and password
// $dsn => username:password@protocol+hostspec/database
if (($at = strpos($dsn,'@')) !== false) {
$str = substr($dsn, 0, $at);
$dsn = substr($dsn, $at + 1);
if (($pos = strpos($str, ':')) !== false) {
$parsed['username'] = urldecode(substr($str, 0, $pos));
$parsed['password'] = urldecode(substr($str, $pos + 1));
} else {
$parsed['username'] = urldecode($str);
}
}
// Find protocol and hostspec
// $dsn => protocol+hostspec/database
if (($pos=strpos($dsn, '/')) !== false) {
$str = substr($dsn, 0, $pos);
$dsn = substr($dsn, $pos + 1);
} else {
$str = $dsn;
$dsn = NULL;
}
// Get protocol + hostspec
// $str => protocol+hostspec
if (($pos=strpos($str, '+')) !== false) {
$parsed['protocol'] = substr($str, 0, $pos);
$parsed['hostspec'] = urldecode(substr($str, $pos + 1));
} else {
$parsed['hostspec'] = urldecode($str);
}
// Get dabase if any
// $dsn => database
if (!empty($dsn)) {
$parsed['database'] = $dsn;
}
return $parsed;
}
/**
* Load a PHP database extension if it is not loaded already.
*
* @access public
*
* @param $name the base name of the extension (without the .so or
* .dll suffix)
*
* @return bool true if the extension was already or successfully
* loaded, false if it could not be loaded
*/
function assertExtension($name)
{
if (!extension_loaded($name)) {
$dlext = (strncmp(PHP_OS,'WIN',3) === 0) ? '.dll' : '.so';
@dl($name . $dlext);
}
if (!extension_loaded($name)) {
return false;
}
return true;
}
}
?> Neuinstallation/HTML_Code/adodb/adodb-perf.inc.php 0100444 0000002 0000002 00000065340 10330414150 0020762 0 ustar root root fnExecute = false;
$t0 = microtime();
$rs =& $conn->Execute($sql,$inputarr);
$t1 = microtime();
if (!empty($conn->_logsql)) {
$conn->_logsql = false; // disable logsql error simulation
$dbT = $conn->databaseType;
$a0 = split(' ',$t0);
$a0 = (float)$a0[1]+(float)$a0[0];
$a1 = split(' ',$t1);
$a1 = (float)$a1[1]+(float)$a1[0];
$time = $a1 - $a0;
if (!$rs) {
$errM = $conn->ErrorMsg();
$errN = $conn->ErrorNo();
$conn->lastInsID = 0;
$tracer = substr('ERROR: '.htmlspecialchars($errM),0,250);
} else {
$tracer = '';
$errM = '';
$errN = 0;
$dbg = $conn->debug;
$conn->debug = false;
if (!is_object($rs) || $rs->dataProvider == 'empty')
$conn->_affected = $conn->affected_rows(true);
$conn->lastInsID = @$conn->Insert_ID();
$conn->debug = $dbg;
}
if (isset($HTTP_SERVER_VARS['HTTP_HOST'])) {
$tracer .= '
'.$HTTP_SERVER_VARS['HTTP_HOST'];
if (isset($HTTP_SERVER_VARS['PHP_SELF'])) $tracer .= $HTTP_SERVER_VARS['PHP_SELF'];
} else
if (isset($HTTP_SERVER_VARS['PHP_SELF'])) $tracer .= '
'.$HTTP_SERVER_VARS['PHP_SELF'];
//$tracer .= (string) adodb_backtrace(false);
$tracer = (string) substr($tracer,0,500);
if (is_array($inputarr)) {
if (is_array(reset($inputarr))) $params = 'Array sizeof='.sizeof($inputarr);
else {
$params = '';
$params = implode(', ',$inputarr);
if (strlen($params) >= 3000) $params = substr($params, 0, 3000);
}
} else {
$params = '';
}
if (is_array($sql)) $sql = $sql[0];
$arr = array('b'=>trim(substr($sql,0,230)),
'c'=>substr($sql,0,3900), 'd'=>$params,'e'=>$tracer,'f'=>adodb_round($time,6));
//var_dump($arr);
$saved = $conn->debug;
$conn->debug = 0;
$d = $conn->sysTimeStamp;
if (empty($d)) $d = date("'Y-m-d H:i:s'");
if ($conn->dataProvider == 'oci8' && $dbT != 'oci8po') {
$isql = "insert into $perf_table values($d,:b,:c,:d,:e,:f)";
} else if ($dbT == 'odbc_mssql' || $dbT == 'informix') {
$timer = $arr['f'];
if ($dbT == 'informix') $sql2 = substr($sql2,0,230);
$sql1 = $conn->qstr($arr['b']);
$sql2 = $conn->qstr($arr['c']);
$params = $conn->qstr($arr['d']);
$tracer = $conn->qstr($arr['e']);
$isql = "insert into $perf_table (created,sql0,sql1,params,tracer,timer) values($d,$sql1,$sql2,$params,$tracer,$timer)";
if ($dbT == 'informix') $isql = str_replace(chr(10),' ',$isql);
$arr = false;
} else {
$isql = "insert into $perf_table (created,sql0,sql1,params,tracer,timer) values( $d,?,?,?,?,?)";
}
$ok = $conn->Execute($isql,$arr);
$conn->debug = $saved;
if ($ok) {
$conn->_logsql = true;
} else {
$err2 = $conn->ErrorMsg();
$conn->_logsql = true; // enable logsql error simulation
$perf =& NewPerfMonitor($conn);
if ($perf) {
if ($perf->CreateLogTable()) $ok = $conn->Execute($isql,$arr);
} else {
$ok = $conn->Execute("create table $perf_table (
created varchar(50),
sql0 varchar(250),
sql1 varchar(4000),
params varchar(3000),
tracer varchar(500),
timer decimal(16,6))");
}
if (!$ok) {
ADOConnection::outp( "LOGSQL Insert Failed: $isql
$err2
");
$conn->_logsql = false;
}
}
$conn->_errorMsg = $errM;
$conn->_errorCode = $errN;
}
$conn->fnExecute = 'adodb_log_sql';
return $rs;
}
/*
The settings data structure is an associative array that database parameter per element.
Each database parameter element in the array is itself an array consisting of:
0: category code, used to group related db parameters
1: either
a. sql string to retrieve value, eg. "select value from v\$parameter where name='db_block_size'",
b. array holding sql string and field to look for, e.g. array('show variables','table_cache'),
c. a string prefixed by =, then a PHP method of the class is invoked,
e.g. to invoke $this->GetIndexValue(), set this array element to '=GetIndexValue',
2: description of the database parameter
*/
class adodb_perf {
var $conn;
var $color = '#F0F0F0';
var $table = '';
var $titles = 'Parameter | Value | Description |
';
var $warnRatio = 90;
var $tablesSQL = false;
var $cliFormat = "%32s => %s \r\n";
var $sql1 = 'sql1'; // used for casting sql1 to text for mssql
var $explain = true;
var $helpurl = "LogSQL help";
var $createTableSQL = false;
var $maxLength = 2000;
// Sets the tablename to be used
function table($newtable = false)
{
static $_table;
if (!empty($newtable)) $_table = $newtable;
if (empty($_table)) $_table = 'adodb_logsql';
return $_table;
}
// returns array with info to calculate CPU Load
function _CPULoad()
{
/*
cpu 524152 2662 2515228 336057010
cpu0 264339 1408 1257951 168025827
cpu1 259813 1254 1257277 168031181
page 622307 25475680
swap 24 1891
intr 890153570 868093576 6 0 4 4 0 6 1 2 0 0 0 124 0 8098760 2 13961053 0 0 0 0 0 0 0 0 0 0 0 0 0 16 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
disk_io: (3,0):(3144904,54369,610378,3090535,50936192) (3,1):(3630212,54097,633016,3576115,50951320)
ctxt 66155838
btime 1062315585
processes 69293
*/
// Algorithm is taken from
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/example__obtaining_raw_performance_data.asp
if (strncmp(PHP_OS,'WIN',3)==0) {
@$c = new COM("WinMgmts:{impersonationLevel=impersonate}!Win32_PerfRawData_PerfOS_Processor.Name='_Total'");
if (!$c) return false;
$info[0] = $c->PercentProcessorTime;
$info[1] = 0;
$info[2] = 0;
$info[3] = $c->TimeStamp_Sys100NS;
//print_r($info);
return $info;
}
// Algorithm - Steve Blinch (BlitzAffe Online, http://www.blitzaffe.com)
$statfile = '/proc/stat';
if (!file_exists($statfile)) return false;
$fd = fopen($statfile,"r");
if (!$fd) return false;
$statinfo = explode("\n",fgets($fd, 1024));
fclose($fd);
foreach($statinfo as $line) {
$info = explode(" ",$line);
if($info[0]=="cpu") {
array_shift($info); // pop off "cpu"
if(!$info[0]) array_shift($info); // pop off blank space (if any)
return $info;
}
}
return false;
}
/* NOT IMPLEMENTED */
function MemInfo()
{
/*
total: used: free: shared: buffers: cached:
Mem: 1055289344 917299200 137990144 0 165437440 599773184
Swap: 2146775040 11055104 2135719936
MemTotal: 1030556 kB
MemFree: 134756 kB
MemShared: 0 kB
Buffers: 161560 kB
Cached: 581384 kB
SwapCached: 4332 kB
Active: 494468 kB
Inact_dirty: 322856 kB
Inact_clean: 24256 kB
Inact_target: 168316 kB
HighTotal: 131064 kB
HighFree: 1024 kB
LowTotal: 899492 kB
LowFree: 133732 kB
SwapTotal: 2096460 kB
SwapFree: 2085664 kB
Committed_AS: 348732 kB
*/
}
/*
Remember that this is client load, not db server load!
*/
var $_lastLoad;
function CPULoad()
{
$info = $this->_CPULoad();
if (!$info) return false;
if (empty($this->_lastLoad)) {
sleep(1);
$this->_lastLoad = $info;
$info = $this->_CPULoad();
}
$last = $this->_lastLoad;
$this->_lastLoad = $info;
$d_user = $info[0] - $last[0];
$d_nice = $info[1] - $last[1];
$d_system = $info[2] - $last[2];
$d_idle = $info[3] - $last[3];
//printf("Delta - User: %f Nice: %f System: %f Idle: %f
",$d_user,$d_nice,$d_system,$d_idle);
if (strncmp(PHP_OS,'WIN',3)==0) {
if ($d_idle < 1) $d_idle = 1;
return 100*(1-$d_user/$d_idle);
}else {
$total=$d_user+$d_nice+$d_system+$d_idle;
if ($total<1) $total=1;
return 100*($d_user+$d_nice+$d_system)/$total;
}
}
function Tracer($sql)
{
$perf_table = adodb_perf::table();
$saveE = $this->conn->fnExecute;
$this->conn->fnExecute = false;
$sqlq = $this->conn->qstr($sql);
$arr = $this->conn->GetArray(
"select count(*),tracer
from $perf_table where sql1=$sqlq
group by tracer
order by 1 desc");
$s = '';
if ($arr) {
$s .= 'Scripts Affected
';
foreach($arr as $k) {
$s .= sprintf("%4d",$k[0]).' '.strip_tags($k[1]).'
';
}
}
$this->conn->fnExecute = $saveE;
return $s;
}
/*
Explain Plan for $sql.
If only a snippet of the $sql is passed in, then $partial will hold the crc32 of the
actual sql.
*/
function Explain($sql,$partial=false)
{
return false;
}
function InvalidSQL($numsql = 10)
{
global $HTTP_GET_VARS;
if (isset($HTTP_GET_VARS['sql'])) return;
$s = 'Invalid SQL
';
$saveE = $this->conn->fnExecute;
$this->conn->fnExecute = false;
$perf_table = adodb_perf::table();
$rs =& $this->conn->SelectLimit("select distinct count(*),sql1,tracer as error_msg from $perf_table where tracer like 'ERROR:%' group by sql1,tracer order by 1 desc",$numsql);//,$numsql);
$this->conn->fnExecute = $saveE;
if ($rs) {
$s .= rs2html($rs,false,false,false,false);
} else
return "$this->helpurl. ".$this->conn->ErrorMsg()."
";
return $s;
}
/*
This script identifies the longest running SQL
*/
function _SuspiciousSQL($numsql = 10)
{
global $ADODB_FETCH_MODE,$HTTP_GET_VARS;
$perf_table = adodb_perf::table();
$saveE = $this->conn->fnExecute;
$this->conn->fnExecute = false;
if (isset($HTTP_GET_VARS['exps']) && isset($HTTP_GET_VARS['sql'])) {
$partial = !empty($HTTP_GET_VARS['part']);
echo "".$this->Explain($HTTP_GET_VARS['sql'],$partial)."\n";
}
if (isset($HTTP_GET_VARS['sql'])) return;
$sql1 = $this->sql1;
$save = $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
//$this->conn->debug=1;
$rs =& $this->conn->SelectLimit(
"select avg(timer) as avg_timer,$sql1,count(*),max(timer) as max_timer,min(timer) as min_timer
from $perf_table
where {$this->conn->upperCase}({$this->conn->substr}(sql0,1,5)) not in ('DROP ','INSER','COMMI','CREAT')
and (tracer is null or tracer not like 'ERROR:%')
group by sql1
order by 1 desc",$numsql);
$ADODB_FETCH_MODE = $save;
$this->conn->fnExecute = $saveE;
if (!$rs) return "$this->helpurl. ".$this->conn->ErrorMsg()."
";
$s = "Suspicious SQL
The following SQL have high average execution times
Avg Time | Count | SQL | Max | Min |
\n";
$max = $this->maxLength;
while (!$rs->EOF) {
$sql = $rs->fields[1];
$raw = urlencode($sql);
if (strlen($raw)>$max-100) {
$sql2 = substr($sql,0,$max-500);
$raw = urlencode($sql2).'&part='.crc32($sql);
}
$prefix = "";
$suffix = "";
if ($this->explain == false || strlen($prefix)>$max) {
$suffix = ' ... String too long for GET parameter: '.strlen($prefix).'';
$prefix = '';
}
$s .= "".adodb_round($rs->fields[0],6)." | ".$rs->fields[2]." | ".$prefix.htmlspecialchars($sql).$suffix."".
" | ".$rs->fields[3]." | ".$rs->fields[4]." |
";
$rs->MoveNext();
}
return $s."
";
}
function CheckMemory()
{
return '';
}
function SuspiciousSQL($numsql=10)
{
return adodb_perf::_SuspiciousSQL($numsql);
}
function ExpensiveSQL($numsql=10)
{
return adodb_perf::_ExpensiveSQL($numsql);
}
/*
This reports the percentage of load on the instance due to the most
expensive few SQL statements. Tuning these statements can often
make huge improvements in overall system performance.
*/
function _ExpensiveSQL($numsql = 10)
{
global $HTTP_GET_VARS,$ADODB_FETCH_MODE;
$perf_table = adodb_perf::table();
$saveE = $this->conn->fnExecute;
$this->conn->fnExecute = false;
if (isset($HTTP_GET_VARS['expe']) && isset($HTTP_GET_VARS['sql'])) {
$partial = !empty($HTTP_GET_VARS['part']);
echo "".$this->Explain($HTTP_GET_VARS['sql'],$partial)."\n";
}
if (isset($HTTP_GET_VARS['sql'])) return;
$sql1 = $this->sql1;
$save = $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
$rs =& $this->conn->SelectLimit(
"select sum(timer) as total,$sql1,count(*),max(timer) as max_timer,min(timer) as min_timer
from $perf_table
where {$this->conn->upperCase}({$this->conn->substr}(sql0,1,5)) not in ('DROP ','INSER','COMMI','CREAT')
and (tracer is null or tracer not like 'ERROR:%')
group by sql1
order by 1 desc",$numsql);
$this->conn->fnExecute = $saveE;
$ADODB_FETCH_MODE = $save;
if (!$rs) return "$this->helpurl. ".$this->conn->ErrorMsg()."
";
$s = "Expensive SQL
Tuning the following SQL will reduce the server load substantially
Load | Count | SQL | Max | Min |
\n";
$max = $this->maxLength;
while (!$rs->EOF) {
$sql = $rs->fields[1];
$raw = urlencode($sql);
if (strlen($raw)>$max-100) {
$sql2 = substr($sql,0,$max-500);
$raw = urlencode($sql2).'&part='.crc32($sql);
}
$prefix = "";
$suffix = "";
if($this->explain == false || strlen($prefix>$max)) {
$prefix = '';
$suffix = '';
}
$s .= "".adodb_round($rs->fields[0],6)." | ".$rs->fields[2]." | ".$prefix.htmlspecialchars($sql).$suffix."".
" | ".$rs->fields[3]." | ".$rs->fields[4]." |
";
$rs->MoveNext();
}
return $s."
";
}
/*
Raw function to return parameter value from $settings.
*/
function DBParameter($param)
{
if (empty($this->settings[$param])) return false;
$sql = $this->settings[$param][1];
return $this->_DBParameter($sql);
}
/*
Raw function returning array of poll paramters
*/
function &PollParameters()
{
$arr[0] = (float)$this->DBParameter('data cache hit ratio');
$arr[1] = (float)$this->DBParameter('data reads');
$arr[2] = (float)$this->DBParameter('data writes');
$arr[3] = (integer) $this->DBParameter('current connections');
return $arr;
}
/*
Low-level Get Database Parameter
*/
function _DBParameter($sql)
{
$savelog = $this->conn->LogSQL(false);
if (is_array($sql)) {
global $ADODB_FETCH_MODE;
$sql1 = $sql[0];
$key = $sql[1];
if (sizeof($sql)>2) $pos = $sql[2];
else $pos = 1;
if (sizeof($sql)>3) $coef = $sql[3];
else $coef = false;
$ret = false;
$save = $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
$rs = $this->conn->Execute($sql1);
$ADODB_FETCH_MODE = $save;
if ($rs) {
while (!$rs->EOF) {
$keyf = reset($rs->fields);
if (trim($keyf) == $key) {
$ret = $rs->fields[$pos];
if ($coef) $ret *= $coef;
break;
}
$rs->MoveNext();
}
$rs->Close();
}
$this->conn->LogSQL($savelog);
return $ret;
} else {
if (strncmp($sql,'=',1) == 0) {
$fn = substr($sql,1);
return $this->$fn();
}
$sql = str_replace('$DATABASE',$this->conn->database,$sql);
$ret = $this->conn->GetOne($sql);
$this->conn->LogSQL($savelog);
return $ret;
}
}
/*
Warn if cache ratio falls below threshold. Displayed in "Description" column.
*/
function WarnCacheRatio($val)
{
if ($val < $this->warnRatio)
return 'Cache ratio should be at least '.$this->warnRatio.'%';
else return '';
}
/***********************************************************************************************/
// HIGH LEVEL UI FUNCTIONS
/***********************************************************************************************/
function UI($pollsecs=5)
{
global $HTTP_GET_VARS,$HTTP_SERVER_VARS,$HTTP_POST_VARS;
$perf_table = adodb_perf::table();
$conn = $this->conn;
$app = $conn->host;
if ($conn->host && $conn->database) $app .= ', db=';
$app .= $conn->database;
if ($app) $app .= ', ';
$savelog = $this->conn->LogSQL(false);
$info = $conn->ServerInfo();
if (isset($HTTP_GET_VARS['clearsql'])) {
$this->conn->Execute("delete from $perf_table");
}
$this->conn->LogSQL($savelog);
// magic quotes
if (isset($HTTP_GET_VARS['sql']) && get_magic_quotes_gpc()) {
$_GET['sql'] = $HTTP_GET_VARS['sql'] = str_replace(array("\\'",'\"'),array("'",'"'),$HTTP_GET_VARS['sql']);
}
if (!isset($_SESSION['ADODB_PERF_SQL'])) $nsql = $_SESSION['ADODB_PERF_SQL'] = 10;
else $nsql = $_SESSION['ADODB_PERF_SQL'];
$app .= $info['description'];
if (isset($HTTP_GET_VARS['do'])) $do = $HTTP_GET_VARS['do'];
else if (isset($HTTP_POST_VARS['do'])) $do = $HTTP_POST_VARS['do'];
else if (isset($HTTP_GET_VARS['sql'])) $do = 'viewsql';
else $do = 'stats';
if (isset($HTTP_GET_VARS['nsql'])) {
if ($HTTP_GET_VARS['nsql'] > 0) $nsql = $_SESSION['ADODB_PERF_SQL'] = (integer) $HTTP_GET_VARS['nsql'];
}
echo "ADOdb Performance Monitor on $app";
if ($do == 'viewsql') $form = " | ";
else $form = " | ";
$allowsql = !defined('ADODB_PERF_NO_RUN_SQL');
if (empty($HTTP_GET_VARS['hidem']))
echo "";
switch ($do) {
default:
case 'stats':
echo $this->HealthCheck();
//$this->conn->debug=1;
echo $this->CheckMemory();
break;
case 'poll':
echo "";
break;
case 'poll2':
echo "";
$this->Poll($pollsecs);
break;
case 'dosql':
if (!$allowsql) break;
$this->DoSQLForm();
break;
case 'viewsql':
if (empty($HTTP_GET_VARS['hidem']))
echo " Clear SQL Log
";
echo($this->SuspiciousSQL($nsql));
echo($this->ExpensiveSQL($nsql));
echo($this->InvalidSQL($nsql));
break;
case 'tables':
echo $this->Tables(); break;
}
global $ADODB_vers;
echo "";
}
/*
Runs in infinite loop, returning real-time statistics
*/
function Poll($secs=5)
{
$this->conn->fnExecute = false;
//$this->conn->debug=1;
if ($secs <= 1) $secs = 1;
echo "Accumulating statistics, every $secs seconds...\n";flush();
$arro =& $this->PollParameters();
$cnt = 0;
set_time_limit(0);
sleep($secs);
while (1) {
$arr =& $this->PollParameters();
$hits = sprintf('%2.2f',$arr[0]);
$reads = sprintf('%12.4f',($arr[1]-$arro[1])/$secs);
$writes = sprintf('%12.4f',($arr[2]-$arro[2])/$secs);
$sess = sprintf('%5d',$arr[3]);
$load = $this->CPULoad();
if ($load !== false) {
$oslabel = 'WS-CPU%';
$osval = sprintf(" %2.1f ",(float) $load);
}else {
$oslabel = '';
$osval = '';
}
if ($cnt % 10 == 0) echo " Time ".$oslabel." Hit% Sess Reads/s Writes/s\n";
$cnt += 1;
echo date('H:i:s').' '.$osval."$hits $sess $reads $writes\n";
flush();
if (connection_aborted()|| connection_timeout()) return;
sleep($secs);
$arro = $arr;
}
}
/*
Returns basic health check in a command line interface
*/
function HealthCheckCLI()
{
return $this->HealthCheck(true);
}
/*
Returns basic health check as HTML
*/
function HealthCheck($cli=false)
{
$saveE = $this->conn->fnExecute;
$this->conn->fnExecute = false;
if ($cli) $html = '';
else $html = $this->table.''.$this->conn->databaseType.' |
'.$this->titles;
$oldc = false;
$bgc = '';
foreach($this->settings as $name => $arr) {
if ($arr === false) break;
if (!is_string($name)) {
if ($cli) $html .= " -- $arr -- \n";
else $html .= "color>$arr |
";
continue;
}
if (!is_array($arr)) break;
$category = $arr[0];
$how = $arr[1];
if (sizeof($arr)>2) $desc = $arr[2];
else $desc = ' ';
if ($category == 'HIDE') continue;
$val = $this->_DBParameter($how);
if ($desc && strncmp($desc,"=",1) === 0) {
$fn = substr($desc,1);
$desc = $this->$fn($val);
}
if ($val === false) {
$m = $this->conn->ErrorMsg();
$val = "Error: $m";
} else {
if (is_numeric($val) && $val >= 256*1024) {
if ($val % (1024*1024) == 0) {
$val /= (1024*1024);
$val .= 'M';
} else if ($val % 1024 == 0) {
$val /= 1024;
$val .= 'K';
}
//$val = htmlspecialchars($val);
}
}
if ($category != $oldc) {
$oldc = $category;
//$bgc = ($bgc == ' bgcolor='.$this->color) ? ' bgcolor=white' : ' bgcolor='.$this->color;
}
if (strlen($desc)==0) $desc = ' ';
if (strlen($val)==0) $val = ' ';
if ($cli) {
$html .= str_replace(' ','',sprintf($this->cliFormat,strip_tags($name),strip_tags($val),strip_tags($desc)));
}else {
$html .= "".$name.' | '.$val.' | '.$desc." |
\n";
}
}
if (!$cli) $html .= "
\n";
$this->conn->fnExecute = $saveE;
return $html;
}
function Tables($orderby='1')
{
if (!$this->tablesSQL) return false;
$savelog = $this->conn->LogSQL(false);
$rs = $this->conn->Execute($this->tablesSQL.' order by '.$orderby);
$this->conn->LogSQL($savelog);
$html = rs2html($rs,false,false,false,false);
return $html;
}
function CreateLogTable()
{
if (!$this->createTableSQL) return false;
$savelog = $this->conn->LogSQL(false);
$ok = $this->conn->Execute($this->createTableSQL);
$this->conn->LogSQL($savelog);
return ($ok) ? true : false;
}
function DoSQLForm()
{
global $HTTP_SERVER_VARS,$HTTP_GET_VARS,$HTTP_POST_VARS,$HTTP_SESSION_VARS;
$HTTP_VARS = array_merge($HTTP_GET_VARS,$HTTP_POST_VARS);
$PHP_SELF = $HTTP_SERVER_VARS['PHP_SELF'];
$sql = isset($HTTP_VARS['sql']) ? $HTTP_VARS['sql'] : '';
if (isset($HTTP_SESSION_VARS['phplens_sqlrows'])) $rows = $HTTP_SESSION_VARS['phplens_sqlrows'];
else $rows = 3;
if (isset($HTTP_VARS['SMALLER'])) {
$rows /= 2;
if ($rows < 3) $rows = 3;
$HTTP_SESSION_VARS['phplens_sqlrows'] = $rows;
}
if (isset($HTTP_VARS['BIGGER'])) {
$rows *= 2;
$HTTP_SESSION_VARS['phplens_sqlrows'] = $rows;
}
?>
undomq(trim($sql));
if (substr($sql,strlen($sql)-1) === ';') {
$print = true;
$sqla = $this->SplitSQL($sql);
} else {
$print = false;
$sqla = array($sql);
}
foreach($sqla as $sqls) {
if (!$sqls) continue;
if ($print) {
print "".htmlspecialchars($sqls)."
";
flush();
}
$savelog = $this->conn->LogSQL(false);
$rs = $this->conn->Execute($sqls);
$this->conn->LogSQL($savelog);
if ($rs && is_object($rs) && !$rs->EOF) {
rs2html($rs);
while ($rs->NextRecordSet()) {
print "";
rs2html($rs);
}
} else {
$e1 = (integer) $this->conn->ErrorNo();
$e2 = $this->conn->ErrorMsg();
if (($e1) || ($e2)) {
if (empty($e1)) $e1 = '-1'; // postgresql fix
print ' '.$e1.': '.$e2;
} else {
print "No Recordset returned
";
}
}
} // foreach
}
function SplitSQL($sql)
{
$arr = explode(';',$sql);
return $arr;
}
function undomq(&$m)
{
if (get_magic_quotes_gpc()) {
// undo the damage
$m = str_replace('\\\\','\\',$m);
$m = str_replace('\"','"',$m);
$m = str_replace('\\\'','\'',$m);
}
return $m;
}
}
?> Neuinstallation/HTML_Code/adodb/adodb-perf.inc.php.#.LENS-03-09-05 0100444 0000002 0000002 00000065170 10330414152 0022536 0 ustar root root fnExecute = false;
$t0 = microtime();
$rs =& $conn->Execute($sql,$inputarr);
$t1 = microtime();
if (!empty($conn->_logsql)) {
$conn->_logsql = false; // disable logsql error simulation
$dbT = $conn->databaseType;
$a0 = split(' ',$t0);
$a0 = (float)$a0[1]+(float)$a0[0];
$a1 = split(' ',$t1);
$a1 = (float)$a1[1]+(float)$a1[0];
$time = $a1 - $a0;
if (!$rs) {
$errM = $conn->ErrorMsg();
$errN = $conn->ErrorNo();
$conn->lastInsID = 0;
$tracer = substr('ERROR: '.htmlspecialchars($errM),0,250);
} else {
$tracer = '';
$errM = '';
$errN = 0;
$dbg = $conn->debug;
$conn->debug = false;
if (!is_object($rs) || $rs->dataProvider == 'empty')
$conn->_affected = $conn->affected_rows(true);
$conn->lastInsID = @$conn->Insert_ID();
$conn->debug = $dbg;
}
if (isset($HTTP_SERVER_VARS['HTTP_HOST'])) {
$tracer .= '
'.$HTTP_SERVER_VARS['HTTP_HOST'];
if (isset($HTTP_SERVER_VARS['PHP_SELF'])) $tracer .= $HTTP_SERVER_VARS['PHP_SELF'];
} else
if (isset($HTTP_SERVER_VARS['PHP_SELF'])) $tracer .= '
'.$HTTP_SERVER_VARS['PHP_SELF'];
//$tracer .= (string) adodb_backtrace(false);
$tracer = substr($tracer,0,500);
if (is_array($inputarr)) {
if (is_array(reset($inputarr))) $params = 'Array sizeof='.sizeof($inputarr);
else {
$params = '';
$params = implode(', ',$inputarr);
if (strlen($params) >= 3000) $params = substr($params, 0, 3000);
}
} else {
$params = '';
}
if (is_array($sql)) $sql = $sql[0];
$arr = array('b'=>trim(substr($sql,0,230)),
'c'=>substr($sql,0,3900), 'd'=>$params,'e'=>$tracer,'f'=>adodb_round($time,6));
//var_dump($arr);
$saved = $conn->debug;
$conn->debug = 0;
if ($conn->dataProvider == 'oci8' && $dbT != 'oci8po') {
$isql = "insert into $perf_table values($conn->sysTimeStamp,:b,:c,:d,:e,:f)";
} else if ($dbT == 'odbc_mssql' || $dbT == 'informix') {
$timer = $arr['f'];
if ($dbT == 'informix') $sql2 = substr($sql2,0,230);
$sql1 = $conn->qstr($arr['b']);
$sql2 = $conn->qstr($arr['c']);
$params = $conn->qstr($arr['d']);
$tracer = $conn->qstr($arr['e']);
$isql = "insert into $perf_table (created,sql0,sql1,params,tracer,timer) values($conn->sysTimeStamp,$sql1,$sql2,$params,$tracer,$timer)";
if ($dbT == 'informix') $isql = str_replace(chr(10),' ',$isql);
$arr = false;
} else {
$isql = "insert into $perf_table (created,sql0,sql1,params,tracer,timer) values( $conn->sysTimeStamp,?,?,?,?,?)";
}
$ok = $conn->Execute($isql,$arr);
$conn->debug = $saved;
if ($ok) {
$conn->_logsql = true;
} else {
$err2 = $conn->ErrorMsg();
$conn->_logsql = true; // enable logsql error simulation
$perf =& NewPerfMonitor($conn);
if ($perf) {
if ($perf->CreateLogTable()) $ok = $conn->Execute($isql,$arr);
} else {
$ok = $conn->Execute("create table $perf_table (
created varchar(50),
sql0 varchar(250),
sql1 varchar(4000),
params varchar(3000),
tracer varchar(500),
timer decimal(16,6))");
}
if (!$ok) {
ADOConnection::outp( "LOGSQL Insert Failed: $isql
$err2");
$conn->_logsql = false;
}
}
$conn->_errorMsg = $errM;
$conn->_errorCode = $errN;
}
$conn->fnExecute = 'adodb_log_sql';
return $rs;
}
/*
The settings data structure is an associative array that database parameter per element.
Each database parameter element in the array is itself an array consisting of:
0: category code, used to group related db parameters
1: either
a. sql string to retrieve value, eg. "select value from v\$parameter where name='db_block_size'",
b. array holding sql string and field to look for, e.g. array('show variables','table_cache'),
c. a string prefixed by =, then a PHP method of the class is invoked,
e.g. to invoke $this->GetIndexValue(), set this array element to '=GetIndexValue',
2: description of the database parameter
*/
class adodb_perf {
var $conn;
var $color = '#F0F0F0';
var $table = '';
var $titles = 'Parameter | Value | Description |
';
var $warnRatio = 90;
var $tablesSQL = false;
var $cliFormat = "%32s => %s \r\n";
var $sql1 = 'sql1'; // used for casting sql1 to text for mssql
var $explain = true;
var $helpurl = "LogSQL help";
var $createTableSQL = false;
var $maxLength = 2000;
// Sets the tablename to be used
function table($newtable = false)
{
static $_table;
if (!empty($newtable)) $_table = $newtable;
if (empty($_table)) $_table = 'adodb_logsql';
return $_table;
}
// returns array with info to calculate CPU Load
function _CPULoad()
{
/*
cpu 524152 2662 2515228 336057010
cpu0 264339 1408 1257951 168025827
cpu1 259813 1254 1257277 168031181
page 622307 25475680
swap 24 1891
intr 890153570 868093576 6 0 4 4 0 6 1 2 0 0 0 124 0 8098760 2 13961053 0 0 0 0 0 0 0 0 0 0 0 0 0 16 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
disk_io: (3,0):(3144904,54369,610378,3090535,50936192) (3,1):(3630212,54097,633016,3576115,50951320)
ctxt 66155838
btime 1062315585
processes 69293
*/
// Algorithm is taken from
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/example__obtaining_raw_performance_data.asp
if (strncmp(PHP_OS,'WIN',3)==0) {
@$c = new COM("WinMgmts:{impersonationLevel=impersonate}!Win32_PerfRawData_PerfOS_Processor.Name='_Total'");
if (!$c) return false;
$info[0] = $c->PercentProcessorTime;
$info[1] = 0;
$info[2] = 0;
$info[3] = $c->TimeStamp_Sys100NS;
//print_r($info);
return $info;
}
// Algorithm - Steve Blinch (BlitzAffe Online, http://www.blitzaffe.com)
$statfile = '/proc/stat';
if (!file_exists($statfile)) return false;
$fd = fopen($statfile,"r");
if (!$fd) return false;
$statinfo = explode("\n",fgets($fd, 1024));
fclose($fd);
foreach($statinfo as $line) {
$info = explode(" ",$line);
if($info[0]=="cpu") {
array_shift($info); // pop off "cpu"
if(!$info[0]) array_shift($info); // pop off blank space (if any)
return $info;
}
}
return false;
}
/* NOT IMPLEMENTED */
function MemInfo()
{
/*
total: used: free: shared: buffers: cached:
Mem: 1055289344 917299200 137990144 0 165437440 599773184
Swap: 2146775040 11055104 2135719936
MemTotal: 1030556 kB
MemFree: 134756 kB
MemShared: 0 kB
Buffers: 161560 kB
Cached: 581384 kB
SwapCached: 4332 kB
Active: 494468 kB
Inact_dirty: 322856 kB
Inact_clean: 24256 kB
Inact_target: 168316 kB
HighTotal: 131064 kB
HighFree: 1024 kB
LowTotal: 899492 kB
LowFree: 133732 kB
SwapTotal: 2096460 kB
SwapFree: 2085664 kB
Committed_AS: 348732 kB
*/
}
/*
Remember that this is client load, not db server load!
*/
var $_lastLoad;
function CPULoad()
{
$info = $this->_CPULoad();
if (!$info) return false;
if (empty($this->_lastLoad)) {
sleep(1);
$this->_lastLoad = $info;
$info = $this->_CPULoad();
}
$last = $this->_lastLoad;
$this->_lastLoad = $info;
$d_user = $info[0] - $last[0];
$d_nice = $info[1] - $last[1];
$d_system = $info[2] - $last[2];
$d_idle = $info[3] - $last[3];
//printf("Delta - User: %f Nice: %f System: %f Idle: %f
",$d_user,$d_nice,$d_system,$d_idle);
if (strncmp(PHP_OS,'WIN',3)==0) {
if ($d_idle < 1) $d_idle = 1;
return 100*(1-$d_user/$d_idle);
}else {
$total=$d_user+$d_nice+$d_system+$d_idle;
if ($total<1) $total=1;
return 100*($d_user+$d_nice+$d_system)/$total;
}
}
function Tracer($sql)
{
$perf_table = adodb_perf::table();
$saveE = $this->conn->fnExecute;
$this->conn->fnExecute = false;
$sqlq = $this->conn->qstr($sql);
$arr = $this->conn->GetArray(
"select count(*),tracer
from $perf_table where sql1=$sqlq
group by tracer
order by 1 desc");
$s = '';
if ($arr) {
$s .= 'Scripts Affected
';
foreach($arr as $k) {
$s .= sprintf("%4d",$k[0]).' '.strip_tags($k[1]).'
';
}
}
$this->conn->fnExecute = $saveE;
return $s;
}
/*
Explain Plan for $sql.
If only a snippet of the $sql is passed in, then $partial will hold the crc32 of the
actual sql.
*/
function Explain($sql,$partial=false)
{
return false;
}
function InvalidSQL($numsql = 10)
{
global $HTTP_GET_VARS;
if (isset($HTTP_GET_VARS['sql'])) return;
$s = 'Invalid SQL
';
$saveE = $this->conn->fnExecute;
$this->conn->fnExecute = false;
$perf_table = adodb_perf::table();
$rs =& $this->conn->SelectLimit("select distinct count(*),sql1,tracer as error_msg from $perf_table where tracer like 'ERROR:%' group by sql1,tracer order by 1 desc",$numsql);//,$numsql);
$this->conn->fnExecute = $saveE;
if ($rs) {
$s .= rs2html($rs,false,false,false,false);
} else
return "$this->helpurl. ".$this->conn->ErrorMsg()."
";
return $s;
}
/*
This script identifies the longest running SQL
*/
function _SuspiciousSQL($numsql = 10)
{
global $ADODB_FETCH_MODE,$HTTP_GET_VARS;
$perf_table = adodb_perf::table();
$saveE = $this->conn->fnExecute;
$this->conn->fnExecute = false;
if (isset($HTTP_GET_VARS['exps']) && isset($HTTP_GET_VARS['sql'])) {
$partial = !empty($HTTP_GET_VARS['part']);
echo "".$this->Explain($HTTP_GET_VARS['sql'],$partial)."\n";
}
if (isset($HTTP_GET_VARS['sql'])) return;
$sql1 = $this->sql1;
$save = $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
//$this->conn->debug=1;
$rs =& $this->conn->SelectLimit(
"select avg(timer) as avg_timer,$sql1,count(*),max(timer) as max_timer,min(timer) as min_timer
from $perf_table
where {$this->conn->upperCase}({$this->conn->substr}(sql0,1,5)) not in ('DROP ','INSER','COMMI','CREAT')
and (tracer is null or tracer not like 'ERROR:%')
group by sql1
order by 1 desc",$numsql);
$ADODB_FETCH_MODE = $save;
$this->conn->fnExecute = $saveE;
if (!$rs) return "$this->helpurl. ".$this->conn->ErrorMsg()."
";
$s = "Suspicious SQL
The following SQL have high average execution times
Avg Time | Count | SQL | Max | Min |
\n";
$max = $this->maxLength;
while (!$rs->EOF) {
$sql = $rs->fields[1];
$raw = urlencode($sql);
if (strlen($raw)>$max-100) {
$sql2 = substr($sql,0,$max-500);
$raw = urlencode($sql2).'&part='.crc32($sql);
}
$prefix = "";
$suffix = "";
if ($this->explain == false || strlen($prefix)>$max) {
$suffix = ' ... String too long for GET parameter: '.strlen($prefix).'';
$prefix = '';
}
$s .= "".adodb_round($rs->fields[0],6)." | ".$rs->fields[2]." | ".$prefix.htmlspecialchars($sql).$suffix."".
" | ".$rs->fields[3]." | ".$rs->fields[4]." |
";
$rs->MoveNext();
}
return $s."
";
}
function CheckMemory()
{
return '';
}
function SuspiciousSQL($numsql=10)
{
return adodb_perf::_SuspiciousSQL($numsql);
}
function ExpensiveSQL($numsql=10)
{
return adodb_perf::_ExpensiveSQL($numsql);
}
/*
This reports the percentage of load on the instance due to the most
expensive few SQL statements. Tuning these statements can often
make huge improvements in overall system performance.
*/
function _ExpensiveSQL($numsql = 10)
{
global $HTTP_GET_VARS,$ADODB_FETCH_MODE;
$perf_table = adodb_perf::table();
$saveE = $this->conn->fnExecute;
$this->conn->fnExecute = false;
if (isset($HTTP_GET_VARS['expe']) && isset($HTTP_GET_VARS['sql'])) {
$partial = !empty($HTTP_GET_VARS['part']);
echo "".$this->Explain($HTTP_GET_VARS['sql'],$partial)."\n";
}
if (isset($HTTP_GET_VARS['sql'])) return;
$sql1 = $this->sql1;
$save = $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
$rs =& $this->conn->SelectLimit(
"select sum(timer) as total,$sql1,count(*),max(timer) as max_timer,min(timer) as min_timer
from $perf_table
where {$this->conn->upperCase}({$this->conn->substr}(sql0,1,5)) not in ('DROP ','INSER','COMMI','CREAT')
and (tracer is null or tracer not like 'ERROR:%')
group by sql1
order by 1 desc",$numsql);
$this->conn->fnExecute = $saveE;
$ADODB_FETCH_MODE = $save;
if (!$rs) return "$this->helpurl. ".$this->conn->ErrorMsg()."
";
$s = "Expensive SQL
Tuning the following SQL will reduce the server load substantially
Load | Count | SQL | Max | Min |
\n";
$max = $this->maxLength;
while (!$rs->EOF) {
$sql = $rs->fields[1];
$raw = urlencode($sql);
if (strlen($raw)>$max-100) {
$sql2 = substr($sql,0,$max-500);
$raw = urlencode($sql2).'&part='.crc32($sql);
}
$prefix = "";
$suffix = "";
if($this->explain == false || strlen($prefix>$max)) {
$prefix = '';
$suffix = '';
}
$s .= "".adodb_round($rs->fields[0],6)." | ".$rs->fields[2]." | ".$prefix.htmlspecialchars($sql).$suffix."".
" | ".$rs->fields[3]." | ".$rs->fields[4]." |
";
$rs->MoveNext();
}
return $s."
";
}
/*
Raw function to return parameter value from $settings.
*/
function DBParameter($param)
{
if (empty($this->settings[$param])) return false;
$sql = $this->settings[$param][1];
return $this->_DBParameter($sql);
}
/*
Raw function returning array of poll paramters
*/
function &PollParameters()
{
$arr[0] = (float)$this->DBParameter('data cache hit ratio');
$arr[1] = (float)$this->DBParameter('data reads');
$arr[2] = (float)$this->DBParameter('data writes');
$arr[3] = (integer) $this->DBParameter('current connections');
return $arr;
}
/*
Low-level Get Database Parameter
*/
function _DBParameter($sql)
{
$savelog = $this->conn->LogSQL(false);
if (is_array($sql)) {
global $ADODB_FETCH_MODE;
$sql1 = $sql[0];
$key = $sql[1];
if (sizeof($sql)>2) $pos = $sql[2];
else $pos = 1;
if (sizeof($sql)>3) $coef = $sql[3];
else $coef = false;
$ret = false;
$save = $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
$rs = $this->conn->Execute($sql1);
$ADODB_FETCH_MODE = $save;
if ($rs) {
while (!$rs->EOF) {
$keyf = reset($rs->fields);
if (trim($keyf) == $key) {
$ret = $rs->fields[$pos];
if ($coef) $ret *= $coef;
break;
}
$rs->MoveNext();
}
$rs->Close();
}
$this->conn->LogSQL($savelog);
return $ret;
} else {
if (strncmp($sql,'=',1) == 0) {
$fn = substr($sql,1);
return $this->$fn();
}
$sql = str_replace('$DATABASE',$this->conn->database,$sql);
$ret = $this->conn->GetOne($sql);
$this->conn->LogSQL($savelog);
return $ret;
}
}
/*
Warn if cache ratio falls below threshold. Displayed in "Description" column.
*/
function WarnCacheRatio($val)
{
if ($val < $this->warnRatio)
return 'Cache ratio should be at least '.$this->warnRatio.'%';
else return '';
}
/***********************************************************************************************/
// HIGH LEVEL UI FUNCTIONS
/***********************************************************************************************/
function UI($pollsecs=5)
{
global $HTTP_GET_VARS,$HTTP_SERVER_VARS,$HTTP_POST_VARS;
$perf_table = adodb_perf::table();
$conn = $this->conn;
$app = $conn->host;
if ($conn->host && $conn->database) $app .= ', db=';
$app .= $conn->database;
if ($app) $app .= ', ';
$savelog = $this->conn->LogSQL(false);
$info = $conn->ServerInfo();
if (isset($HTTP_GET_VARS['clearsql'])) {
$this->conn->Execute("delete from $perf_table");
}
$this->conn->LogSQL($savelog);
// magic quotes
if (isset($HTTP_GET_VARS['sql']) && get_magic_quotes_gpc()) {
$_GET['sql'] = $HTTP_GET_VARS['sql'] = str_replace(array("\\'",'\"'),array("'",'"'),$HTTP_GET_VARS['sql']);
}
if (!isset($_SESSION['ADODB_PERF_SQL'])) $nsql = $_SESSION['ADODB_PERF_SQL'] = 10;
else $nsql = $_SESSION['ADODB_PERF_SQL'];
$app .= $info['description'];
if (isset($HTTP_GET_VARS['do'])) $do = $HTTP_GET_VARS['do'];
else if (isset($HTTP_POST_VARS['do'])) $do = $HTTP_POST_VARS['do'];
else if (isset($HTTP_GET_VARS['sql'])) $do = 'viewsql';
else $do = 'stats';
if (isset($HTTP_GET_VARS['nsql'])) {
if ($HTTP_GET_VARS['nsql'] > 0) $nsql = $_SESSION['ADODB_PERF_SQL'] = (integer) $HTTP_GET_VARS['nsql'];
}
echo "ADOdb Performance Monitor on $app";
if ($do == 'viewsql') $form = " | ";
else $form = " | ";
$allowsql = !defined('ADODB_PERF_NO_RUN_SQL');
if (empty($HTTP_GET_VARS['hidem']))
echo "";
switch ($do) {
default:
case 'stats':
echo $this->HealthCheck();
//$this->conn->debug=1;
echo $this->CheckMemory();
break;
case 'poll':
echo "";
break;
case 'poll2':
echo "";
$this->Poll($pollsecs);
break;
case 'dosql':
if (!$allowsql) break;
$this->DoSQLForm();
break;
case 'viewsql':
if (empty($HTTP_GET_VARS['hidem']))
echo " Clear SQL Log
";
echo($this->SuspiciousSQL($nsql));
echo($this->ExpensiveSQL($nsql));
echo($this->InvalidSQL($nsql));
break;
case 'tables':
echo $this->Tables(); break;
}
global $ADODB_vers;
echo "";
}
/*
Runs in infinite loop, returning real-time statistics
*/
function Poll($secs=5)
{
$this->conn->fnExecute = false;
//$this->conn->debug=1;
if ($secs <= 1) $secs = 1;
echo "Accumulating statistics, every $secs seconds...\n";flush();
$arro =& $this->PollParameters();
$cnt = 0;
set_time_limit(0);
sleep($secs);
while (1) {
$arr =& $this->PollParameters();
$hits = sprintf('%2.2f',$arr[0]);
$reads = sprintf('%12.4f',($arr[1]-$arro[1])/$secs);
$writes = sprintf('%12.4f',($arr[2]-$arro[2])/$secs);
$sess = sprintf('%5d',$arr[3]);
$load = $this->CPULoad();
if ($load !== false) {
$oslabel = 'WS-CPU%';
$osval = sprintf(" %2.1f ",(float) $load);
}else {
$oslabel = '';
$osval = '';
}
if ($cnt % 10 == 0) echo " Time ".$oslabel." Hit% Sess Reads/s Writes/s\n";
$cnt += 1;
echo date('H:i:s').' '.$osval."$hits $sess $reads $writes\n";
flush();
sleep($secs);
$arro = $arr;
}
}
/*
Returns basic health check in a command line interface
*/
function HealthCheckCLI()
{
return $this->HealthCheck(true);
}
/*
Returns basic health check as HTML
*/
function HealthCheck($cli=false)
{
$saveE = $this->conn->fnExecute;
$this->conn->fnExecute = false;
if ($cli) $html = '';
else $html = $this->table.''.$this->conn->databaseType.' |
'.$this->titles;
$oldc = false;
$bgc = '';
foreach($this->settings as $name => $arr) {
if ($arr === false) break;
if (!is_string($name)) {
if ($cli) $html .= " -- $arr -- \n";
else $html .= "color>$arr |
";
continue;
}
if (!is_array($arr)) break;
$category = $arr[0];
$how = $arr[1];
if (sizeof($arr)>2) $desc = $arr[2];
else $desc = ' ';
if ($category == 'HIDE') continue;
$val = $this->_DBParameter($how);
if ($desc && strncmp($desc,"=",1) === 0) {
$fn = substr($desc,1);
$desc = $this->$fn($val);
}
if ($val === false) {
$m = $this->conn->ErrorMsg();
$val = "Error: $m";
} else {
if (is_numeric($val) && $val >= 256*1024) {
if ($val % (1024*1024) == 0) {
$val /= (1024*1024);
$val .= 'M';
} else if ($val % 1024 == 0) {
$val /= 1024;
$val .= 'K';
}
//$val = htmlspecialchars($val);
}
}
if ($category != $oldc) {
$oldc = $category;
//$bgc = ($bgc == ' bgcolor='.$this->color) ? ' bgcolor=white' : ' bgcolor='.$this->color;
}
if (strlen($desc)==0) $desc = ' ';
if (strlen($val)==0) $val = ' ';
if ($cli) {
$html .= str_replace(' ','',sprintf($this->cliFormat,strip_tags($name),strip_tags($val),strip_tags($desc)));
}else {
$html .= "".$name.' | '.$val.' | '.$desc." |
\n";
}
}
if (!$cli) $html .= "
\n";
$this->conn->fnExecute = $saveE;
return $html;
}
function Tables($orderby='1')
{
if (!$this->tablesSQL) return false;
$savelog = $this->conn->LogSQL(false);
$rs = $this->conn->Execute($this->tablesSQL.' order by '.$orderby);
$this->conn->LogSQL($savelog);
$html = rs2html($rs,false,false,false,false);
return $html;
}
function CreateLogTable()
{
if (!$this->createTableSQL) return false;
$savelog = $this->conn->LogSQL(false);
$ok = $this->conn->Execute($this->createTableSQL);
$this->conn->LogSQL($savelog);
return ($ok) ? true : false;
}
function DoSQLForm()
{
global $HTTP_SERVER_VARS,$HTTP_GET_VARS,$HTTP_POST_VARS,$HTTP_SESSION_VARS;
$HTTP_VARS = array_merge($HTTP_GET_VARS,$HTTP_POST_VARS);
$PHP_SELF = $HTTP_SERVER_VARS['PHP_SELF'];
$sql = isset($HTTP_VARS['sql']) ? $HTTP_VARS['sql'] : '';
if (isset($HTTP_SESSION_VARS['phplens_sqlrows'])) $rows = $HTTP_SESSION_VARS['phplens_sqlrows'];
else $rows = 3;
if (isset($HTTP_VARS['SMALLER'])) {
$rows /= 2;
if ($rows < 3) $rows = 3;
$HTTP_SESSION_VARS['phplens_sqlrows'] = $rows;
}
if (isset($HTTP_VARS['BIGGER'])) {
$rows *= 2;
$HTTP_SESSION_VARS['phplens_sqlrows'] = $rows;
}
?>
undomq(trim($sql));
if (substr($sql,strlen($sql)-1) === ';') {
$print = true;
$sqla = $this->SplitSQL($sql);
} else {
$print = false;
$sqla = array($sql);
}
foreach($sqla as $sqls) {
if (!$sqls) continue;
if ($print) {
print "".htmlspecialchars($sqls)."
";
flush();
}
$savelog = $this->conn->LogSQL(false);
$rs = $this->conn->Execute($sqls);
$this->conn->LogSQL($savelog);
if ($rs && is_object($rs) && !$rs->EOF) {
rs2html($rs);
while ($rs->NextRecordSet()) {
print "";
rs2html($rs);
}
} else {
$e1 = (integer) $this->conn->ErrorNo();
$e2 = $this->conn->ErrorMsg();
if (($e1) || ($e2)) {
if (empty($e1)) $e1 = '-1'; // postgresql fix
print ' '.$e1.': '.$e2;
} else {
print "No Recordset returned
";
}
}
} // foreach
}
function SplitSQL($sql)
{
$arr = explode(';',$sql);
return $arr;
}
function undomq(&$m)
{
if (get_magic_quotes_gpc()) {
// undo the damage
$m = str_replace('\\\\','\\',$m);
$m = str_replace('\"','"',$m);
$m = str_replace('\\\'','\'',$m);
}
return $m;
}
}
?> Neuinstallation/HTML_Code/adodb/adodb-php4.inc.php 0100444 0000002 0000002 00000000516 10330414152 0020675 0 ustar root root