summaryrefslogtreecommitdiff
path: root/framework/Data/Common/Mssql/TMssqlMetaData.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/Mssql/TMssqlMetaData.php
parent5ad92b6fe39f04aad8d94f32d23c7e665725fe8c (diff)
Add methods quoteTableName, quoteColumnName, quoteColumnAlias to TDbMetaData & TDbConnection and add TDbConnection:getDbMetaData [TODO: customize TOracleMetaData]
Diffstat (limited to 'framework/Data/Common/Mssql/TMssqlMetaData.php')
-rw-r--r--framework/Data/Common/Mssql/TMssqlMetaData.php80
1 files changed, 55 insertions, 25 deletions
diff --git a/framework/Data/Common/Mssql/TMssqlMetaData.php b/framework/Data/Common/Mssql/TMssqlMetaData.php
index 334a297e..08d005ea 100644
--- a/framework/Data/Common/Mssql/TMssqlMetaData.php
+++ b/framework/Data/Common/Mssql/TMssqlMetaData.php
@@ -7,7 +7,7 @@
* @copyright Copyright &copy; 2005-2011 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id: TPgsqlMetaData.php 1866 2007-04-14 05:02:29Z wei $
- * @package System.Data.Common.Pgsql
+ * @package System.Data.Common.Mssql
*/
/**
@@ -35,6 +35,36 @@ class TMssqlMetaData extends TDbMetaData
}
/**
+ * Quotes a table name for use in a query.
+ * @param string $name table name
+ * @return string the properly quoted table name
+ */
+ public function quoteTableName($name)
+ {
+ return parent::quoteTableName($name, '[', ']');
+ }
+
+ /**
+ * Quotes a column name for use in a query.
+ * @param string $name column name
+ * @return string the properly quoted column name
+ */
+ public function quoteColumnName($name)
+ {
+ return parent::quoteColumnName($name, '[', ']');
+ }
+
+ /**
+ * Quotes a column alias for use in a query.
+ * @param string $name column alias
+ * @return string the properly quoted column alias
+ */
+ public function quoteColumnAlias($name)
+ {
+ return parent::quoteColumnAlias($name, '"', '"');
+ }
+
+ /**
* Get the column definitions for given table.
* @param string table name.
* @return TMssqlTableInfo table information.
@@ -45,12 +75,12 @@ class TMssqlMetaData extends TDbMetaData
$this->getDbConnection()->setActive(true);
$sql = <<<EOD
SELECT t.*,
- c.*,
+ c.*,
columnproperty(object_id(c.table_schema + '.' + c.table_name), c.column_name,'IsIdentity') as IsIdentity
- FROM INFORMATION_SCHEMA.TABLES t,
- INFORMATION_SCHEMA.COLUMNS c
- WHERE t.table_name = c.table_name
- AND t.table_name = :table
+ FROM INFORMATION_SCHEMA.TABLES t,
+ INFORMATION_SCHEMA.COLUMNS c
+ WHERE t.table_name = c.table_name
+ AND t.table_name = :table
EOD;
if($schemaName!==null)
$sql .= ' AND t.table_schema = :schema';
@@ -152,14 +182,14 @@ EOD;
{
$sql = <<<EOD
SELECT k.column_name field_name
- FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE k
- LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS c
- ON k.table_name = c.table_name
- AND k.constraint_name = c.constraint_name
- WHERE k.constraint_catalog = DB_NAME()
+ FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE k
+ LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS c
+ ON k.table_name = c.table_name
+ AND k.constraint_name = c.constraint_name
+ WHERE k.constraint_catalog = DB_NAME()
AND
c.constraint_type ='PRIMARY KEY'
- AND k.table_name = :table
+ AND k.table_name = :table
EOD;
$command = $this->getDbConnection()->createCommand($sql);
$command->bindValue(':table', $col['TABLE_NAME']);
@@ -181,27 +211,27 @@ EOD;
//From http://msdn2.microsoft.com/en-us/library/aa175805(SQL.80).aspx
$sql = <<<EOD
SELECT
- KCU1.CONSTRAINT_NAME AS 'FK_CONSTRAINT_NAME'
- , KCU1.TABLE_NAME AS 'FK_TABLE_NAME'
- , KCU1.COLUMN_NAME AS 'FK_COLUMN_NAME'
- , KCU1.ORDINAL_POSITION AS 'FK_ORDINAL_POSITION'
- , KCU2.CONSTRAINT_NAME AS 'UQ_CONSTRAINT_NAME'
- , KCU2.TABLE_NAME AS 'UQ_TABLE_NAME'
- , KCU2.COLUMN_NAME AS 'UQ_COLUMN_NAME'
- , KCU2.ORDINAL_POSITION AS 'UQ_ORDINAL_POSITION'
+ KCU1.CONSTRAINT_NAME AS 'FK_CONSTRAINT_NAME'
+ , KCU1.TABLE_NAME AS 'FK_TABLE_NAME'
+ , KCU1.COLUMN_NAME AS 'FK_COLUMN_NAME'
+ , KCU1.ORDINAL_POSITION AS 'FK_ORDINAL_POSITION'
+ , KCU2.CONSTRAINT_NAME AS 'UQ_CONSTRAINT_NAME'
+ , KCU2.TABLE_NAME AS 'UQ_TABLE_NAME'
+ , KCU2.COLUMN_NAME AS 'UQ_COLUMN_NAME'
+ , KCU2.ORDINAL_POSITION AS 'UQ_ORDINAL_POSITION'
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS RC
JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU1
ON KCU1.CONSTRAINT_CATALOG = RC.CONSTRAINT_CATALOG
- AND KCU1.CONSTRAINT_SCHEMA = RC.CONSTRAINT_SCHEMA
- AND KCU1.CONSTRAINT_NAME = RC.CONSTRAINT_NAME
+ AND KCU1.CONSTRAINT_SCHEMA = RC.CONSTRAINT_SCHEMA
+ AND KCU1.CONSTRAINT_NAME = RC.CONSTRAINT_NAME
JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU2
ON KCU2.CONSTRAINT_CATALOG =
RC.UNIQUE_CONSTRAINT_CATALOG
- AND KCU2.CONSTRAINT_SCHEMA =
+ AND KCU2.CONSTRAINT_SCHEMA =
RC.UNIQUE_CONSTRAINT_SCHEMA
- AND KCU2.CONSTRAINT_NAME =
+ AND KCU2.CONSTRAINT_NAME =
RC.UNIQUE_CONSTRAINT_NAME
- AND KCU2.ORDINAL_POSITION = KCU1.ORDINAL_POSITION
+ AND KCU2.ORDINAL_POSITION = KCU1.ORDINAL_POSITION
WHERE KCU1.TABLE_NAME = :table
EOD;
$command = $this->getDbConnection()->createCommand($sql);