Example #1
0
function &send2server($url, $sql)
{
    $url .= '?sql=' . urlencode($sql);
    print "<p>{$url}</p>";
    $rs = csv2rs($url, $err);
    if ($err) {
        print $err;
    }
    return $rs;
}
Example #2
0
 function &readcache($filename, &$err, $secs2cache, $rsClass)
 {
     $rs = csv2rs($filename, $err, $secs2cache, $rsClass);
     return $rs;
 }
Example #3
0
	/**
	 * Execute SQL, caching recordsets.
	 *
	 * @param [secs2cache]	seconds to cache data, set to 0 to force query. 
	 *					  This is an optional parameter.
	 * @param sql		SQL statement to execute
	 * @param [inputarr]	holds the input data  to bind to
	 * @return 		RecordSet or false
	 */
	function &CacheExecute($secs2cache,$sql=false,$inputarr=false)
	{
		if (!is_numeric($secs2cache)) {
			$inputarr = $sql;
			$sql = $secs2cache;
			$secs2cache = $this->cacheSecs;
		}
		global $ADODB_INCLUDED_CSV;
		if (empty($ADODB_INCLUDED_CSV)) include_once(ADODB_DIR.'/adodb-csvlib.inc.php');
		
		if (is_array($sql)) $sql = $sql[0];
			
		$md5file = $this->_gencachename($sql.serialize($inputarr),true);
		$err = '';
		
		if ($secs2cache > 0){
			$rs = &csv2rs($md5file,$err,$secs2cache);
			$this->numCacheHits += 1;
		} else {
			$err='Timeout 1';
			$rs = false;
			$this->numCacheMisses += 1;
		}
		if (!$rs) {
		// no cached rs found
			if ($this->debug) {
				if (get_magic_quotes_runtime()) {
					ADOConnection::outp("Please disable magic_quotes_runtime - it corrupts cache files :(");
				}
				if ($this->debug !== -1) ADOConnection::outp( " $md5file cache failure: $err (see sql below)");
			}
			
			$rs = &$this->Execute($sql,$inputarr);

			if ($rs) {
				$eof = $rs->EOF;
				$rs = &$this->_rs2rs($rs); // read entire recordset into memory immediately
				$txt = _rs2serialize($rs,false,$sql); // serialize
		
				if (!adodb_write_file($md5file,$txt,$this->debug)) {
					if ($fn = $this->raiseErrorFn) {
						$fn($this->databaseType,'CacheExecute',-32000,"Cache write error",$md5file,$sql,$this);
					}
					if ($this->debug) ADOConnection::outp( " Cache write error");
				}
				if ($rs->EOF && !$eof) {
					$rs->MoveFirst();
					//$rs = &csv2rs($md5file,$err);		
					$rs->connection = &$this; // Pablo suggestion
				}  
				
			} else
				@unlink($md5file);
		} else {
			$this->_errorMsg = '';
			$this->_errorCode = 0;
			
			if ($this->fnCacheExecute) {
				$fn = $this->fnCacheExecute;
				$fn($this, $secs2cache, $sql, $inputarr);
			}
		// ok, set cached object found
			$rs->connection = &$this; // Pablo suggestion
			if ($this->debug){ 
			global $HTTP_SERVER_VARS;
					
				$inBrowser = isset($HTTP_SERVER_VARS['HTTP_USER_AGENT']);
				$ttl = $rs->timeCreated + $secs2cache - time();
				$s = is_array($sql) ? $sql[0] : $sql;
				if ($inBrowser) $s = '<i>'.htmlspecialchars($s).'</i>';
				
				ADOConnection::outp( " $md5file reloaded, ttl=$ttl [ $s ]");
			}
		}
		return $rs;
	}
 function _Execute($sql, $inputarr = false)
 {
     global $ADODB_FETCH_MODE;
     if (!$this->_bindInputArray && $inputarr) {
         $sqlarr = explode('?', $sql);
         $sql = '';
         $i = 0;
         foreach ($inputarr as $v) {
             $sql .= $sqlarr[$i];
             if (gettype($v) == 'string') {
                 $sql .= $this->qstr($v);
             } else {
                 if ($v === null) {
                     $sql .= 'NULL';
                 } else {
                     $sql .= $v;
                 }
             }
             $i += 1;
         }
         $sql .= $sqlarr[$i];
         if ($i + 1 != sizeof($sqlarr)) {
             print "Input Array does not match ?: " . htmlspecialchars($sql);
         }
         $inputarr = false;
     }
     $url = $this->_url . '?sql=' . urlencode($sql) . "&fetch=" . ($this->fetchMode !== false ? $this->fetchMode : $ADODB_FETCH_MODE);
     $err = false;
     $rs = csv2rs($url, $err, false);
     if ($this->debug) {
         print urldecode($url) . "<br><i>{$err}</i><br>";
     }
     $at = strpos($err, '::::');
     if ($at === false) {
         $this->_errorMsg = $err;
         $this->_errorNo = (int) $err;
     } else {
         $this->_errorMsg = substr($err, $at + 4, 1024);
         $this->_errorNo = -9999;
     }
     if ($this->_errorNo) {
         if ($fn = $this->raiseErrorFn) {
             $fn($this->databaseType, 'EXECUTE', $this->ErrorNo(), $this->ErrorMsg(), $sql, $inputarr);
         }
     }
     if (is_object($rs)) {
         $rs->fetchMode = $this->fetchMode !== false ? $this->fetchMode : $ADODB_FETCH_MODE;
         $this->_affectedrows = $rs->affectedrows;
         $this->_insertid = $rs->insertid;
         $rs->databaseType = 'csv';
         $rs->connection = $this;
     }
     return $rs;
 }
 /**
  * Execute SQL, caching recordsets.
  *
  * @param [secs2cache]	seconds to cache data, set to 0 to force query. 
  *					  This is an optional parameter.
  * @param sql		SQL statement to execute
  * @param [inputarr]	holds the input data  to bind to
  * @return 		RecordSet or false
  */
 function CacheExecute($secs2cache, $sql = false, $inputarr = false)
 {
     if (!is_numeric($secs2cache)) {
         $inputarr = $sql;
         $sql = $secs2cache;
         $secs2cache = $this->cacheSecs;
     }
     if (is_array($sql)) {
         $sqlparam = $sql;
         $sql = $sql[0];
     } else {
         $sqlparam = $sql;
     }
     if ($this->memCache) {
         global $ADODB_INCLUDED_MEMCACHE;
         if (empty($ADODB_INCLUDED_MEMCACHE)) {
             include ADODB_DIR . '/adodb-memcache.lib.inc.php';
         }
         $md5file = $this->_gencachename($sql . serialize($inputarr), false, true);
     } else {
         global $ADODB_INCLUDED_CSV;
         if (empty($ADODB_INCLUDED_CSV)) {
             include ADODB_DIR . '/adodb-csvlib.inc.php';
         }
         $md5file = $this->_gencachename($sql . serialize($inputarr), true);
     }
     $err = '';
     if ($secs2cache > 0) {
         if ($this->memCache) {
             $rs = getmemCache($md5file, $err, $secs2cache, $this->memCacheHost, $this->memCachePort);
         } else {
             $rs = csv2rs($md5file, $err, $secs2cache, $this->arrayClass);
         }
         $this->numCacheHits += 1;
     } else {
         $err = 'Timeout 1';
         $rs = false;
         $this->numCacheMisses += 1;
     }
     if (!$rs) {
         // no cached rs found
         if ($this->debug) {
             if (get_magic_quotes_runtime() && !$this->memCache) {
                 ADOConnection::outp("Please disable magic_quotes_runtime - it corrupts cache files :(");
             }
             if ($this->debug !== -1) {
                 ADOConnection::outp(" {$md5file} cache failure: {$err} (see sql below)");
             }
         }
         $rs = $this->Execute($sqlparam, $inputarr);
         if ($rs && $this->memCache) {
             $rs = $this->_rs2rs($rs);
             // read entire recordset into memory immediately
             if (!putmemCache($md5file, $rs, $this->memCacheHost, $this->memCachePort, $this->memCacheCompress, $this->debug)) {
                 if ($fn = $this->raiseErrorFn) {
                     $fn($this->databaseType, 'CacheExecute', -32000, "Cache write error", $md5file, $sql, $this);
                 }
                 if ($this->debug) {
                     ADOConnection::outp(" Cache write error");
                 }
             }
         } else {
             if ($rs) {
                 $eof = $rs->EOF;
                 $rs = $this->_rs2rs($rs);
                 // read entire recordset into memory immediately
                 $txt = _rs2serialize($rs, false, $sql);
                 // serialize
                 if (!adodb_write_file($md5file, $txt, $this->debug)) {
                     if ($fn = $this->raiseErrorFn) {
                         $fn($this->databaseType, 'CacheExecute', -32000, "Cache write error", $md5file, $sql, $this);
                     }
                     if ($this->debug) {
                         ADOConnection::outp(" Cache write error");
                     }
                 }
                 if ($rs->EOF && !$eof) {
                     $rs->MoveFirst();
                     //$rs = csv2rs($md5file,$err);
                     $rs->connection = $this;
                     // Pablo suggestion
                 }
             } else {
                 if (!$this->memCache) {
                     @unlink($md5file);
                 }
             }
         }
     } else {
         $this->_errorMsg = '';
         $this->_errorCode = 0;
         if ($this->fnCacheExecute) {
             $fn = $this->fnCacheExecute;
             $fn($this, $secs2cache, $sql, $inputarr);
         }
         // ok, set cached object found
         $rs->connection = $this;
         // Pablo suggestion
         if ($this->debug) {
             $inBrowser = isset($_SERVER['HTTP_USER_AGENT']);
             $ttl = $rs->timeCreated + $secs2cache - time();
             $s = is_array($sql) ? $sql[0] : $sql;
             if ($inBrowser) {
                 $s = '<i>' . htmlspecialchars($s) . '</i>';
             }
             ADOConnection::outp(" {$md5file} reloaded, ttl={$ttl} [ {$s} ]");
         }
     }
     return $rs;
 }
