From a8b3ebe8f62c3888b216d827c1c5dcba8a47d4e1 Mon Sep 17 00:00:00 2001 From: wei <> Date: Sun, 26 Nov 2006 22:15:58 +0000 Subject: Adding active record implementation. --- .../Data/ActiveRecord/Vendor/TMysqlMetaData.php | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 framework/Data/ActiveRecord/Vendor/TMysqlMetaData.php (limited to 'framework/Data/ActiveRecord/Vendor/TMysqlMetaData.php') diff --git a/framework/Data/ActiveRecord/Vendor/TMysqlMetaData.php b/framework/Data/ActiveRecord/Vendor/TMysqlMetaData.php new file mode 100644 index 00000000..7902146d --- /dev/null +++ b/framework/Data/ActiveRecord/Vendor/TMysqlMetaData.php @@ -0,0 +1,47 @@ + + * @version $Id$ + * @package System.Data.ActiveRecord.Vendor + */ + +Prado::using('System.Data.ActiveRecord.Vendor.TDbMetaDataCommon'); + +/** + * TMysqlMetaData specialized command builder for Mysql database. + * + * @author Wei Zhuo + * @version $Id$ + * @package System.Data.ActiveRecord.Vendor + * @since 3.1 + */ +class TMysqlMetaData extends TDbMetaDataCommon +{ + /** + * Build the SQL search string from the criteria object for Postgress database. + * @param TActiveRecordCriteria search criteria. + * @return string SQL search. + */ + protected function getSqlFromCriteria(TActiveRecordCriteria $criteria) + { + $sql = ''; + if(($condition = $criteria->getCondition())!==null) + $sql .= $condition; + $orders=array(); + foreach($criteria->getOrdersBy() as $by=>$ordering) + $orders[] = $by.' '.$ordering; + if(count($orders) > 0) + $sql .= ' ORDER BY '.implode(', ', $orders); + if(($limit = $criteria->getLimit())!==null) + { + $offset = $criteria->getOffset(); + $offset = $offset===null?0:$offset; + $sql .= ' LIMIT '.$offset.', '.$limit; + } + return strlen($sql) > 0 ? ' WHERE '.$sql : ''; + } +} + +?> \ No newline at end of file -- cgit v1.2.3