From 2c48bf162f2a8e7cf13e8c53b1205cc0f65132e5 Mon Sep 17 00:00:00 2001 From: xue <> Date: Wed, 6 Feb 2008 18:01:14 +0000 Subject: Fixed ticket#766, #786 - TDbCache does not work with MySQL and PostgreSQL --- framework/Caching/TDbCache.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'framework/Caching/TDbCache.php') diff --git a/framework/Caching/TDbCache.php b/framework/Caching/TDbCache.php index bc4d4309..90607368 100644 --- a/framework/Caching/TDbCache.php +++ b/framework/Caching/TDbCache.php @@ -31,10 +31,10 @@ Prado::using('System.Data.TDbConnection'); * The cached data is stored in a table in the specified database. * By default, the name of the table is called 'pradocache'. If the table does not * exist in the database, it will be automatically created with the following structure: - * (key CHAR(128) PRIMARY KEY, value BLOB, expire INT) + * (itemkey CHAR(128) PRIMARY KEY, value BLOB, expire INT) * - * Note, if you are using MySQL, you may want to manually create the DB table by relacing - * BLOB with LONGBLOB. Some users reported that BLOB may cause problems in MySQL. + * Note, some DBMS might not support BLOB type. In this case, replace 'BLOB' with a suitable + * binary data type (e.g. LONGBLOB in MySQL, BYTEA in PostgreSQL.) * * If you want to change the cache table name, or if you want to create the table by yourself, * you may set {@link setCacheTableName CacheTableName} and {@link setAutoCreateCacheTable AutoCreateCacheTableName} properties. @@ -134,7 +134,15 @@ class TDbCache extends TCache // DB table not exists if($this->_autoCreate) { - $sql='CREATE TABLE '.$this->_cacheTable.' (itemkey CHAR(128) PRIMARY KEY, value BLOB, expire INT)'; + $driver=$db->getDriverName(); + if($driver==='mysql') + $blob='LONGBLOB'; + else if($driver==='pgsql') + $blob='BYTEA'; + else + $blob='BLOB'; + + $sql='CREATE TABLE '.$this->_cacheTable." (itemkey CHAR(128) PRIMARY KEY, value $blob, expire INT)"; $db->createCommand($sql)->execute(); } else @@ -276,7 +284,9 @@ class TDbCache extends TCache * Note, if {@link setAutoCreateCacheTable AutoCreateCacheTable} is false * and you want to create the DB table manually by yourself, * you need to make sure the DB table is of the following structure: - * (key CHAR(128) PRIMARY KEY, value BLOB, expire INT) + * (itemkey CHAR(128) PRIMARY KEY, value BLOB, expire INT) + * Note, some DBMS might not support BLOB type. In this case, replace 'BLOB' with a suitable + * binary data type (e.g. LONGBLOB in MySQL, BYTEA in PostgreSQL.) * @param string the name of the DB table to store cache content * @see setAutoCreateCacheTable */ -- cgit v1.2.3