{"action":"created","issue":{"url":"https://api.github.com/repos/yiisoft/yii/issues/3926","labels_url":"https://api.github.com/repos/yiisoft/yii/issues/3926/labels{/name}","comments_url":"https://api.github.com/repos/yiisoft/yii/issues/3926/comments","events_url":"https://api.github.com/repos/yiisoft/yii/issues/3926/events","html_url":"https://github.com/yiisoft/yii/issues/3926","id":102050408,"number":3926,"title":"CActiveRecord class Error (using Mssql) Query Functions Result in Error in the INFORMATION_SCHEMA Table","user":{"login":"aireol","id":7277937,"avatar_url":"https://avatars.githubusercontent.com/u/7277937?v=3","gravatar_id":"","url":"https://api.github.com/users/aireol","html_url":"https://github.com/aireol","followers_url":"https://api.github.com/users/aireol/followers","following_url":"https://api.github.com/users/aireol/following{/other_user}","gists_url":"https://api.github.com/users/aireol/gists{/gist_id}","starred_url":"https://api.github.com/users/aireol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aireol/subscriptions","organizations_url":"https://api.github.com/users/aireol/orgs","repos_url":"https://api.github.com/users/aireol/repos","events_url":"https://api.github.com/users/aireol/events{/privacy}","received_events_url":"https://api.github.com/users/aireol/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/yiisoft/yii/labels/feature:MSSQL","name":"feature:MSSQL","color":"0b02e1"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-08-20T03:08:16Z","updated_at":"2015-12-21T13:08:21Z","closed_at":null,"body":"Hi!\r\n\r\nI am trying to write a child class of the `CActiveRecord` class, but results in an error below in the `INFORMATION_SCHEMA` table: \r\n\r\n_My environment:_\r\nMSSQL Server 11.0.3153\r\npdo_sqlsrv driver\r\nPHP 5.4\r\nYii 1.1.16\r\nIIS\r\nZendServer 7\r\n\r\nHere's my implementation:\r\n\r\n````\r\n<?php\r\nclass User extends CActiveRecord\r\n{\r\n    public static function model($className=__CLASS__)\r\n    {\r\n        return parent::model($className);\r\n    }\r\n \r\n    public function tableName(){\r\n        return '[my_database].[dbo].[user]';\r\n    }\r\n\r\n    // public function getDbConnection(){}\r\n}\r\n````\r\n\r\nMy usage:\r\n\r\n````\r\n<?php \r\n...\r\n$instance = User::model()->findByPk(19086);\r\nprint_r($instance);\r\n...\r\n````\r\n\r\nError log:\r\n\r\n````\r\n\r\n2015/08/20 10:54:46 [trace] [system.db.CDbCommand] Querying SQL: \t\tSELECT k.column_name field_name\r\n\t\tFROM [my_database].[INFORMATION_SCHEMA].[KEY_COLUMN_USAGE] k\r\n\t\tLEFT JOIN [my_database].[INFORMATION_SCHEMA].[TABLE_CONSTRAINTS] c\r\n\t\tON k.table_name = c.table_name\r\n\t\t\tAND k.constraint_name = c.constraint_name\r\n\t\tWHERE c.constraint_type ='PRIMARY KEY'\r\n\t\t\tAND k.table_name = :table\r\n\t\t\tAND k.table_schema = :schema. Bound with :table='user', :schema='dbo'\r\nin C:\\inetpub\\wwwroot\\gps_listener\\trunk\\protected\\commands\\DTDMemberUploadCommand.php (93)\r\nin C:\\inetpub\\wwwroot\\gps_listener\\trunk\\console.php (35)\r\n\r\n2015/08/20 10:54:46 [trace] [system.CModule] Loading \"coreMessages\" application component\r\nin C:\\inetpub\\wwwroot\\gps_listener\\trunk\\protected\\commands\\DTDMemberUploadCommand.php (93)\r\nin C:\\inetpub\\wwwroot\\gps_listener\\trunk\\console.php (35)\r\n\r\n2015/08/20 10:54:46 [error] [system.db.CDbCommand] CDbCommand::fetchAll() failed: \r\nSQLSTATE[42S02]: [Microsoft][SQL Server Native Client 11.0][SQL Server] Invalid object name 'my_database.INFORMATION_SCHEMA.KEY_COLUMN_USAGE'.. The SQL statement executed was:\r\n\t\tSELECT k.column_name field_name\r\n\t\tFROM [my_database].[INFORMATION_SCHEMA].[KEY_COLUMN_USAGE] k\r\n\t\tLEFT JOIN [my_database].[INFORMATION_SCHEMA].[TABLE_CONSTRAINTS] c\r\n\t\tON k.table_name = c.table_name\r\n\t\t\tAND k.constraint_name = c.constraint_name\r\n\t\tWHERE c.constraint_type ='PRIMARY KEY'\r\n\t\t\tAND k.table_name = :table\r\n\t\t\tAND k.table_schema = :schema. Bound with :table='user', :schema='dbo'.\r\nin C:\\inetpub\\wwwroot\\gps_listener\\trunk\\protected\\commands\\DTDMemberUploadCommand.php (93)\r\nin C:\\inetpub\\wwwroot\\gps_listener\\trunk\\console.php (35)\r\n\r\n2015/08/20 10:54:46 [error] [exception.CDbException] exception 'CDbException' with message 'CDbCommand failed to execute the SQL statement: SQLSTATE[42S02]: [Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid object name 'my_database.INFORMATION_SCHEMA.KEY_COLUMN_USAGE'.. The SQL statement executed was: \t\tSELECT k.column_name field_name\r\n\t\tFROM [my_database].[INFORMATION_SCHEMA].[KEY_COLUMN_USAGE] k\r\n\t\tLEFT JOIN [my_database].[INFORMATION_SCHEMA].[TABLE_CONSTRAINTS] c\r\n\t\tON k.table_name = c.table_name\r\n\t\t\tAND k.constraint_name = c.constraint_name\r\n\t\tWHERE c.constraint_type ='PRIMARY KEY'\r\n\t\t\tAND k.table_name = :table\r\n\t\t\tAND k.table_schema = :schema. Bound with :table='user', :schema='dbo'' in C:\\inetpub\\wwwroot\\yii\\framework\\db\\CDbCommand.php:543\r\nStack trace:\r\n#0 C:\\inetpub\\wwwroot\\yii\\framework\\db\\CDbCommand.php(455): CDbCommand->queryInternal('fetchAll', Array, Array)\r\n#1 C:\\inetpub\\wwwroot\\yii\\framework\\db\\schema\\mssql\\CMssqlSchema.php(210): CDbCommand->queryColumn()\r\n#2 C:\\inetpub\\wwwroot\\yii\\framework\\db\\schema\\mssql\\CMssqlSchema.php(139): CMssqlSchema->findPrimaryKey(Object(CMssqlTableSchema))\r\n#3 C:\\inetpub\\wwwroot\\yii\\framework\\db\\schema\\CDbSchema.php(103): CMssqlSchema->loadTable('[my_database].[d...')\r\n#4 C:\\inetpub\\wwwroot\\yii\\framework\\db\\ar\\CActiveRecord.php(2384): CDbSchema->getTable('[my_database].[d...')\r\n#5 C:\\inetpub\\wwwroot\\yii\\framework\\db\\ar\\CActiveRecord.php(411): CActiveRecordMetaData->__construct(Object(User))\r\n#6 C:\\inetpub\\wwwroot\\yii\\framework\\db\\ar\\CActiveRecord.php(661): CActiveRecord->getMetaData()\r\n#7 C:\\inetpub\\wwwroot\\yii\\framework\\db\\ar\\CActiveRecord.php(1490): CActiveRecord->getTableSchema()\r\n#8 C:\\inetpub\\wwwroot\\gps_listener\\trunk\\protected\\commands\\DTDMemberUploadCommand.php(93): CActiveRecord->findByPk(19086)\r\n#9 [internal function]: DTDMemberUploadCommand->actionTest()\r\n#10 C:\\inetpub\\wwwroot\\yii\\framework\\console\\CConsoleCommand.php(172): ReflectionMethod->invokeArgs(Object(DTDMemberUploadCommand), Array)\r\n#11 C:\\inetpub\\wwwroot\\yii\\framework\\console\\CConsoleCommandRunner.php(71): CConsoleCommand->run(Array)\r\n#12 C:\\inetpub\\wwwroot\\yii\\framework\\console\\CConsoleApplication.php(92): CConsoleCommandRunner->run(Array)\r\n#13 C:\\inetpub\\wwwroot\\yii\\framework\\base\\CApplication.php(184): CConsoleApplication->processRequest()\r\n#14 C:\\inetpub\\wwwroot\\gps_listener\\trunk\\console.php(35): CApplication->run()\r\n#15 {main}\r\n---\r\n2015/08/20 10:54:46 [trace] [system.CModule] Loading \"errorHandler\" application component\r\n2015/08/20 10:54:46 [trace] [system.CModule] Loading \"request\" application component\r\n\r\n````"},"comment":{"url":"https://api.github.com/repos/yiisoft/yii/issues/comments/166301125","html_url":"https://github.com/yiisoft/yii/issues/3926#issuecomment-166301125","issue_url":"https://api.github.com/repos/yiisoft/yii/issues/3926","id":166301125,"user":{"login":"jjdunn","id":333222,"avatar_url":"https://avatars.githubusercontent.com/u/333222?v=3","gravatar_id":"","url":"https://api.github.com/users/jjdunn","html_url":"https://github.com/jjdunn","followers_url":"https://api.github.com/users/jjdunn/followers","following_url":"https://api.github.com/users/jjdunn/following{/other_user}","gists_url":"https://api.github.com/users/jjdunn/gists{/gist_id}","starred_url":"https://api.github.com/users/jjdunn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jjdunn/subscriptions","organizations_url":"https://api.github.com/users/jjdunn/orgs","repos_url":"https://api.github.com/users/jjdunn/repos","events_url":"https://api.github.com/users/jjdunn/events{/privacy}","received_events_url":"https://api.github.com/users/jjdunn/received_events","type":"User","site_admin":false},"created_at":"2015-12-21T13:08:21Z","updated_at":"2015-12-21T13:08:21Z","body":"works fine in SQL Server 2008 R2, which we've been using with Yii since 2010."}}