@@ 22-67 (lines=46) @@ | ||
19 | * |
|
20 | * @author Franck Cassedanne <franck at ouarz.net> |
|
21 | */ |
|
22 | class Mysql extends AbstractPdo |
|
23 | { |
|
24 | ||
25 | /** |
|
26 | * Holds the SQL definitions for MySQL 3.x, 4.x and 5.x. |
|
27 | */ |
|
28 | protected $sql_definitions = array( |
|
29 | 'init' => 'CREATE TABLE IF NOT EXISTS %s (`key` VARCHAR(255) NOT NULL, |
|
30 | `data` LONGTEXT NULL, `tags` TEXT NULL, `expire` INTEGER |
|
31 | UNSIGNED, `dated` TIMESTAMP, PRIMARY KEY (`key`)) |
|
32 | ENGINE=MYISAM DEFAULT charset=utf8;', |
|
33 | 'key_idx' => 'CREATE INDEX `%s_key_idx` ON `%s` (`key`);', |
|
34 | 'exp_idx' => 'CREATE INDEX `%s_exp_idx` ON `%s` (`expire`);', |
|
35 | ||
36 | // 'tag_idx' will throw MYSQL ERROR 1170 -- if the index is needed then |
|
37 | // we should split keys and tags into diff tables and use varchar(255). |
|
38 | // 'tag_idx' => 'CREATE INDEX `%s_tag_idx` ON `%s` (`tags`);', |
|
39 | ||
40 | 'loadKey' => 'SELECT `data`, `expire` FROM `%s` WHERE `key`=:key AND |
|
41 | (`expire` IS NULL OR `expire` > :now);', |
|
42 | 'loadTag' => 'SELECT `key` FROM `%s` WHERE `tags` LIKE :tag AND |
|
43 | (`expire` IS NULL OR `expire` > :now);', |
|
44 | 'update' => 'UPDATE `%s` SET `data`=:data, `tags`=:tags, `expire`=:exp, |
|
45 | `dated`=:dated WHERE `key`=:key;', |
|
46 | 'insert' => 'INSERT INTO `%s` (`key`, `data`, `tags`, `expire`, `dated`) |
|
47 | VALUES (:key, :data, :tags, :exp, :dated);', |
|
48 | 'delete' => 'DELETE FROM `%s` WHERE `key`=?;', |
|
49 | 'clean' => 'DELETE FROM `%s` WHERE %s;', // %s 'clean_like' iterated |
|
50 | 'clean_like'=> 'tags LIKE ?', |
|
51 | 'flush_all' => 'DROP TABLE IF EXISTS `%s`;', |
|
52 | 'flush' => 'DELETE FROM `%s`;', |
|
53 | 'purge' => 'DELETE FROM `%s` WHERE `expire` IS NOT NULL AND `expire` < %d;' |
|
54 | ); |
|
55 | ||
56 | /** |
|
57 | * Constructor. |
|
58 | * |
|
59 | * @param \PDO $pdo |
|
60 | * @param array $options Array of options. |
|
61 | */ |
|
62 | public function __construct(\PDO $pdo, array $options=null) |
|
63 | { |
|
64 | parent::__construct($pdo, $options); |
|
65 | } |
|
66 | ||
67 | } |
|
68 |
@@ 22-62 (lines=41) @@ | ||
19 | * |
|
20 | * @author Franck Cassedanne <franck at ouarz.net> |
|
21 | */ |
|
22 | class Pgsql extends AbstractPdo |
|
23 | { |
|
24 | ||
25 | /** |
|
26 | * Holds the SQL definitions for PostgreSQL. |
|
27 | */ |
|
28 | protected $sql_definitions = array( |
|
29 | 'init' => 'CREATE TABLE IF NOT EXISTS "%s" |
|
30 | ("key" VARCHAR PRIMARY KEY, "data" TEXT, "tags" TEXT, |
|
31 | "expire" INTEGER, "dated" TIMESTAMP);', |
|
32 | 'key_idx' => 'CREATE INDEX "%s_key_idx" ON "%s" ("key");', |
|
33 | 'exp_idx' => 'CREATE INDEX "%s_exp_idx" ON "%s" ("expire");', |
|
34 | 'tag_idx' => 'CREATE INDEX "%s_tag_idx" ON "%s" ("tags");', |
|
35 | 'loadKey' => 'SELECT "data", "expire" FROM "%s" WHERE "key"=:key AND |
|
36 | ("expire" IS NULL OR "expire" > :now);', |
|
37 | 'loadTag' => 'SELECT "key" FROM "%s" WHERE "tags" LIKE :tag AND |
|
38 | ("expire" IS NULL OR "expire" > :now);', |
|
39 | 'update' => 'UPDATE "%s" SET "data"=:data, "tags"=:tags, "expire"=:exp, |
|
40 | "dated"=:dated WHERE "key"=:key;', |
|
41 | 'insert' => 'INSERT INTO "%s" ("key", "data", "tags", "expire", "dated") |
|
42 | VALUES (:key, :data, :tags, :exp, :dated);', |
|
43 | 'delete' => 'DELETE FROM "%s" WHERE "key"=?;', |
|
44 | 'clean' => 'DELETE FROM "%s" WHERE %s;', // %s 'clean_like' iterated |
|
45 | 'clean_like'=> 'tags LIKE ?', |
|
46 | 'flush_all' => 'DROP TABLE IF EXISTS "%s";', |
|
47 | 'flush' => 'DELETE FROM "%s";', |
|
48 | 'purge' => 'DELETE FROM "%s" WHERE "expire" IS NOT NULL AND "expire" < %d;' |
|
49 | ); |
|
50 | ||
51 | /** |
|
52 | * Constructor. |
|
53 | * |
|
54 | * @param \PDO $pdo |
|
55 | * @param array $options Array of options. |
|
56 | */ |
|
57 | public function __construct(\PDO $pdo, array $options=null) |
|
58 | { |
|
59 | parent::__construct($pdo, $options); |
|
60 | } |
|
61 | ||
62 | } |
|
63 |