Example #6
0
 function Execute($sql, $inputarr = false, $arg3 = false)
 {
     $url = $this->_url . '?sql=' . urlencode($sql);
     if ($arg3) {
         $url .= "&arg3=" . urlencode($arg3);
     }
     $err = false;
     $rs = csv2rs($url, $err, false);
     if ($this->debug) {
         print urldecode($url) . "<br><i>{$err}</i><br>";
     }
     $at = strpos($err, '::::');
     if ($at === false) {
         $this->_errorMsg = $err;
         $this->_errorNo = (int) $err;
     } else {
         $this->_errorMsg = substr($err, $at + 4, 1024);
         $this->_errorNo = -9999;
     }
     if (is_object($rs)) {
         $this->_affectedrows = $rs->affectedrows;
         $this->_insertid = $rs->insertid;
         $rs->databaseType = 'csv';
     }
     return $rs;
 }
Example #7
0
 /**
  * Execute SQL, caching recordsets.
  *
  * @param secs2cache	seconds to cache data, set to 0 to force query
  * @param sql		SQL statement to execute
  * @param [inputarr]	holds the input data  to bind to
  * @param [arg3]	reserved for john lim for future use
  * @return 		RecordSet or false
  */
 function &CacheExecute($secs2cache, $sql, $inputarr = false, $arg3 = false)
 {
     $md5file = $this->_gencachename($sql);
     $err = '';
     if ($secs2cache > 0) {
         $rs =& csv2rs($md5file, $err, $secs2cache);
     } else {
         $err = 'Timeout 1';
         $rs = false;
     }
     if (!$rs) {
         if ($this->debug) {
             print " {$md5file} cache failure: {$err}<br>";
         }
         $rs =& $this->Execute($sql, $inputarr, $arg3);
         if ($rs) {
             $eof = $rs->EOF;
             $rs =& $this->_rs2rs($rs);
             $txt =& rs2csv($rs, false, $sql);
             if (!adodb_write_file($md5file, $txt, $this->debug) && $this->debug) {
                 print ' Cache write error<br>';
             }
             if ($rs->EOF && !$eof) {
                 $rs =& csv2rs($md5file, $err);
             }
         } else {
             @unlink($md5file);
         }
     } else {
         if ($this->debug) {
             $ttl = $rs->timeCreated + $secs2cache - time();
             print " {$md5file} success ttl={$ttl}<br>";
         }
     }
     return $rs;
 }
