rendered paste body// Nottez qu'il reste possiblement quelque bugsclass CuteDB_Query { private $sql = ""; private $sql_template = ""; private $arguments = array(); private $name = ""; private $abilities = ""; private $res = false; public function __construct($sql, $abilities = array(), $name = '') { if (strin($sql, '$')) { $this->sql_template = $sql; } else { $this->sql = $sql; } $this->abilities = $abilities; $this->name = $name; return true; } public function __get($key) { $_return = false; if (isset($this->$key) && $this->$key) { $_return = $this->$key; } elseif ($key == 'res') { return CuteDB::getInstance()->query($this->sql); } return $_return; } public function sql() { $args = func_get_args(); $o_db = CuteDB::getInstance(); $find = array('($prefix)'); $replace = array($o_db->prefix); $sql = str_ireplace($find, $replace, $this->sql_template); foreach ($args as $v) { if (!is_array($v) && !is_object($v)) { // Todo } elseif (is_object($v)) { $sql = preg_replace('/\(\$([^\)]*)\)/e', "\$v->\\1", $sql); } elseif (is_array($v)) { $sql = preg_replace('/\(\$([^\)]*)\)/e', "\$v['\\1']", $sql); } } $this->sql = $sql; } public function query($query_args = null) { $o_db = CuteDB::getInstance(); $this->sql($query_args); $this->res = $o_db->query($this->sql); return $this->res; } public function fetch_assoc($query_args = null) { if (!$this->res) { $this->query($query_args); } return CuteDB::getInstance()->fetch_assoc($this->res); } public static function factory($m_sql, $abilities = array(), $name = '') { if (is_array($m_sql)) { if (isset($m_sql['sql'])) { $s_sql = $m_sql['sql']; } if (isset($m_sql['abilities'])) { $abilities = $m_sql['abilities']; } if (isset($m_sql['name'])) { $name = $m_sql['name']; } } elseif (is_string($m_sql)) { $s_sql = $m_sql; } if (is_string($abilities)) { $abilities = array($abilities); } if (!isset($s_sql) || !is_string($s_sql) || !$s_sql) { return false; } $o_query = new CuteDB_Query($s_sql, $abilities, $name); return $o_query; }}class CuteDB_QueryList { private $queries = array(); private $queryCount = 0; protected $currentQuery = 0; public function __construct() { } public function getQueryCount() { return $this->queryCount; } private function setQueryCount($newCount) { $this->queryCount = $newCount; } public function getQuery($m_queryToGet) { $_return = false; if (is_numeric($m_queryToGet)) { $_return = $this->getQueryNumber($m_queryToGet); } elseif (is_string($m_queryToGet)) { $_return = $this->getQueryName($m_queryToGet); } if (!$_return) { Logger::Log(DEBUG, array('tmsg'=> 'Query not found : '.$m_queryToGet)); } return $_return; } private function getQueryName($queryNameToGet) { if ( is_string($queryNameToGet) ) { $this->resetCurrentQuery(); while (@$o_query->name != $queryNameToGet) { $o_query = $this->getNextQuery(); } return $o_query; } return false; } private function getQueryNumber($queryNumberToGet) { if ( (is_numeric($queryNumberToGet)) && ($queryNumberToGet <= $this->getQueryCount())) { return $this->queries[$queryNumberToGet]; } else { return NULL; } } public function newQ($a_query_in) { return $this->addQuery(new CuteDB_Query($a_query_in)); } public function addQuery(CuteDB_Query $query_in) { $this->setQueryCount($this->getQueryCount() + 1); $this->queries[$this->getQueryCount()] = $query_in; return $this->getQueryCount(); } public function removeQuery(CuteDB_Query $query_in) { $counter = 0; while (++$counter <= $this->getQueryCount()) { if ($query_in->getAuthorAndTitle() == $this->queries[$counter]->getAuthorAndTitle()) { for ($x = $counter; $x < $this->getQueryCount(); $x++) { $this->queries[$x] = $this->queries[$x + 1]; } $this->setQueryCount($this->getQueryCount() - 1); } } return $this->getQueryCount(); } public function getCurrentQuery() { if (($this->currentQuery > 0) && ($this->getQueryCount() >= $this->currentQuery)) { return $this->getQuery($this->currentQuery); } } public function resetCurrentQuery() { $this->currentQuery = 0; } public function getNextQuery() { if ($this->hasNextQuery()) { return $this->getQuery(++$this->currentQuery); } else { return NULL; } } public function hasNextQuery() { if ($this->getQueryCount() > $this->currentQuery) { return TRUE; } else { return FALSE; } }}