diff options
Diffstat (limited to 'framework/Data/Common/TDbMetaData.php')
-rw-r--r-- | framework/Data/Common/TDbMetaData.php | 48 |
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;
+ }
}
|