Example #8
0
 /**
  * Execute SQL, caching recordsets.
  *
  * @param secs2cache	seconds to cache data, set to 0 to force query
  * @param sql		SQL statement to execute
  * @param [inputarr]	holds the input data  to bind to
  * @param [arg3]	reserved for john lim for future use
  * @return 		RecordSet or false
  */
 function &CacheExecute($secs2cache, $sql, $inputarr = false, $arg3 = false)
 {
     include_once ADODB_DIR . '/adodb-csvlib.inc.php';
     // cannot cache if $inputarr set
     if ($inputarr) {
         return $this->Execute($sql, $inputarr, $arg3);
     }
     $md5file = $this->_gencachename($sql);
     $err = '';
     if ($secs2cache > 0) {
         $rs =& csv2rs($md5file, $err, $secs2cache);
     } else {
         $err = 'Timeout 1';
         $rs = false;
     }
     if (!$rs) {
         // no cached rs found
         if ($this->debug) {
             print " {$md5file} cache failure: {$err}<br>";
         }
         $rs =& $this->Execute($sql, $inputarr, $arg3);
         if ($rs) {
             $eof = $rs->EOF;
             $rs =& $this->_rs2rs($rs);
             $txt =& rs2csv($rs, false, $sql);
             if (!adodb_write_file($md5file, $txt, $this->debug) && $this->debug) {
                 print ' Cache write error<br>';
             }
             if ($rs->EOF && !$eof) {
                 $rs =& csv2rs($md5file, $err);
                 $rs->connection =& $this;
                 // Pablo suggestion
             }
         } else {
             @unlink($md5file);
         }
     } else {
         // ok, set cached object found
         $rs->connection =& $this;
         // Pablo suggestion
         if ($this->debug) {
             $ttl = $rs->timeCreated + $secs2cache - time();
             print " {$md5file} success ttl={$ttl}<br>";
         }
     }
     return $rs;
 }
 /**
  * Execute SQL, caching recordsets.
  *
  * @param [secs2cache]	seconds to cache data, set to 0 to force query. 
  *                  This is an optional parameter.
  * @param sql       SQL statement to execute
  * @param [inputarr]    holds the input data  to bind to
  * @param [arg3]    reserved for john lim for future use
  * @return      RecordSet or false
  */
 function &CacheExecute($secs2cache, $sql = false, $inputarr = false, $arg3 = false)
 {
     if (!is_numeric($secs2cache)) {
         $arg3 = $inputarr;
         $inputarr = $sql;
         $sql = $secs2cache;
         $secs2cache = $this->cacheSecs;
     }
     include_once ADODB_DIR . '/adodb-csvlib.inc.php';
     $md5file = $this->_gencachename($sql . serialize($inputarr), true);
     $err = '';
     if ($secs2cache > 0) {
         $rs =& csv2rs($md5file, $err, $secs2cache);
         $this->numCacheHits += 1;
     } else {
         $err = 'Timeout 1';
         $rs = false;
         $this->numCacheMisses += 1;
     }
     if (!$rs) {
         /*  no cached rs found */
         if ($this->debug) {
             if (get_magic_quotes_runtime()) {
                 ADOConnection::outp("Please disable magic_quotes_runtime - it corrupts cache files :(");
             }
             ADOConnection::outp(" {$md5file} cache failure: {$err} (see sql below)");
         }
         $rs =& $this->Execute($sql, $inputarr, $arg3);
         if ($rs) {
             $eof = $rs->EOF;
             $rs =& $this->_rs2rs($rs);
             /*  read entire recordset into memory immediately */
             $txt = _rs2serialize($rs, false, $sql);
             /*  serialize */
             if (!adodb_write_file($md5file, $txt, $this->debug)) {
                 if ($fn = $this->raiseErrorFn) {
                     $fn($this->databaseType, 'CacheExecute', -32000, "Cache write error", $md5file, $sql, $this);
                 }
                 if ($this->debug) {
                     ADOConnection::outp(" Cache write error");
                 }
             }
             if ($rs->EOF && !$eof) {
                 $rs->MoveFirst();
                 /* $rs = &csv2rs($md5file,$err);		 */
                 $rs->connection =& $this;
                 /*  Pablo suggestion */
             }
         } else {
             @unlink($md5file);
         }
     } else {
         if ($this->fnCacheExecute) {
             $fn = $this->fnCacheExecute;
             $fn($this, $secs2cache, $sql, $inputarr);
         }
         /*  ok, set cached object found */
         $rs->connection =& $this;
         /*  Pablo suggestion */
         if ($this->debug) {
             global $HTTP_SERVER_VARS;
             $inBrowser = isset($HTTP_SERVER_VARS['HTTP_USER_AGENT']);
             $ttl = $rs->timeCreated + $secs2cache - time();
             $s = is_array($sql) ? $sql[0] : $sql;
             if ($inBrowser) {
                 $s = '<i>' . htmlspecialchars($s) . '</i>';
             }
             ADOConnection::outp(" {$md5file} reloaded, ttl={$ttl} [ {$s} ]");
         }
     }
     return $rs;
 }