SqlserverTest.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. <?php
  2. /**
  3. * SqlserverTest file
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8. * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * Redistributions of files must retain the above copyright notice.
  12. *
  13. * @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://cakephp.org CakePHP(tm) Project
  15. * @package Cake.Test.Case.Model.Datasource.Database
  16. * @since CakePHP(tm) v 1.2.0
  17. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  18. */
  19. App::uses('Model', 'Model');
  20. App::uses('AppModel', 'Model');
  21. App::uses('Sqlserver', 'Model/Datasource/Database');
  22. require_once dirname(dirname(dirname(__FILE__))) . DS . 'models.php';
  23. /**
  24. * SqlserverTestDb class
  25. *
  26. * @package Cake.Test.Case.Model.Datasource.Database
  27. */
  28. class SqlserverTestDb extends Sqlserver {
  29. /**
  30. * simulated property
  31. *
  32. * @var array
  33. */
  34. public $simulated = array();
  35. /**
  36. * execute results stack
  37. *
  38. * @var array
  39. */
  40. public $executeResultsStack = array();
  41. /**
  42. * execute method
  43. *
  44. * @param mixed $sql
  45. * @param mixed $params
  46. * @param mixed $prepareOptions
  47. * @return mixed
  48. */
  49. protected function _execute($sql, $params = array(), $prepareOptions = array()) {
  50. $this->simulated[] = $sql;
  51. return empty($this->executeResultsStack) ? null : array_pop($this->executeResultsStack);
  52. }
  53. /**
  54. * fetchAll method
  55. *
  56. * @param mixed $sql
  57. * @return void
  58. */
  59. protected function _matchRecords($model, $conditions = null) {
  60. return $this->conditions(array('id' => array(1, 2)));
  61. }
  62. /**
  63. * getLastQuery method
  64. *
  65. * @return string
  66. */
  67. public function getLastQuery() {
  68. return $this->simulated[count($this->simulated) - 1];
  69. }
  70. /**
  71. * getPrimaryKey method
  72. *
  73. * @param mixed $model
  74. * @return string
  75. */
  76. public function getPrimaryKey($model) {
  77. return parent::_getPrimaryKey($model);
  78. }
  79. /**
  80. * clearFieldMappings method
  81. *
  82. * @return void
  83. */
  84. public function clearFieldMappings() {
  85. $this->_fieldMappings = array();
  86. }
  87. /**
  88. * describe method
  89. *
  90. * @param object $model
  91. * @return void
  92. */
  93. public function describe($model) {
  94. return empty($this->describe) ? parent::describe($model) : $this->describe;
  95. }
  96. }
  97. /**
  98. * SqlserverTestModel class
  99. *
  100. * @package Cake.Test.Case.Model.Datasource.Database
  101. */
  102. class SqlserverTestModel extends CakeTestModel {
  103. /**
  104. * name property
  105. *
  106. * @var string 'SqlserverTestModel'
  107. */
  108. public $name = 'SqlserverTestModel';
  109. /**
  110. * useTable property
  111. *
  112. * @var bool false
  113. */
  114. public $useTable = false;
  115. /**
  116. * _schema property
  117. *
  118. * @var array
  119. */
  120. protected $_schema = array(
  121. 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8', 'key' => 'primary'),
  122. 'client_id' => array('type' => 'integer', 'null' => '', 'default' => '0', 'length' => '11'),
  123. 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  124. 'login' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  125. 'passwd' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'),
  126. 'addr_1' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'),
  127. 'addr_2' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '25'),
  128. 'zip_code' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
  129. 'city' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
  130. 'country' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
  131. 'phone' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
  132. 'fax' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
  133. 'url' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'),
  134. 'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
  135. 'comments' => array('type' => 'text', 'null' => '1', 'default' => '', 'length' => ''),
  136. 'last_login'=> array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => ''),
  137. 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
  138. 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
  139. );
  140. /**
  141. * belongsTo property
  142. *
  143. * @var array
  144. */
  145. public $belongsTo = array(
  146. 'SqlserverClientTestModel' => array(
  147. 'foreignKey' => 'client_id'
  148. )
  149. );
  150. /**
  151. * find method
  152. *
  153. * @param mixed $conditions
  154. * @param mixed $fields
  155. * @param mixed $order
  156. * @param mixed $recursive
  157. * @return void
  158. */
  159. public function find($conditions = null, $fields = null, $order = null, $recursive = null) {
  160. return $conditions;
  161. }
  162. }
  163. /**
  164. * SqlserverClientTestModel class
  165. *
  166. * @package Cake.Test.Case.Model.Datasource.Database
  167. */
  168. class SqlserverClientTestModel extends CakeTestModel {
  169. /**
  170. * name property
  171. *
  172. * @var string 'SqlserverAssociatedTestModel'
  173. */
  174. public $name = 'SqlserverClientTestModel';
  175. /**
  176. * useTable property
  177. *
  178. * @var bool false
  179. */
  180. public $useTable = false;
  181. /**
  182. * _schema property
  183. *
  184. * @var array
  185. */
  186. protected $_schema = array(
  187. 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8', 'key' => 'primary'),
  188. 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  189. 'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
  190. 'created' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => ''),
  191. 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
  192. );
  193. }
  194. /**
  195. * SqlserverTestResultIterator class
  196. *
  197. * @package Cake.Test.Case.Model.Datasource.Database
  198. */
  199. class SqlserverTestResultIterator extends ArrayIterator {
  200. /**
  201. * closeCursor method
  202. *
  203. * @return void
  204. */
  205. public function closeCursor() {}
  206. /**
  207. * fetch method
  208. *
  209. * @return void
  210. */
  211. public function fetch() {
  212. if (!$this->valid()) {
  213. return null;
  214. }
  215. $current = $this->current();
  216. $this->next();
  217. return $current;
  218. }
  219. }
  220. /**
  221. * SqlserverTest class
  222. *
  223. * @package Cake.Test.Case.Model.Datasource.Database
  224. */
  225. class SqlserverTest extends CakeTestCase {
  226. /**
  227. * The Dbo instance to be tested
  228. *
  229. * @var DboSource
  230. */
  231. public $db = null;
  232. /**
  233. * autoFixtures property
  234. *
  235. * @var bool false
  236. */
  237. public $autoFixtures = false;
  238. /**
  239. * fixtures property
  240. *
  241. * @var array
  242. */
  243. public $fixtures = array('core.user', 'core.category', 'core.author', 'core.post');
  244. /**
  245. * Sets up a Dbo class instance for testing
  246. *
  247. */
  248. public function setUp() {
  249. $this->Dbo = ConnectionManager::getDataSource('test');
  250. if (!($this->Dbo instanceof Sqlserver)) {
  251. $this->markTestSkipped('Please configure the test datasource to use SQL Server.');
  252. }
  253. $this->db = new SqlserverTestDb($this->Dbo->config);
  254. $this->model = new SqlserverTestModel();
  255. }
  256. /**
  257. * tearDown method
  258. *
  259. * @return void
  260. */
  261. public function tearDown() {
  262. unset($this->Dbo);
  263. unset($this->model);
  264. }
  265. /**
  266. * testQuoting method
  267. *
  268. * @return void
  269. */
  270. public function testQuoting() {
  271. $expected = "1.2";
  272. $result = $this->db->value(1.2, 'float');
  273. $this->assertSame($expected, $result);
  274. $expected = "'1,2'";
  275. $result = $this->db->value('1,2', 'float');
  276. $this->assertSame($expected, $result);
  277. $expected = 'NULL';
  278. $result = $this->db->value('', 'integer');
  279. $this->assertSame($expected, $result);
  280. $expected = 'NULL';
  281. $result = $this->db->value('', 'float');
  282. $this->assertSame($expected, $result);
  283. $expected = "''";
  284. $result = $this->db->value('', 'binary');
  285. $this->assertSame($expected, $result);
  286. }
  287. /**
  288. * testFields method
  289. *
  290. * @return void
  291. */
  292. public function testFields() {
  293. $fields = array(
  294. '[SqlserverTestModel].[id] AS [SqlserverTestModel__id]',
  295. '[SqlserverTestModel].[client_id] AS [SqlserverTestModel__client_id]',
  296. '[SqlserverTestModel].[name] AS [SqlserverTestModel__name]',
  297. '[SqlserverTestModel].[login] AS [SqlserverTestModel__login]',
  298. '[SqlserverTestModel].[passwd] AS [SqlserverTestModel__passwd]',
  299. '[SqlserverTestModel].[addr_1] AS [SqlserverTestModel__addr_1]',
  300. '[SqlserverTestModel].[addr_2] AS [SqlserverTestModel__addr_2]',
  301. '[SqlserverTestModel].[zip_code] AS [SqlserverTestModel__zip_code]',
  302. '[SqlserverTestModel].[city] AS [SqlserverTestModel__city]',
  303. '[SqlserverTestModel].[country] AS [SqlserverTestModel__country]',
  304. '[SqlserverTestModel].[phone] AS [SqlserverTestModel__phone]',
  305. '[SqlserverTestModel].[fax] AS [SqlserverTestModel__fax]',
  306. '[SqlserverTestModel].[url] AS [SqlserverTestModel__url]',
  307. '[SqlserverTestModel].[email] AS [SqlserverTestModel__email]',
  308. '[SqlserverTestModel].[comments] AS [SqlserverTestModel__comments]',
  309. 'CONVERT(VARCHAR(20), [SqlserverTestModel].[last_login], 20) AS [SqlserverTestModel__last_login]',
  310. '[SqlserverTestModel].[created] AS [SqlserverTestModel__created]',
  311. 'CONVERT(VARCHAR(20), [SqlserverTestModel].[updated], 20) AS [SqlserverTestModel__updated]'
  312. );
  313. $result = $this->db->fields($this->model);
  314. $expected = $fields;
  315. $this->assertEquals($expected, $result);
  316. $this->db->clearFieldMappings();
  317. $result = $this->db->fields($this->model, null, 'SqlserverTestModel.*');
  318. $expected = $fields;
  319. $this->assertEquals($expected, $result);
  320. $this->db->clearFieldMappings();
  321. $result = $this->db->fields($this->model, null, array('*', 'AnotherModel.id', 'AnotherModel.name'));
  322. $expected = array_merge($fields, array(
  323. '[AnotherModel].[id] AS [AnotherModel__id]',
  324. '[AnotherModel].[name] AS [AnotherModel__name]'));
  325. $this->assertEquals($expected, $result);
  326. $this->db->clearFieldMappings();
  327. $result = $this->db->fields($this->model, null, array('*', 'SqlserverClientTestModel.*'));
  328. $expected = array_merge($fields, array(
  329. '[SqlserverClientTestModel].[id] AS [SqlserverClientTestModel__id]',
  330. '[SqlserverClientTestModel].[name] AS [SqlserverClientTestModel__name]',
  331. '[SqlserverClientTestModel].[email] AS [SqlserverClientTestModel__email]',
  332. 'CONVERT(VARCHAR(20), [SqlserverClientTestModel].[created], 20) AS [SqlserverClientTestModel__created]',
  333. 'CONVERT(VARCHAR(20), [SqlserverClientTestModel].[updated], 20) AS [SqlserverClientTestModel__updated]'));
  334. $this->assertEquals($expected, $result);
  335. }
  336. /**
  337. * testDistinctFields method
  338. *
  339. * @return void
  340. */
  341. public function testDistinctFields() {
  342. $result = $this->db->fields($this->model, null, array('DISTINCT Car.country_code'));
  343. $expected = array('DISTINCT [Car].[country_code] AS [Car__country_code]');
  344. $this->assertEquals($expected, $result);
  345. $result = $this->db->fields($this->model, null, 'DISTINCT Car.country_code');
  346. $expected = array('DISTINCT [Car].[country_code] AS [Car__country_code]');
  347. $this->assertEquals($expected, $result);
  348. }
  349. /**
  350. * testDistinctWithLimit method
  351. *
  352. * @return void
  353. */
  354. public function testDistinctWithLimit() {
  355. $this->db->read($this->model, array(
  356. 'fields' => array('DISTINCT SqlserverTestModel.city', 'SqlserverTestModel.country'),
  357. 'limit' => 5
  358. ));
  359. $result = $this->db->getLastQuery();
  360. $this->assertRegExp('/^SELECT DISTINCT TOP 5/', $result);
  361. }
  362. /**
  363. * testDescribe method
  364. *
  365. * @return void
  366. */
  367. public function testDescribe() {
  368. $SqlserverTableDescription = new SqlserverTestResultIterator(array(
  369. (object) array(
  370. 'Default' => '((0))',
  371. 'Field' => 'count',
  372. 'Key' => 0,
  373. 'Length' => '4',
  374. 'Null' => 'NO',
  375. 'Type' => 'integer'
  376. ),
  377. (object) array(
  378. 'Default' => '',
  379. 'Field' => 'body',
  380. 'Key' => 0,
  381. 'Length' => '-1',
  382. 'Null' => 'YES',
  383. 'Type' => 'nvarchar'
  384. ),
  385. (object) array(
  386. 'Default' => '',
  387. 'Field' => 'published',
  388. 'Key' => 0,
  389. 'Type' => 'datetime2',
  390. 'Length' => 8,
  391. 'Null' => 'YES',
  392. 'Size' => ''
  393. ),
  394. (object) array(
  395. 'Default' => '',
  396. 'Field' => 'id',
  397. 'Key' => 1,
  398. 'Type' => 'nchar',
  399. 'Length' => 72,
  400. 'Null' => 'NO',
  401. 'Size' => ''
  402. )
  403. ));
  404. $this->db->executeResultsStack = array($SqlserverTableDescription);
  405. $dummyModel = $this->model;
  406. $result = $this->db->describe($dummyModel);
  407. $expected = array(
  408. 'count' => array(
  409. 'type' => 'integer',
  410. 'null' => false,
  411. 'default' => '0',
  412. 'length' => 4
  413. ),
  414. 'body' => array(
  415. 'type' => 'text',
  416. 'null' => true,
  417. 'default' => null,
  418. 'length' => null
  419. ),
  420. 'published' => array(
  421. 'type' => 'datetime',
  422. 'null' => true,
  423. 'default' => '',
  424. 'length' => null
  425. ),
  426. 'id' => array(
  427. 'type' => 'string',
  428. 'null' => false,
  429. 'default' => '',
  430. 'length' => 36,
  431. 'key' => 'primary'
  432. )
  433. );
  434. $this->assertEquals($expected, $result);
  435. }
  436. /**
  437. * testBuildColumn
  438. *
  439. * @return void
  440. */
  441. public function testBuildColumn() {
  442. $column = array('name' => 'id', 'type' => 'integer', 'null' => false, 'default' => '', 'length' => '8', 'key' => 'primary');
  443. $result = $this->db->buildColumn($column);
  444. $expected = '[id] int IDENTITY (1, 1) NOT NULL';
  445. $this->assertEquals($expected, $result);
  446. $column = array('name' => 'client_id', 'type' => 'integer', 'null' => false, 'default' => '0', 'length' => '11');
  447. $result = $this->db->buildColumn($column);
  448. $expected = '[client_id] int DEFAULT 0 NOT NULL';
  449. $this->assertEquals($expected, $result);
  450. $column = array('name' => 'client_id', 'type' => 'integer', 'null' => true);
  451. $result = $this->db->buildColumn($column);
  452. $expected = '[client_id] int NULL';
  453. $this->assertEquals($expected, $result);
  454. // 'name' => 'type' format for columns
  455. $column = array('type' => 'integer', 'name' => 'client_id');
  456. $result = $this->db->buildColumn($column);
  457. $expected = '[client_id] int NULL';
  458. $this->assertEquals($expected, $result);
  459. $column = array('type' => 'string', 'name' => 'name');
  460. $result = $this->db->buildColumn($column);
  461. $expected = '[name] nvarchar(255) NULL';
  462. $this->assertEquals($expected, $result);
  463. $column = array('name' => 'name', 'type' => 'string', 'null' => false, 'default' => '', 'length' => '255');
  464. $result = $this->db->buildColumn($column);
  465. $expected = '[name] nvarchar(255) DEFAULT \'\' NOT NULL';
  466. $this->assertEquals($expected, $result);
  467. $column = array('name' => 'name', 'type' => 'string', 'null' => false, 'length' => '255');
  468. $result = $this->db->buildColumn($column);
  469. $expected = '[name] nvarchar(255) NOT NULL';
  470. $this->assertEquals($expected, $result);
  471. $column = array('name' => 'name', 'type' => 'string', 'null' => false, 'default' => null, 'length' => '255');
  472. $result = $this->db->buildColumn($column);
  473. $expected = '[name] nvarchar(255) NOT NULL';
  474. $this->assertEquals($expected, $result);
  475. $column = array('name' => 'name', 'type' => 'string', 'null' => true, 'default' => null, 'length' => '255');
  476. $result = $this->db->buildColumn($column);
  477. $expected = '[name] nvarchar(255) NULL';
  478. $this->assertEquals($expected, $result);
  479. $column = array('name' => 'name', 'type' => 'string', 'null' => true, 'default' => '', 'length' => '255');
  480. $result = $this->db->buildColumn($column);
  481. $expected = '[name] nvarchar(255) DEFAULT \'\'';
  482. $this->assertEquals($expected, $result);
  483. $column = array('name' => 'body', 'type' => 'text');
  484. $result = $this->db->buildColumn($column);
  485. $expected = '[body] nvarchar(MAX)';
  486. $this->assertEquals($expected, $result);
  487. }
  488. /**
  489. * testBuildIndex method
  490. *
  491. * @return void
  492. */
  493. public function testBuildIndex() {
  494. $indexes = array(
  495. 'PRIMARY' => array('column' => 'id', 'unique' => 1),
  496. 'client_id' => array('column' => 'client_id', 'unique' => 1)
  497. );
  498. $result = $this->db->buildIndex($indexes, 'items');
  499. $expected = array(
  500. 'PRIMARY KEY ([id])',
  501. 'ALTER TABLE items ADD CONSTRAINT client_id UNIQUE([client_id]);'
  502. );
  503. $this->assertEquals($expected, $result);
  504. $indexes = array('client_id' => array('column' => 'client_id'));
  505. $result = $this->db->buildIndex($indexes, 'items');
  506. $this->assertEquals($result, array());
  507. $indexes = array('client_id' => array('column' => array('client_id', 'period_id'), 'unique' => 1));
  508. $result = $this->db->buildIndex($indexes, 'items');
  509. $expected = array('ALTER TABLE items ADD CONSTRAINT client_id UNIQUE([client_id], [period_id]);');
  510. $this->assertEquals($expected, $result);
  511. }
  512. /**
  513. * testUpdateAllSyntax method
  514. *
  515. * @return void
  516. */
  517. public function testUpdateAllSyntax() {
  518. $fields = array('SqlserverTestModel.client_id' => '[SqlserverTestModel].[client_id] + 1');
  519. $conditions = array('SqlserverTestModel.updated <' => date('2009-01-01 00:00:00'));
  520. $this->db->update($this->model, $fields, null, $conditions);
  521. $result = $this->db->getLastQuery();
  522. $this->assertNotRegExp('/SqlserverTestModel/', $result);
  523. $this->assertRegExp('/^UPDATE \[sqlserver_test_models\]/', $result);
  524. $this->assertRegExp('/SET \[client_id\] = \[client_id\] \+ 1/', $result);
  525. }
  526. /**
  527. * testGetPrimaryKey method
  528. *
  529. * @return void
  530. */
  531. public function testGetPrimaryKey() {
  532. $schema = $this->model->schema();
  533. $this->db->describe = $schema;
  534. $result = $this->db->getPrimaryKey($this->model);
  535. $this->assertEquals($result, 'id');
  536. unset($schema['id']['key']);
  537. $this->db->describe = $schema;
  538. $result = $this->db->getPrimaryKey($this->model);
  539. $this->assertNull($result);
  540. }
  541. /**
  542. * SQL server < 11 doesn't have proper limit/offset support, test that our hack works.
  543. *
  544. * @return void
  545. */
  546. public function testLimitOffsetHack() {
  547. $this->loadFixtures('Author', 'Post', 'User');
  548. $query = array(
  549. 'limit' => 2,
  550. 'page' => 1,
  551. 'order' => 'User.user ASC',
  552. );
  553. $User = ClassRegistry::init('User');
  554. $results = $User->find('all', $query);
  555. $this->assertEquals(2, count($results));
  556. $this->assertEquals('garrett', $results[0]['User']['user']);
  557. $this->assertEquals('larry', $results[1]['User']['user']);
  558. $query = array(
  559. 'limit' => 2,
  560. 'page' => 2,
  561. 'order' => 'User.user ASC',
  562. );
  563. $User = ClassRegistry::init('User');
  564. $results = $User->find('all', $query);
  565. $this->assertEquals(2, count($results));
  566. $this->assertFalse(isset($results[0][0]));
  567. $this->assertEquals('mariano', $results[0]['User']['user']);
  568. $this->assertEquals('nate', $results[1]['User']['user']);
  569. }
  570. /**
  571. * Test that the return of stored procedures is honoured
  572. *
  573. * @return void
  574. */
  575. public function testStoredProcedureReturn() {
  576. $sql = <<<SQL
  577. CREATE PROCEDURE cake_test_procedure
  578. AS
  579. BEGIN
  580. RETURN 2;
  581. END
  582. SQL;
  583. $this->Dbo->execute($sql);
  584. $sql = <<<SQL
  585. DECLARE @return_value int
  586. EXEC @return_value = [cake_test_procedure]
  587. SELECT 'value' = @return_value
  588. SQL;
  589. $query = $this->Dbo->execute($sql);
  590. $this->Dbo->execute('DROP PROC cake_test_procedure');
  591. $result = $query->fetch();
  592. $this->assertEquals(2, $result['value']);
  593. }
  594. }