summaryrefslogtreecommitdiff
path: root/framework/Data/Common/TDbMetaData.php
diff options
context:
space:
mode:
authorGODZilla0480@gmail.com <>2011-08-28 06:24:03 +0000
committerGODZilla0480@gmail.com <>2011-08-28 06:24:03 +0000
commitfb494d1e299e256721cba77105a01b7480c48c08 (patch)
tree60a126bd254916501f45f8034108a77c580bd0bc /framework/Data/Common/TDbMetaData.php
parent5ad92b6fe39f04aad8d94f32d23c7e665725fe8c (diff)
Add methods quoteTableName, quoteColumnName, quoteColumnAlias to TDbMetaData & TDbConnection and add TDbConnection:getDbMetaData [TODO: customize TOracleMetaData]
Diffstat (limited to 'framework/Data/Common/TDbMetaData.php')
-rw-r--r--framework/Data/Common/TDbMetaData.php48
1 files changed, 48 insertions, 0 deletions
diff --git a/framework/Data/Common/TDbMetaData.php b/framework/Data/Common/TDbMetaData.php
index 13f2eeb9..bc29927f 100644
--- a/framework/Data/Common/TDbMetaData.php
+++ b/framework/Data/Common/TDbMetaData.php
@@ -27,6 +27,11 @@ abstract class TDbMetaData extends TComponent
private $_connection;
/**
+ * @var array
+ */
+ protected static $delimiterIdentifier = array('[', ']', '"', '`', "'");
+
+ /**
* @param TDbConnection database connection.
*/
public function __construct($conn)
@@ -119,5 +124,48 @@ abstract class TDbMetaData extends TComponent
{
return 'TDbTableInfo';
}
+
+ /**
+ * Quotes a table name for use in a query.
+ * @param string $name table name
+ * @param string $lft left delimiter
+ * @param string $rgt right delimiter
+ * @return string the properly quoted table name
+ */
+ public function quoteTableName($name, $lft='', $rgt='')
+ {
+ $name = str_replace(self::$delimiterIdentifier, '', $name);
+
+ if(strpos($name, '.')===false)
+ return $lft . $name . $rgt;
+ $names=explode('.', $name);
+ foreach($names as &$n)
+ $n = $lft . $n . $rgt;
+ return implode('.', $names);
+ }
+
+ /**
+ * Quotes a column name for use in a query.
+ * @param string $name column name
+ * @param string $lft left delimiter
+ * @param string $rgt right delimiter
+ * @return string the properly quoted column name
+ */
+ public function quoteColumnName($name, $lft='', $rgt='')
+ {
+ return $lft . str_replace(self::$delimiterIdentifier, '', $name) . $rgt;
+ }
+
+ /**
+ * Quotes a column alias for use in a query.
+ * @param string $name column alias
+ * @param string $lft left delimiter
+ * @param string $rgt right delimiter
+ * @return string the properly quoted column alias
+ */
+ public function quoteColumnAlias($name, $lft='', $rgt='')
+ {
+ return $lft . str_replace(self::$delimiterIdentifier, '', $name) . $rgt;
+ }
}