UtilTest.php 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace Doctrine\Tests\DBAL;
  3. require_once __DIR__ . '/../TestInit.php';
  4. class UtilTest extends \Doctrine\Tests\DbalTestCase
  5. {
  6. static public function dataConvertPositionalToNamedParameters()
  7. {
  8. return array(
  9. array(
  10. 'SELECT name FROM users WHERE id = ?',
  11. 'SELECT name FROM users WHERE id = :param1',
  12. array(1 => ':param1')
  13. ),
  14. array(
  15. 'SELECT name FROM users WHERE id = ? AND status = ?',
  16. 'SELECT name FROM users WHERE id = :param1 AND status = :param2',
  17. array(1 => ':param1', 2 => ':param2'),
  18. ),
  19. array(
  20. "UPDATE users SET name = '???', status = ?",
  21. "UPDATE users SET name = '???', status = :param1",
  22. array(1 => ':param1'),
  23. ),
  24. array(
  25. "UPDATE users SET status = ?, name = '???'",
  26. "UPDATE users SET status = :param1, name = '???'",
  27. array(1 => ':param1'),
  28. ),
  29. array(
  30. "UPDATE users SET foo = ?, name = '???', status = ?",
  31. "UPDATE users SET foo = :param1, name = '???', status = :param2",
  32. array(1 => ':param1', 2 => ':param2'),
  33. ),
  34. array(
  35. 'UPDATE users SET name = "???", status = ?',
  36. 'UPDATE users SET name = "???", status = :param1',
  37. array(1 => ':param1'),
  38. ),
  39. array(
  40. 'UPDATE users SET status = ?, name = "???"',
  41. 'UPDATE users SET status = :param1, name = "???"',
  42. array(1 => ':param1'),
  43. ),
  44. array(
  45. 'UPDATE users SET foo = ?, name = "???", status = ?',
  46. 'UPDATE users SET foo = :param1, name = "???", status = :param2',
  47. array(1 => ':param1', 2 => ':param2'),
  48. ),
  49. array(
  50. 'SELECT * FROM users WHERE id = ? AND name = "" AND status = ?',
  51. 'SELECT * FROM users WHERE id = :param1 AND name = "" AND status = :param2',
  52. array(1 => ':param1', 2 => ':param2'),
  53. ),
  54. array(
  55. "SELECT * FROM users WHERE id = ? AND name = '' AND status = ?",
  56. "SELECT * FROM users WHERE id = :param1 AND name = '' AND status = :param2",
  57. array(1 => ':param1', 2 => ':param2'),
  58. )
  59. );
  60. }
  61. /**
  62. * @dataProvider dataConvertPositionalToNamedParameters
  63. * @param string $inputSQL
  64. * @param string $expectedOutputSQL
  65. * @param array $expectedOutputParamsMap
  66. */
  67. public function testConvertPositionalToNamedParameters($inputSQL, $expectedOutputSQL, $expectedOutputParamsMap)
  68. {
  69. list($statement, $params) = \Doctrine\DBAL\Driver\OCI8\OCI8Statement::convertPositionalToNamedPlaceholders($inputSQL);
  70. $this->assertEquals($expectedOutputSQL, $statement);
  71. $this->assertEquals($expectedOutputParamsMap, $params);
  72. }
  73. }