CMssqlPdoAdapter.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * CMssqlPdo class file
  4. *
  5. * @author Christophe Boulain <Christophe.Boulain@gmail.com>
  6. * @link http://www.yiiframework.com/
  7. * @copyright 2008-2013 Yii Software LLC
  8. * @license http://www.yiiframework.com/license/
  9. */
  10. /**
  11. * This is an extension of default PDO class for mssql driver only
  12. * It provides some missing functionalities of pdo driver
  13. * @author Christophe Boulain <Christophe.Boulain@gmail.com>
  14. * @package system.db.schema.mssql
  15. */
  16. class CMssqlPdoAdapter extends PDO
  17. {
  18. /**
  19. * Get the last inserted id value
  20. * MSSQL doesn't support sequence, so, argument is ignored
  21. *
  22. * @param string|null sequence name. Defaults to null
  23. * @return integer last inserted id
  24. */
  25. public function lastInsertId ($sequence=NULL)
  26. {
  27. return $this->query('SELECT CAST(COALESCE(SCOPE_IDENTITY(), @@IDENTITY) AS bigint)')->fetchColumn();
  28. }
  29. /**
  30. * Begin a transaction
  31. *
  32. * Is is necessary to override pdo's method, as mssql pdo drivers
  33. * does not support transaction
  34. *
  35. * @return boolean
  36. */
  37. public function beginTransaction ()
  38. {
  39. $this->exec('BEGIN TRANSACTION');
  40. return true;
  41. }
  42. /**
  43. * Commit a transaction
  44. *
  45. * Is is necessary to override pdo's method, as mssql pdo drivers
  46. * does not support transaction
  47. *
  48. * @return boolean
  49. */
  50. public function commit ()
  51. {
  52. $this->exec('COMMIT TRANSACTION');
  53. return true;
  54. }
  55. /**
  56. * Rollback a transaction
  57. *
  58. * Is is necessary to override pdo's method, ac mssql pdo drivers
  59. * does not support transaction
  60. *
  61. * @return boolean
  62. */
  63. public function rollBack ()
  64. {
  65. $this->exec('ROLLBACK TRANSACTION');
  66. return true;
  67. }
  68. }