PostgresTest.php 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006
  1. <?php
  2. /**
  3. * DboPostgresTest file
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8. * Copyright 2005-2012, 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-2012, 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('Postgres', 'Model/Datasource/Database');
  22. require_once dirname(dirname(dirname(__FILE__))) . DS . 'models.php';
  23. /**
  24. * DboPostgresTestDb class
  25. *
  26. * @package Cake.Test.Case.Model.Datasource.Database
  27. */
  28. class DboPostgresTestDb extends Postgres {
  29. /**
  30. * simulated property
  31. *
  32. * @var array
  33. */
  34. public $simulated = array();
  35. /**
  36. * execute method
  37. *
  38. * @param mixed $sql
  39. * @return void
  40. */
  41. protected function _execute($sql, $params = array(), $prepareOptions = array()) {
  42. $this->simulated[] = $sql;
  43. return null;
  44. }
  45. /**
  46. * getLastQuery method
  47. *
  48. * @return void
  49. */
  50. public function getLastQuery() {
  51. return $this->simulated[count($this->simulated) - 1];
  52. }
  53. }
  54. /**
  55. * PostgresTestModel class
  56. *
  57. * @package Cake.Test.Case.Model.Datasource.Database
  58. */
  59. class PostgresTestModel extends Model {
  60. /**
  61. * name property
  62. *
  63. * @var string 'PostgresTestModel'
  64. */
  65. public $name = 'PostgresTestModel';
  66. /**
  67. * useTable property
  68. *
  69. * @var bool false
  70. */
  71. public $useTable = false;
  72. /**
  73. * belongsTo property
  74. *
  75. * @var array
  76. */
  77. public $belongsTo = array(
  78. 'PostgresClientTestModel' => array(
  79. 'foreignKey' => 'client_id'
  80. )
  81. );
  82. /**
  83. * find method
  84. *
  85. * @param mixed $conditions
  86. * @param mixed $fields
  87. * @param mixed $order
  88. * @param mixed $recursive
  89. * @return void
  90. */
  91. public function find($conditions = null, $fields = null, $order = null, $recursive = null) {
  92. return $conditions;
  93. }
  94. /**
  95. * findAll method
  96. *
  97. * @param mixed $conditions
  98. * @param mixed $fields
  99. * @param mixed $order
  100. * @param mixed $recursive
  101. * @return void
  102. */
  103. public function findAll($conditions = null, $fields = null, $order = null, $recursive = null) {
  104. return $conditions;
  105. }
  106. /**
  107. * schema method
  108. *
  109. * @return void
  110. */
  111. public function schema($field = false) {
  112. return array(
  113. 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
  114. 'client_id' => array('type' => 'integer', 'null' => '', 'default' => '0', 'length' => '11'),
  115. 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  116. 'login' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  117. 'passwd' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'),
  118. 'addr_1' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'),
  119. 'addr_2' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '25'),
  120. 'zip_code' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
  121. 'city' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
  122. 'country' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
  123. 'phone' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
  124. 'fax' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
  125. 'url' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'),
  126. 'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
  127. 'comments' => array('type' => 'text', 'null' => '1', 'default' => '', 'length' => ''),
  128. 'last_login' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => ''),
  129. 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
  130. 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
  131. );
  132. }
  133. }
  134. /**
  135. * PostgresClientTestModel class
  136. *
  137. * @package Cake.Test.Case.Model.Datasource.Database
  138. */
  139. class PostgresClientTestModel extends Model {
  140. /**
  141. * name property
  142. *
  143. * @var string 'PostgresClientTestModel'
  144. */
  145. public $name = 'PostgresClientTestModel';
  146. /**
  147. * useTable property
  148. *
  149. * @var bool false
  150. */
  151. public $useTable = false;
  152. /**
  153. * schema method
  154. *
  155. * @return void
  156. */
  157. public function schema($field = false) {
  158. return array(
  159. 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8', 'key' => 'primary'),
  160. 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
  161. 'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
  162. 'created' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => ''),
  163. 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
  164. );
  165. }
  166. }
  167. /**
  168. * PostgresTest class
  169. *
  170. * @package Cake.Test.Case.Model.Datasource.Database
  171. */
  172. class PostgresTest extends CakeTestCase {
  173. /**
  174. * Do not automatically load fixtures for each test, they will be loaded manually
  175. * using CakeTestCase::loadFixtures
  176. *
  177. * @var boolean
  178. */
  179. public $autoFixtures = false;
  180. /**
  181. * Fixtures
  182. *
  183. * @var object
  184. */
  185. public $fixtures = array('core.user', 'core.binary_test', 'core.comment', 'core.article',
  186. 'core.tag', 'core.articles_tag', 'core.attachment', 'core.person', 'core.post', 'core.author',
  187. 'core.datatype',
  188. );
  189. /**
  190. * Actual DB connection used in testing
  191. *
  192. * @var DboSource
  193. */
  194. public $Dbo = null;
  195. /**
  196. * Simulated DB connection used in testing
  197. *
  198. * @var DboSource
  199. */
  200. public $Dbo2 = null;
  201. /**
  202. * Sets up a Dbo class instance for testing
  203. *
  204. */
  205. public function setUp() {
  206. Configure::write('Cache.disable', true);
  207. $this->Dbo = ConnectionManager::getDataSource('test');
  208. $this->skipIf(!($this->Dbo instanceof Postgres));
  209. $this->Dbo2 = new DboPostgresTestDb($this->Dbo->config, false);
  210. $this->model = new PostgresTestModel();
  211. }
  212. /**
  213. * Sets up a Dbo class instance for testing
  214. *
  215. */
  216. public function tearDown() {
  217. Configure::write('Cache.disable', false);
  218. unset($this->Dbo2);
  219. }
  220. /**
  221. * Test field quoting method
  222. *
  223. */
  224. public function testFieldQuoting() {
  225. $fields = array(
  226. '"PostgresTestModel"."id" AS "PostgresTestModel__id"',
  227. '"PostgresTestModel"."client_id" AS "PostgresTestModel__client_id"',
  228. '"PostgresTestModel"."name" AS "PostgresTestModel__name"',
  229. '"PostgresTestModel"."login" AS "PostgresTestModel__login"',
  230. '"PostgresTestModel"."passwd" AS "PostgresTestModel__passwd"',
  231. '"PostgresTestModel"."addr_1" AS "PostgresTestModel__addr_1"',
  232. '"PostgresTestModel"."addr_2" AS "PostgresTestModel__addr_2"',
  233. '"PostgresTestModel"."zip_code" AS "PostgresTestModel__zip_code"',
  234. '"PostgresTestModel"."city" AS "PostgresTestModel__city"',
  235. '"PostgresTestModel"."country" AS "PostgresTestModel__country"',
  236. '"PostgresTestModel"."phone" AS "PostgresTestModel__phone"',
  237. '"PostgresTestModel"."fax" AS "PostgresTestModel__fax"',
  238. '"PostgresTestModel"."url" AS "PostgresTestModel__url"',
  239. '"PostgresTestModel"."email" AS "PostgresTestModel__email"',
  240. '"PostgresTestModel"."comments" AS "PostgresTestModel__comments"',
  241. '"PostgresTestModel"."last_login" AS "PostgresTestModel__last_login"',
  242. '"PostgresTestModel"."created" AS "PostgresTestModel__created"',
  243. '"PostgresTestModel"."updated" AS "PostgresTestModel__updated"'
  244. );
  245. $result = $this->Dbo->fields($this->model);
  246. $expected = $fields;
  247. $this->assertEquals($expected, $result);
  248. $result = $this->Dbo->fields($this->model, null, 'PostgresTestModel.*');
  249. $expected = $fields;
  250. $this->assertEquals($expected, $result);
  251. $result = $this->Dbo->fields($this->model, null, array('*', 'AnotherModel.id', 'AnotherModel.name'));
  252. $expected = array_merge($fields, array(
  253. '"AnotherModel"."id" AS "AnotherModel__id"',
  254. '"AnotherModel"."name" AS "AnotherModel__name"'));
  255. $this->assertEquals($expected, $result);
  256. $result = $this->Dbo->fields($this->model, null, array('*', 'PostgresClientTestModel.*'));
  257. $expected = array_merge($fields, array(
  258. '"PostgresClientTestModel"."id" AS "PostgresClientTestModel__id"',
  259. '"PostgresClientTestModel"."name" AS "PostgresClientTestModel__name"',
  260. '"PostgresClientTestModel"."email" AS "PostgresClientTestModel__email"',
  261. '"PostgresClientTestModel"."created" AS "PostgresClientTestModel__created"',
  262. '"PostgresClientTestModel"."updated" AS "PostgresClientTestModel__updated"'));
  263. $this->assertEquals($expected, $result);
  264. }
  265. /**
  266. * testColumnParsing method
  267. *
  268. * @return void
  269. */
  270. public function testColumnParsing() {
  271. $this->assertEquals('text', $this->Dbo2->column('text'));
  272. $this->assertEquals('date', $this->Dbo2->column('date'));
  273. $this->assertEquals('boolean', $this->Dbo2->column('boolean'));
  274. $this->assertEquals('string', $this->Dbo2->column('character varying'));
  275. $this->assertEquals('time', $this->Dbo2->column('time without time zone'));
  276. $this->assertEquals('datetime', $this->Dbo2->column('timestamp without time zone'));
  277. $result = $this->Dbo2->column('bigint');
  278. $expected = 'biginteger';
  279. $this->assertEquals($expected, $result);
  280. }
  281. /**
  282. * testValueQuoting method
  283. *
  284. * @return void
  285. */
  286. public function testValueQuoting() {
  287. $this->assertEquals("1.200000", $this->Dbo->value(1.2, 'float'));
  288. $this->assertEquals("'1,2'", $this->Dbo->value('1,2', 'float'));
  289. $this->assertEquals("0", $this->Dbo->value('0', 'integer'));
  290. $this->assertEquals('NULL', $this->Dbo->value('', 'integer'));
  291. $this->assertEquals('NULL', $this->Dbo->value('', 'float'));
  292. $this->assertEquals("NULL", $this->Dbo->value('', 'integer', false));
  293. $this->assertEquals("NULL", $this->Dbo->value('', 'float', false));
  294. $this->assertEquals("'0.0'", $this->Dbo->value('0.0', 'float'));
  295. $this->assertEquals("'TRUE'", $this->Dbo->value('t', 'boolean'));
  296. $this->assertEquals("'FALSE'", $this->Dbo->value('f', 'boolean'));
  297. $this->assertEquals("'TRUE'", $this->Dbo->value(true));
  298. $this->assertEquals("'FALSE'", $this->Dbo->value(false));
  299. $this->assertEquals("'t'", $this->Dbo->value('t'));
  300. $this->assertEquals("'f'", $this->Dbo->value('f'));
  301. $this->assertEquals("'TRUE'", $this->Dbo->value('true', 'boolean'));
  302. $this->assertEquals("'FALSE'", $this->Dbo->value('false', 'boolean'));
  303. $this->assertEquals("'FALSE'", $this->Dbo->value('', 'boolean'));
  304. $this->assertEquals("'FALSE'", $this->Dbo->value(0, 'boolean'));
  305. $this->assertEquals("'TRUE'", $this->Dbo->value(1, 'boolean'));
  306. $this->assertEquals("'TRUE'", $this->Dbo->value('1', 'boolean'));
  307. $this->assertEquals("NULL", $this->Dbo->value(null, 'boolean'));
  308. $this->assertEquals("NULL", $this->Dbo->value(array()));
  309. }
  310. /**
  311. * test that localized floats don't cause trouble.
  312. *
  313. * @return void
  314. */
  315. public function testLocalizedFloats() {
  316. $restore = setlocale(LC_NUMERIC, 0);
  317. setlocale(LC_NUMERIC, 'de_DE');
  318. $result = $this->db->value(3.141593, 'float');
  319. $this->assertEquals("3.141593", $result);
  320. $result = $this->db->value(3.14);
  321. $this->assertEquals("3.140000", $result);
  322. setlocale(LC_NUMERIC, $restore);
  323. }
  324. /**
  325. * test that date and time columns do not generate errors with null and nullish values.
  326. *
  327. * @return void
  328. */
  329. public function testDateAndTimeAsNull() {
  330. $this->assertEquals('NULL', $this->Dbo->value(null, 'date'));
  331. $this->assertEquals('NULL', $this->Dbo->value('', 'date'));
  332. $this->assertEquals('NULL', $this->Dbo->value('', 'datetime'));
  333. $this->assertEquals('NULL', $this->Dbo->value(null, 'datetime'));
  334. $this->assertEquals('NULL', $this->Dbo->value('', 'timestamp'));
  335. $this->assertEquals('NULL', $this->Dbo->value(null, 'timestamp'));
  336. $this->assertEquals('NULL', $this->Dbo->value('', 'time'));
  337. $this->assertEquals('NULL', $this->Dbo->value(null, 'time'));
  338. }
  339. /**
  340. * Tests that different Postgres boolean 'flavors' are properly returned as native PHP booleans
  341. *
  342. * @return void
  343. */
  344. public function testBooleanNormalization() {
  345. $this->assertEquals(true, $this->Dbo2->boolean('t', false));
  346. $this->assertEquals(true, $this->Dbo2->boolean('true', false));
  347. $this->assertEquals(true, $this->Dbo2->boolean('TRUE', false));
  348. $this->assertEquals(true, $this->Dbo2->boolean(true, false));
  349. $this->assertEquals(true, $this->Dbo2->boolean(1, false));
  350. $this->assertEquals(true, $this->Dbo2->boolean(" ", false));
  351. $this->assertEquals(false, $this->Dbo2->boolean('f', false));
  352. $this->assertEquals(false, $this->Dbo2->boolean('false', false));
  353. $this->assertEquals(false, $this->Dbo2->boolean('FALSE', false));
  354. $this->assertEquals(false, $this->Dbo2->boolean(false, false));
  355. $this->assertEquals(false, $this->Dbo2->boolean(0, false));
  356. $this->assertEquals(false, $this->Dbo2->boolean('', false));
  357. }
  358. /**
  359. * test that default -> false in schemas works correctly.
  360. *
  361. * @return void
  362. */
  363. public function testBooleanDefaultFalseInSchema() {
  364. $this->loadFixtures('Datatype');
  365. $model = new Model(array('name' => 'Datatype', 'table' => 'datatypes', 'ds' => 'test'));
  366. $model->create();
  367. $this->assertSame(false, $model->data['Datatype']['bool']);
  368. }
  369. /**
  370. * testLastInsertIdMultipleInsert method
  371. *
  372. * @return void
  373. */
  374. public function testLastInsertIdMultipleInsert() {
  375. $this->loadFixtures('User');
  376. $db1 = ConnectionManager::getDataSource('test');
  377. $table = $db1->fullTableName('users', false);
  378. $password = '5f4dcc3b5aa765d61d8327deb882cf99';
  379. $db1->execute(
  380. "INSERT INTO {$table} (\"user\", password) VALUES ('mariano', '{$password}')"
  381. );
  382. $this->assertEquals(5, $db1->lastInsertId($table));
  383. $db1->execute("INSERT INTO {$table} (\"user\", password) VALUES ('hoge', '{$password}')");
  384. $this->assertEquals(6, $db1->lastInsertId($table));
  385. }
  386. /**
  387. * Tests that column types without default lengths in $columns do not have length values
  388. * applied when generating schemas.
  389. *
  390. * @return void
  391. */
  392. public function testColumnUseLength() {
  393. $result = array('name' => 'foo', 'type' => 'string', 'length' => 100, 'default' => 'FOO');
  394. $expected = '"foo" varchar(100) DEFAULT \'FOO\'';
  395. $this->assertEquals($expected, $this->Dbo->buildColumn($result));
  396. $result = array('name' => 'foo', 'type' => 'text', 'length' => 100, 'default' => 'FOO');
  397. $expected = '"foo" text DEFAULT \'FOO\'';
  398. $this->assertEquals($expected, $this->Dbo->buildColumn($result));
  399. }
  400. /**
  401. * Tests that binary data is escaped/unescaped properly on reads and writes
  402. *
  403. * @return void
  404. */
  405. public function testBinaryDataIntegrity() {
  406. $this->loadFixtures('BinaryTest');
  407. $data = '%PDF-1.3
  408. %ƒÂÚÂÎßÛ†–ƒ∆
  409. 4 0 obj
  410. << /Length 5 0 R /Filter /FlateDecode >>
  411. stream
  412. xµYMì€∆Ω„WÃ%)nï0¯îâ-«é]Q"πXµáÿ•Ip - P V,]Ú#c˚ˇ‰ut¥†∏Ti9 Ü=”›Ø_˜4>à∑‚Épcé¢Pxæ®2q\'
  413. 1UªbU ᡒ+ö«√[ıµ⁄ão"R∑"HiGæä€(å≠≈^Ãøsm?YlƒÃõªfi‹âEÚB&‚Î◊7bÒ^¸m°÷˛?2±Øs“fiu#®U√ˇú÷g¥C;ä")n})JºIÔ3ËSnÑÎ¥≤ıD∆¢∂Msx1üèG˚±Œ™⁄>¶ySïufØ ˝¸?UπÃã√6flÌÚC=øK?˝…s
  414. ˛§¯ˇ:-˜ò7€ÓFæ∂∑Õ˛∆“V’>ılflëÅd«ÜQdI ›ÎB%W¿ΩıÉn~h vêCS>«é˛(ØôK!€¡zB!√
  415. [œÜ"ûß ·iH¸[Àºæ∑¯¡L,ÀÚAlS∫ˆ=∫Œ≤cÄr&ˆÈ:√ÿ£˚È«4fl•À]vc›bÅôÿî=siXe4/¡p]ã]ôÆIœ™ Ωflà_ƒ‚G?«7 ùÿ ı¯K4ïIpV◊÷·\'éµóªÚæ>î
  416. ;›sú!2fl¬F•/f∑j£
  417. dw"IÊÜπ<ôÿˆ%IG1ytÛDflXg|Éòa§˜}C˛¿ÿe°G´Ú±jÍm~¿/∂hã<#-¥•ıùe87€t˜õ6w}´{æ
  418. m‹ê– ∆¡ 6⁄\
  419. rAÀBùZ3aË‚r$G·$ó0Ñ üâUY4È™¡%C∑Ÿ2rc<Iõ-cï.
  420. [ŒöâFA†É‡+QglMÉîÉÄúÌ|¸»#x7¥«MgVÎ-GGÚ• I?Á‘”Lzw∞pHů◊nefqCî.nÕeè∆ÿÛy¡˙fb≤üŒHÜAëÕNq=´@ ’cQdÖúAÉIqñŸ˘+2&∏ Àù.gÅ‚ƒœ3EPƒOi—‰:>ÍCäı
  421. =Õec=ëR˝”eñ=<V$ì˙+x+¢ïÒÕ<àeWå»–˚∫Õ d§&£àf ]fPA´âtënöå∏◊ó „Ë@∆≠K´÷˘}a_CI˚©yòHg,ôSSVìBƒl4 L.ÈY…á,2∂íäÙ.$ó¸CäŸ*€óy
  422. π?G,_√·ÆÎç=^Vkvo±ó{§ƒ2»±¨Ïüo»ëD-ãé fió¥cVÙ\'™G~\'p¢%* ã˚÷
  423. ªºnh˚ºO^∏…®[Ó“‚ÅfıÌ≥∫F!Eœ(π∑T6`¬tΩÆ0ì»rTÎ`»Ñ«
  424. ]≈åp˝)=¿Ô0∆öVÂmˇˆ„ø~¯ÁÔ∏b*fc»‡Îı„Ú}∆tœs∂Y∫ÜaÆ˙X∏~<ÿ·Ù vé1‹p¿TD∆ÔîÄ“úhˆ*Ú€îe)K –p¨ÚJ3Ÿ∞ã>ÊuNê°“√Ü ‹Ê9iÙ0˙AAEÍ ˙`∂£\'ûce•åƒX›ŸÁ´1SK{qdá"tÏ[wQ#SµBe∞∑µó…ÌV`B"Ñ≥„!è_Óφ-º*ºú¿Ë0ˆeê∂´ë+HFj…‡zvHÓN|ÔL÷ûñ3õÜ$z%sá…pÎóV38âs Çoµ•ß3†<9B·¨û~¢3)ÂxóÿÁCÕòÆ ∫Í=»ÿSπS;∆~±êÆTEp∑óÈ÷ÀuìDHÈ $ÉõæÜjû§"≤ÃONM®RËíRr{õS ∏Ê™op±W;ÂUÔ P∫kÔˇflTæ∑óflË” ÆC©Ô[≥◊HÁ˚¨hê"ÆbF?ú%h˙ˇ4xèÕ(ó2ÙáíM])Ñd|=fë-cI0ñL¢kÖêk‰Rƒ«ıÄWñ8mO3∏&√æËX¯Hó—ì]yF2»–˜ádàà‡‹Çο„≥7mªHAS∑¶.;Œx(1} _kd©.fidç48M\'àáªCp^Krí<ɉXÓıïl!Ì$N<ı∞B»G]…∂Ó¯>˛ÔbõÒπÀ•:ôO<j∂™œ%âÏ—>@È$pÖu‹Ê´-QqV ?V≥JÆÍqÛX8(lπï@zgÖ}Fe<ˇ‡Sñ“ÿ˜ê?6‡L∫Oß~µ –?ËeäÚ®YîÕ =Ü=¢DÁu*GvBk;)L¬N«î:flö∂≠ÇΩq„Ñm하Ë∂‚"û≥§:±≤i^ΩÑ!)Wıyŧô á„RÄ÷Òôc’≠—s™rı‚Pdêãh˘ßHVç5fifiÈF€çÌÛuçÖ/M=gëµ±ÿGû1coÔuñæ‘z®. õ∑7ÉÏÜÆ,°’H†ÍÉÌ∂7e º® íˆ⁄◊øNWK”ÂYµ‚ñé;µ¶gV-fl>µtË¥áßN2 ¯¶BaP-)eW.àôt^∏1›C∑Ö?L„&”5’4jvã–ªZ ÷+4% ´0l…»ú^°´© ûiπ∑é®óܱÒÿ‰ïˆÌ–dˆ◊Æ19rQ=Í|ı•rMæ¬;ò‰Y‰é9.” ‹˝V«ã¯∏,+ë®j*¡·/';
  425. $model = new AppModel(array('name' => 'BinaryTest', 'ds' => 'test'));
  426. $model->save(compact('data'));
  427. $result = $model->find('first');
  428. $this->assertEquals($data, $result['BinaryTest']['data']);
  429. }
  430. /**
  431. * Tests passing PostgreSQL regular expression operators when building queries
  432. *
  433. * @return void
  434. */
  435. public function testRegexpOperatorConditionsParsing() {
  436. $this->assertSame(' WHERE "name" ~ \'[a-z_]+\'', $this->Dbo->conditions(array('name ~' => '[a-z_]+')));
  437. $this->assertSame(' WHERE "name" ~* \'[a-z_]+\'', $this->Dbo->conditions(array('name ~*' => '[a-z_]+')));
  438. $this->assertSame(' WHERE "name" !~ \'[a-z_]+\'', $this->Dbo->conditions(array('name !~' => '[a-z_]+')));
  439. $this->assertSame(' WHERE "name" !~* \'[a-z_]+\'', $this->Dbo->conditions(array('name !~*' => '[a-z_]+')));
  440. }
  441. /**
  442. * Tests the syntax of generated schema indexes
  443. *
  444. * @return void
  445. */
  446. public function testSchemaIndexSyntax() {
  447. $schema = new CakeSchema();
  448. $schema->tables = array('i18n' => array(
  449. 'id' => array(
  450. 'type' => 'integer', 'null' => false, 'default' => null,
  451. 'length' => 10, 'key' => 'primary'
  452. ),
  453. 'locale' => array('type' => 'string', 'null' => false, 'length' => 6, 'key' => 'index'),
  454. 'model' => array('type' => 'string', 'null' => false, 'key' => 'index'),
  455. 'foreign_key' => array(
  456. 'type' => 'integer', 'null' => false, 'length' => 10, 'key' => 'index'
  457. ),
  458. 'field' => array('type' => 'string', 'null' => false, 'key' => 'index'),
  459. 'content' => array('type' => 'text', 'null' => true, 'default' => null),
  460. 'indexes' => array(
  461. 'PRIMARY' => array('column' => 'id', 'unique' => 1),
  462. 'locale' => array('column' => 'locale', 'unique' => 0),
  463. 'model' => array('column' => 'model', 'unique' => 0),
  464. 'row_id' => array('column' => 'foreign_key', 'unique' => 0),
  465. 'field' => array('column' => 'field', 'unique' => 0)
  466. )
  467. ));
  468. $result = $this->Dbo->createSchema($schema);
  469. $this->assertNotRegExp('/^CREATE INDEX(.+);,$/', $result);
  470. }
  471. /**
  472. * testCakeSchema method
  473. *
  474. * Test that schema generated postgresql queries are valid. ref #5696
  475. * Check that the create statement for a schema generated table is the same as the original sql
  476. *
  477. * @return void
  478. */
  479. public function testCakeSchema() {
  480. $db1 = ConnectionManager::getDataSource('test');
  481. $db1->cacheSources = false;
  482. $db1->rawQuery('CREATE TABLE ' . $db1->fullTableName('datatype_tests') . ' (
  483. id serial NOT NULL,
  484. "varchar" character varying(40) NOT NULL,
  485. "full_length" character varying NOT NULL,
  486. "huge_int" bigint NOT NULL,
  487. "timestamp" timestamp without time zone,
  488. "date" date,
  489. CONSTRAINT test_data_types_pkey PRIMARY KEY (id)
  490. )');
  491. $schema = new CakeSchema(array('connection' => 'test'));
  492. $result = $schema->read(array(
  493. 'connection' => 'test',
  494. 'models' => array('DatatypeTest')
  495. ));
  496. $schema->tables = array(
  497. 'datatype_tests' => $result['tables']['missing']['datatype_tests']
  498. );
  499. $result = $db1->createSchema($schema, 'datatype_tests');
  500. $this->assertNotRegExp('/timestamp DEFAULT/', $result);
  501. $this->assertRegExp('/\"full_length\"\s*text\s.*,/', $result);
  502. $this->assertContains('timestamp ,', $result);
  503. $this->assertContains('"huge_int" bigint NOT NULL,', $result);
  504. $db1->query('DROP TABLE ' . $db1->fullTableName('datatype_tests'));
  505. $db1->query($result);
  506. $result2 = $schema->read(array(
  507. 'connection' => 'test',
  508. 'models' => array('DatatypeTest')
  509. ));
  510. $schema->tables = array('datatype_tests' => $result2['tables']['missing']['datatype_tests']);
  511. $result2 = $db1->createSchema($schema, 'datatype_tests');
  512. $this->assertEquals($result, $result2);
  513. $db1->query('DROP TABLE ' . $db1->fullTableName('datatype_tests'));
  514. }
  515. /**
  516. * Test index generation from table info.
  517. *
  518. * @return void
  519. */
  520. public function testIndexGeneration() {
  521. $name = $this->Dbo->fullTableName('index_test', false, false);
  522. $this->Dbo->query('CREATE TABLE ' . $name . ' ("id" serial NOT NULL PRIMARY KEY, "bool" integer, "small_char" varchar(50), "description" varchar(40) )');
  523. $this->Dbo->query('CREATE INDEX pointless_bool ON ' . $name . '("bool")');
  524. $this->Dbo->query('CREATE UNIQUE INDEX char_index ON ' . $name . '("small_char")');
  525. $expected = array(
  526. 'PRIMARY' => array('unique' => true, 'column' => 'id'),
  527. 'pointless_bool' => array('unique' => false, 'column' => 'bool'),
  528. 'char_index' => array('unique' => true, 'column' => 'small_char'),
  529. );
  530. $result = $this->Dbo->index($name);
  531. $this->Dbo->query('DROP TABLE ' . $name);
  532. $this->assertEquals($expected, $result);
  533. $name = $this->Dbo->fullTableName('index_test_2', false, false);
  534. $this->Dbo->query('CREATE TABLE ' . $name . ' ("id" serial NOT NULL PRIMARY KEY, "bool" integer, "small_char" varchar(50), "description" varchar(40) )');
  535. $this->Dbo->query('CREATE UNIQUE INDEX multi_col ON ' . $name . '("small_char", "bool")');
  536. $expected = array(
  537. 'PRIMARY' => array('unique' => true, 'column' => 'id'),
  538. 'multi_col' => array('unique' => true, 'column' => array('small_char', 'bool')),
  539. );
  540. $result = $this->Dbo->index($name);
  541. $this->Dbo->query('DROP TABLE ' . $name);
  542. $this->assertEquals($expected, $result);
  543. }
  544. /**
  545. * Test the alterSchema capabilities of postgres
  546. *
  547. * @return void
  548. */
  549. public function testAlterSchema() {
  550. $Old = new CakeSchema(array(
  551. 'connection' => 'test',
  552. 'name' => 'AlterPosts',
  553. 'alter_posts' => array(
  554. 'id' => array('type' => 'integer', 'key' => 'primary'),
  555. 'author_id' => array('type' => 'integer', 'null' => false),
  556. 'title' => array('type' => 'string', 'null' => true),
  557. 'body' => array('type' => 'text'),
  558. 'published' => array('type' => 'string', 'length' => 1, 'default' => 'N'),
  559. 'created' => array('type' => 'datetime'),
  560. 'updated' => array('type' => 'datetime'),
  561. )
  562. ));
  563. $this->Dbo->query($this->Dbo->createSchema($Old));
  564. $New = new CakeSchema(array(
  565. 'connection' => 'test',
  566. 'name' => 'AlterPosts',
  567. 'alter_posts' => array(
  568. 'id' => array('type' => 'integer', 'key' => 'primary'),
  569. 'author_id' => array('type' => 'integer', 'null' => true),
  570. 'title' => array('type' => 'string', 'null' => false, 'default' => 'my title'),
  571. 'body' => array('type' => 'string', 'length' => 500),
  572. 'status' => array('type' => 'integer', 'length' => 3, 'default' => 1),
  573. 'created' => array('type' => 'datetime'),
  574. 'updated' => array('type' => 'datetime'),
  575. )
  576. ));
  577. $this->Dbo->query($this->Dbo->alterSchema($New->compare($Old), 'alter_posts'));
  578. $model = new CakeTestModel(array('table' => 'alter_posts', 'ds' => 'test'));
  579. $result = $model->schema();
  580. $this->assertTrue(isset($result['status']));
  581. $this->assertFalse(isset($result['published']));
  582. $this->assertEquals('string', $result['body']['type']);
  583. $this->assertEquals(1, $result['status']['default']);
  584. $this->assertEquals(true, $result['author_id']['null']);
  585. $this->assertEquals(false, $result['title']['null']);
  586. $this->Dbo->query($this->Dbo->dropSchema($New));
  587. $New = new CakeSchema(array(
  588. 'connection' => 'test_suite',
  589. 'name' => 'AlterPosts',
  590. 'alter_posts' => array(
  591. 'id' => array('type' => 'string', 'length' => 36, 'key' => 'primary'),
  592. 'author_id' => array('type' => 'integer', 'null' => false),
  593. 'title' => array('type' => 'string', 'null' => true),
  594. 'body' => array('type' => 'text'),
  595. 'published' => array('type' => 'string', 'length' => 1, 'default' => 'N'),
  596. 'created' => array('type' => 'datetime'),
  597. 'updated' => array('type' => 'datetime'),
  598. )
  599. ));
  600. $result = $this->Dbo->alterSchema($New->compare($Old), 'alter_posts');
  601. $this->assertNotRegExp('/varchar\(36\) NOT NULL/i', $result);
  602. }
  603. /**
  604. * Test the alter index capabilities of postgres
  605. *
  606. * @return void
  607. */
  608. public function testAlterIndexes() {
  609. $this->Dbo->cacheSources = false;
  610. $schema1 = new CakeSchema(array(
  611. 'name' => 'AlterTest1',
  612. 'connection' => 'test',
  613. 'altertest' => array(
  614. 'id' => array('type' => 'integer', 'null' => false, 'default' => 0),
  615. 'name' => array('type' => 'string', 'null' => false, 'length' => 50),
  616. 'group1' => array('type' => 'integer', 'null' => true),
  617. 'group2' => array('type' => 'integer', 'null' => true)
  618. )
  619. ));
  620. $this->Dbo->rawQuery($this->Dbo->createSchema($schema1));
  621. $schema2 = new CakeSchema(array(
  622. 'name' => 'AlterTest2',
  623. 'connection' => 'test',
  624. 'altertest' => array(
  625. 'id' => array('type' => 'integer', 'null' => false, 'default' => 0),
  626. 'name' => array('type' => 'string', 'null' => false, 'length' => 50),
  627. 'group1' => array('type' => 'integer', 'null' => true),
  628. 'group2' => array('type' => 'integer', 'null' => true),
  629. 'indexes' => array(
  630. 'name_idx' => array('unique' => false, 'column' => 'name'),
  631. 'group_idx' => array('unique' => false, 'column' => 'group1'),
  632. 'compound_idx' => array('unique' => false, 'column' => array('group1', 'group2')),
  633. 'PRIMARY' => array('unique' => true, 'column' => 'id')
  634. )
  635. )
  636. ));
  637. $this->Dbo->query($this->Dbo->alterSchema($schema2->compare($schema1)));
  638. $indexes = $this->Dbo->index('altertest');
  639. $this->assertEquals($schema2->tables['altertest']['indexes'], $indexes);
  640. // Change three indexes, delete one and add another one
  641. $schema3 = new CakeSchema(array(
  642. 'name' => 'AlterTest3',
  643. 'connection' => 'test',
  644. 'altertest' => array(
  645. 'id' => array('type' => 'integer', 'null' => false, 'default' => 0),
  646. 'name' => array('type' => 'string', 'null' => false, 'length' => 50),
  647. 'group1' => array('type' => 'integer', 'null' => true),
  648. 'group2' => array('type' => 'integer', 'null' => true),
  649. 'indexes' => array(
  650. 'name_idx' => array('unique' => true, 'column' => 'name'),
  651. 'group_idx' => array('unique' => false, 'column' => 'group2'),
  652. 'compound_idx' => array('unique' => false, 'column' => array('group2', 'group1')),
  653. 'another_idx' => array('unique' => false, 'column' => array('group1', 'name')))
  654. )));
  655. $this->Dbo->query($this->Dbo->alterSchema($schema3->compare($schema2)));
  656. $indexes = $this->Dbo->index('altertest');
  657. $this->assertEquals($schema3->tables['altertest']['indexes'], $indexes);
  658. // Compare us to ourself.
  659. $this->assertEquals(array(), $schema3->compare($schema3));
  660. // Drop the indexes
  661. $this->Dbo->query($this->Dbo->alterSchema($schema1->compare($schema3)));
  662. $indexes = $this->Dbo->index('altertest');
  663. $this->assertEquals(array(), $indexes);
  664. $this->Dbo->query($this->Dbo->dropSchema($schema1));
  665. }
  666. /**
  667. * Test the alterSchema RENAME statements
  668. *
  669. * @return void
  670. */
  671. public function testAlterSchemaRenameTo() {
  672. $query = $this->Dbo->alterSchema(array(
  673. 'posts' => array(
  674. 'change' => array(
  675. 'title' => array('name' => 'subject', 'type' => 'string', 'null' => false)
  676. )
  677. )
  678. ));
  679. $this->assertContains('RENAME "title" TO "subject";', $query);
  680. $this->assertContains('ALTER COLUMN "subject" TYPE', $query);
  681. $this->assertNotContains(";\n\tALTER COLUMN \"subject\" TYPE", $query);
  682. $this->assertNotContains('ALTER COLUMN "title" TYPE "subject"', $query);
  683. }
  684. /**
  685. * Test it is possible to use virtual field with postgresql
  686. *
  687. * @return void
  688. */
  689. public function testVirtualFields() {
  690. $this->loadFixtures('Article', 'Comment', 'User', 'Attachment', 'Tag', 'ArticlesTag');
  691. $Article = new Article;
  692. $Article->virtualFields = array(
  693. 'next_id' => 'Article.id + 1',
  694. 'complex' => 'Article.title || Article.body',
  695. 'functional' => 'COALESCE(User.user, Article.title)',
  696. 'subquery' => 'SELECT count(*) FROM ' . $Article->Comment->table
  697. );
  698. $result = $Article->find('first');
  699. $this->assertEquals(2, $result['Article']['next_id']);
  700. $this->assertEquals($result['Article']['complex'], $result['Article']['title'] . $result['Article']['body']);
  701. $this->assertEquals($result['Article']['functional'], $result['User']['user']);
  702. $this->assertEquals(6, $result['Article']['subquery']);
  703. }
  704. /**
  705. * Test that virtual fields work with SQL constants
  706. *
  707. * @return void
  708. */
  709. public function testVirtualFieldAsAConstant() {
  710. $this->loadFixtures('Article', 'Comment');
  711. $Article = ClassRegistry::init('Article');
  712. $Article->virtualFields = array(
  713. 'empty' => "NULL",
  714. 'number' => 43,
  715. 'truth' => 'TRUE'
  716. );
  717. $result = $Article->find('first');
  718. $this->assertNull($result['Article']['empty']);
  719. $this->assertTrue($result['Article']['truth']);
  720. $this->assertEquals(43, $result['Article']['number']);
  721. }
  722. /**
  723. * Tests additional order options for postgres
  724. *
  725. * @return void
  726. */
  727. public function testOrderAdditionalParams() {
  728. $result = $this->Dbo->order(array('title' => 'DESC NULLS FIRST', 'body' => 'DESC'));
  729. $expected = ' ORDER BY "title" DESC NULLS FIRST, "body" DESC';
  730. $this->assertEquals($expected, $result);
  731. }
  732. /**
  733. * Test it is possible to do a SELECT COUNT(DISTINCT Model.field)
  734. * query in postgres and it gets correctly quoted
  735. *
  736. * @return void
  737. */
  738. public function testQuoteDistinctInFunction() {
  739. $this->loadFixtures('Article');
  740. $Article = new Article;
  741. $result = $this->Dbo->fields($Article, null, array('COUNT(DISTINCT Article.id)'));
  742. $expected = array('COUNT(DISTINCT "Article"."id")');
  743. $this->assertEquals($expected, $result);
  744. $result = $this->Dbo->fields($Article, null, array('COUNT(DISTINCT id)'));
  745. $expected = array('COUNT(DISTINCT "id")');
  746. $this->assertEquals($expected, $result);
  747. $result = $this->Dbo->fields($Article, null, array('COUNT(DISTINCT FUNC(id))'));
  748. $expected = array('COUNT(DISTINCT FUNC("id"))');
  749. $this->assertEquals($expected, $result);
  750. }
  751. /**
  752. * test that saveAll works even with conditions that lack a model name.
  753. *
  754. * @return void
  755. */
  756. public function testUpdateAllWithNonQualifiedConditions() {
  757. $this->loadFixtures('Article');
  758. $Article = new Article();
  759. $result = $Article->updateAll(array('title' => "'Awesome'"), array('title' => 'Third Article'));
  760. $this->assertTrue($result);
  761. $result = $Article->find('count', array(
  762. 'conditions' => array('Article.title' => 'Awesome')
  763. ));
  764. $this->assertEquals(1, $result, 'Article count is wrong or fixture has changed.');
  765. }
  766. /**
  767. * test alterSchema on two tables.
  768. *
  769. * @return void
  770. */
  771. public function testAlteringTwoTables() {
  772. $schema1 = new CakeSchema(array(
  773. 'name' => 'AlterTest1',
  774. 'connection' => 'test',
  775. 'altertest' => array(
  776. 'id' => array('type' => 'integer', 'null' => false, 'default' => 0),
  777. 'name' => array('type' => 'string', 'null' => false, 'length' => 50),
  778. ),
  779. 'other_table' => array(
  780. 'id' => array('type' => 'integer', 'null' => false, 'default' => 0),
  781. 'name' => array('type' => 'string', 'null' => false, 'length' => 50),
  782. )
  783. ));
  784. $schema2 = new CakeSchema(array(
  785. 'name' => 'AlterTest1',
  786. 'connection' => 'test',
  787. 'altertest' => array(
  788. 'id' => array('type' => 'integer', 'null' => false, 'default' => 0),
  789. 'field_two' => array('type' => 'string', 'null' => false, 'length' => 50),
  790. ),
  791. 'other_table' => array(
  792. 'id' => array('type' => 'integer', 'null' => false, 'default' => 0),
  793. 'field_two' => array('type' => 'string', 'null' => false, 'length' => 50),
  794. )
  795. ));
  796. $result = $this->db->alterSchema($schema2->compare($schema1));
  797. $this->assertEquals(2, substr_count($result, 'field_two'), 'Too many fields');
  798. $this->assertFalse(strpos(';ALTER', $result), 'Too many semi colons');
  799. }
  800. /**
  801. * test encoding setting.
  802. *
  803. * @return void
  804. */
  805. public function testEncoding() {
  806. $result = $this->Dbo->setEncoding('UTF8');
  807. $this->assertTrue($result);
  808. $result = $this->Dbo->getEncoding();
  809. $this->assertEquals('UTF8', $result);
  810. $result = $this->Dbo->setEncoding('EUC_JP'); /* 'EUC_JP' is right character code name in PostgreSQL */
  811. $this->assertTrue($result);
  812. $result = $this->Dbo->getEncoding();
  813. $this->assertEquals('EUC_JP', $result);
  814. }
  815. /**
  816. * Test truncate with a mock.
  817. *
  818. * @return void
  819. */
  820. public function testTruncateStatements() {
  821. $this->loadFixtures('Article', 'User');
  822. $db = ConnectionManager::getDatasource('test');
  823. $schema = $db->config['schema'];
  824. $Article = new Article();
  825. $this->Dbo = $this->getMock('Postgres', array('execute'), array($db->config));
  826. $this->Dbo->expects($this->at(0))->method('execute')
  827. ->with("DELETE FROM \"$schema\".\"articles\"");
  828. $this->Dbo->truncate($Article);
  829. $this->Dbo->expects($this->at(0))->method('execute')
  830. ->with("DELETE FROM \"$schema\".\"articles\"");
  831. $this->Dbo->truncate('articles');
  832. // #2355: prevent duplicate prefix
  833. $this->Dbo->config['prefix'] = 'tbl_';
  834. $Article->tablePrefix = 'tbl_';
  835. $this->Dbo->expects($this->at(0))->method('execute')
  836. ->with("DELETE FROM \"$schema\".\"tbl_articles\"");
  837. $this->Dbo->truncate($Article);
  838. $this->Dbo->expects($this->at(0))->method('execute')
  839. ->with("DELETE FROM \"$schema\".\"tbl_articles\"");
  840. $this->Dbo->truncate('articles');
  841. }
  842. /**
  843. * Test nested transaction
  844. *
  845. * @return void
  846. */
  847. public function testNestedTransaction() {
  848. $this->Dbo->useNestedTransactions = true;
  849. $this->skipIf($this->Dbo->nestedTransactionSupported() === false, 'The Postgres server do not support nested transaction');
  850. $this->loadFixtures('Article');
  851. $model = new Article();
  852. $model->hasOne = $model->hasMany = $model->belongsTo = $model->hasAndBelongsToMany = array();
  853. $model->cacheQueries = false;
  854. $this->Dbo->cacheMethods = false;
  855. $this->assertTrue($this->Dbo->begin());
  856. $this->assertNotEmpty($model->read(null, 1));
  857. $this->assertTrue($this->Dbo->begin());
  858. $this->assertTrue($model->delete(1));
  859. $this->assertEmpty($model->read(null, 1));
  860. $this->assertTrue($this->Dbo->rollback());
  861. $this->assertNotEmpty($model->read(null, 1));
  862. $this->assertTrue($this->Dbo->begin());
  863. $this->assertTrue($model->delete(1));
  864. $this->assertEmpty($model->read(null, 1));
  865. $this->assertTrue($this->Dbo->commit());
  866. $this->assertEmpty($model->read(null, 1));
  867. $this->assertTrue($this->Dbo->rollback());
  868. $this->assertNotEmpty($model->read(null, 1));
  869. }
  870. public function testResetSequence() {
  871. $model = new Article();
  872. $table = $this->Dbo->fullTableName($model, false);
  873. $fields = array(
  874. 'id', 'user_id', 'title', 'body', 'published',
  875. );
  876. $values = array(
  877. array(1, 1, 'test', 'first post', false),
  878. array(2, 1, 'test 2', 'second post post', false),
  879. );
  880. $this->Dbo->insertMulti($table, $fields, $values);
  881. $sequence = $this->Dbo->getSequence($table);
  882. $result = $this->Dbo->rawQuery("SELECT nextval('$sequence')");
  883. $original = $result->fetch(PDO::FETCH_ASSOC);
  884. $this->assertTrue($this->Dbo->resetSequence($table, 'id'));
  885. $result = $this->Dbo->rawQuery("SELECT currval('$sequence')");
  886. $new = $result->fetch(PDO::FETCH_ASSOC);
  887. $this->assertTrue($new['currval'] > $original['nextval'], 'Sequence did not update');
  888. }
  889. }