sql = $sql; $this->variables = $variables; } public function append($querylet) { assert(!is_null($querylet)); $this->sql .= $querylet->sql; $this->variables = array_merge($this->variables, $querylet->variables); } public function append_sql($sql) { $this->sql .= $sql; } public function add_variable($var) { $this->variables[] = $var; } } class TagQuerylet { var $tag; var $positive; public function TagQuerylet($tag, $positive) { $this->tag = $tag; $this->positive = $positive; } } class ImgQuerylet { var $qlet; var $positive; public function ImgQuerylet($qlet, $positive) { $this->qlet = $qlet; $this->positive = $positive; } } // }}} // {{{ db engines class DBEngine { var $name = null; var $auto_increment = null; var $create_table_extras = ""; } class MySQL extends DBEngine { var $name = "mysql"; var $auto_increment = "INTEGER PRIMARY KEY auto_increment"; var $create_table_extras = "TYPE=INNODB DEFAULT CHARSET='utf8'"; function init($db) { $db->Execute("SET NAMES utf8;"); } } class PostgreSQL extends DBEngine { var $name = "pgsql"; var $auto_increment = "SERIAL PRIMARY KEY"; function init($db) { } } // }}} // {{{ cache engines interface CacheEngine { var $db; public function cache_get($key); public function cache_set($key, $val, $time); public function cache_delete($key); } class MemCache implements CacheEngine { public function __construct(Database $db) { $this->db = $db; } public function cache_get($key) { assert(!is_null($key)); $val = $this->db->memcache->get($key); if($val) { $this->cache_hits++; return $val; } else { $this->cache_misses++; return false; } } public function cache_set($key, $val, $time=0) { assert(!is_null($key)); $this->db->memcache->set($key, $val, false, $time); } public function cache_delete($key) { assert(!is_null($key)); $this->db->memcache->delete($key); } } // }}} /* * A class for controlled database access */ class Database { var $db; var $extensions; var $cache_hits = 0, $cache_misses = 0; var $engine = null; var $cache = null; /* * Create a new database object using connection info * stored in config.php in the root shimmie folder */ public function Database() { if(is_readable("config.php")) { require_once "config.php"; $this->engine = new MySQL(); $this->db = @NewADOConnection($database_dsn); $this->use_memcache = isset($memcache); if(isset($memcache)) { $this->cache = new MemCache($this); } if(isset($cache)) { //$matches = array(); //preg_match("#(memcache)://#", $cache, $matches); } if($this->db) { $this->db->SetFetchMode(ADODB_FETCH_ASSOC); $this->engine->init($this->db); } else { $version = VERSION; print "
"; var_dump($sql); echo ""; $result = $schema->ExecuteSchema(); if(!$result) { die("Error creating tables from XML schema ($filename)"); } $config->set_bool("in_upgrade", false); } // }}} } ?>