diff options
author | xue <> | 2008-02-06 18:01:14 +0000 |
---|---|---|
committer | xue <> | 2008-02-06 18:01:14 +0000 |
commit | 2c48bf162f2a8e7cf13e8c53b1205cc0f65132e5 (patch) | |
tree | a423b807a5016684ba8b97dac19f5118adca7beb /framework | |
parent | abe35ff7bb2b7bdca24ac39e57be7a0b3ed4a330 (diff) |
Fixed ticket#766, #786 - TDbCache does not work with MySQL and PostgreSQL
Diffstat (limited to 'framework')
-rw-r--r-- | framework/Caching/TDbCache.php | 20 | ||||
-rw-r--r-- | framework/Data/TDbCommand.php | 5 |
2 files changed, 19 insertions, 6 deletions
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
*/
diff --git a/framework/Data/TDbCommand.php b/framework/Data/TDbCommand.php index caa4476b..90e86844 100644 --- a/framework/Data/TDbCommand.php +++ b/framework/Data/TDbCommand.php @@ -276,7 +276,10 @@ class TDbCommand extends TComponent $this->_statement=$this->getConnection()->getPdoInstance()->query($this->getText());
$result=$this->_statement->fetchColumn();
$this->_statement->closeCursor();
- return $result;
+ if(is_resource($result) && get_resource_type($result)==='stream')
+ return stream_get_contents($result);
+ else
+ return $result;
}
catch(Exception $e)
{
|