Skip to content
Permalink
Browse files

Sqlserver Datasource how properly appends the schemaName prefix in th…

…e describe() method
  • Loading branch information...
Joseph Woodruff
Joseph Woodruff committed Apr 2, 2014
1 parent d526fda commit 85363715010cc572f9bff31b920846a37b5769e5
Showing with 9 additions and 5 deletions.
  1. +9 −5 lib/Cake/Model/Datasource/Database/Sqlserver.php
@@ -195,26 +195,30 @@ public function listSources($data = null) {
* @throws CakeException
*/
public function describe($model) {
$table = $this->fullTableName($model, false);
$cache = parent::describe($table);
$table = $this->fullTableName($model, false, false);
$fulltable = $this->fullTableName($model, false, true);
$cache = parent::describe($fulltable);
if ($cache) {
return $cache;
}
$fields = array();
$table = $this->fullTableName($model, false, false);
$schema = $model->schemaName;
$cols = $this->_execute(
"SELECT
COLUMN_NAME as Field,
DATA_TYPE as Type,
COL_LENGTH('" . $table . "', COLUMN_NAME) as Length,
COL_LENGTH('" . ($schema ? $fulltable : $table) . "', COLUMN_NAME) as Length,
IS_NULLABLE As [Null],
COLUMN_DEFAULT as [Default],
COLUMNPROPERTY(OBJECT_ID('" . $table . "'), COLUMN_NAME, 'IsIdentity') as [Key],
COLUMNPROPERTY(OBJECT_ID('" . ($schema ? $fulltable : $table) . "'), COLUMN_NAME, 'IsIdentity') as [Key],
NUMERIC_SCALE as Size
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = '" . $table . "'" . ($schema ? " AND TABLE_SCHEMA = '" . $schema . "'" : '')
);
if (!$cols) {
throw new CakeException(__d('cake_dev', 'Could not describe table for %s', $table));
}

0 comments on commit 8536371

Please sign in to comment.
You can’t perform that action at this time.