Commit e2a65931 authored by bcosca's avatar bcosca
Browse files

Add entropy to SQL cache hash; Add uuid() method to DB backends

parent 5994d1be
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -73,6 +73,14 @@ class Jig {
		return $out;
	}

	/**
	*	Return UUID
	*	@return string
	**/
	function uuid() {
		return \Base::instance()->hash($this->dir);
	}

	/**
	*	Return SQL profiler results
	*	@return string
+11 −0
Original line number Diff line number Diff line
@@ -24,9 +24,19 @@ class Mongo extends \MongoDB {
	//@}

	private
		//! Data source name
		$dsn,
		//! MongoDB log
		$log;

	/**
	*	Return UUID
	*	@return string
	**/
	function uuid() {
		return \Base::instance()->hash($this->dsn);
	}

	/**
	*	Return MongoDB profiler results
	*	@return string
@@ -63,6 +73,7 @@ class Mongo extends \MongoDB {
	*	@param $options array
	**/
	function __construct($dsn,$dbname,array $options=NULL) {
		$this->dsn=$dsn;
		$class=class_exists('\MongoClient')?'\MongoClient':'\Mongo';
		parent::__construct(new $class($dsn,$options?:array()),$dbname);
		$this->setprofilinglevel(2);
+14 −2
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ namespace DB;
class SQL extends \PDO {

	private
		//! Data source name
		$dsn,
		//! Database engine
		$engine,
		//! Database name
@@ -112,8 +114,9 @@ class SQL extends \PDO {
			$now=microtime(TRUE);
			$keys=$vals=array();
			if ($fw->get('CACHE') && $ttl && ($cached=$cache->exists(
				$hash=$fw->hash($cmd.$fw->stringify($arg)).'.sql',
				$result)) && $cached[0]+$ttl>microtime(TRUE)) {
				$hash=$fw->hash($this->dsn.$cmd.
				$fw->stringify($arg)).'.sql',$result)) &&
				$cached[0]+$ttl>microtime(TRUE)) {
				foreach ($arg as $key=>$val) {
					$vals[]=$fw->stringify(is_array($val)?$val[0]:$val);
					$keys[]='/'.(is_numeric($key)?'\?':preg_quote($key)).'/';
@@ -276,6 +279,14 @@ class SQL extends \PDO {
			parent::quote($val,$type);
	}

	/**
	*	Return UUID
	*	@return string
	**/
	function uuid() {
		return \Base::instance()->hash($this->dsn);
	}

	/**
	*	Return database engine
	*	@return string
@@ -327,6 +338,7 @@ class SQL extends \PDO {
	*	@param $options array
	**/
	function __construct($dsn,$user=NULL,$pw=NULL,array $options=NULL) {
		$this->dsn=$dsn;
		if (preg_match('/^.+?(?:dbname|database)=(.+?)(?=;|$)/i',$dsn,$parts))
			$this->dbname=$parts[1];
		if (!$options)