Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

87 lines
2.6KB

  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yii\db\mssql;
  8. /**
  9. * This is an extension of the default PDO class of MSSQL and DBLIB drivers.
  10. * It provides workarounds for improperly implemented functionalities of the MSSQL and DBLIB drivers.
  11. *
  12. * @author Timur Ruziev <resurtm@gmail.com>
  13. * @since 2.0
  14. */
  15. class PDO extends \PDO
  16. {
  17. /**
  18. * Returns value of the last inserted ID.
  19. * @param string|null $sequence the sequence name. Defaults to null.
  20. * @return integer last inserted ID value.
  21. */
  22. public function lastInsertId($sequence = null)
  23. {
  24. return $this->query('SELECT CAST(COALESCE(SCOPE_IDENTITY(), @@IDENTITY) AS bigint)')->fetchColumn();
  25. }
  26. /**
  27. * Starts a transaction. It is necessary to override PDO's method as MSSQL PDO driver does not
  28. * natively support transactions.
  29. * @return boolean the result of a transaction start.
  30. */
  31. public function beginTransaction()
  32. {
  33. $this->exec('BEGIN TRANSACTION');
  34. return true;
  35. }
  36. /**
  37. * Commits a transaction. It is necessary to override PDO's method as MSSQL PDO driver does not
  38. * natively support transactions.
  39. * @return boolean the result of a transaction commit.
  40. */
  41. public function commit()
  42. {
  43. $this->exec('COMMIT TRANSACTION');
  44. return true;
  45. }
  46. /**
  47. * Rollbacks a transaction. It is necessary to override PDO's method as MSSQL PDO driver does not
  48. * natively support transactions.
  49. * @return boolean the result of a transaction roll back.
  50. */
  51. public function rollBack()
  52. {
  53. $this->exec('ROLLBACK TRANSACTION');
  54. return true;
  55. }
  56. /**
  57. * Retrieve a database connection attribute.
  58. * It is necessary to override PDO's method as some MSSQL PDO driver (e.g. dblib) does not
  59. * support getting attributes
  60. * @param integer $attribute One of the PDO::ATTR_* constants.
  61. * @return mixed A successful call returns the value of the requested PDO attribute.
  62. * An unsuccessful call returns null.
  63. */
  64. public function getAttribute($attribute)
  65. {
  66. try {
  67. return parent::getAttribute($attribute);
  68. } catch (\PDOException $e) {
  69. switch ($attribute) {
  70. case PDO::ATTR_SERVER_VERSION:
  71. return $this->query("SELECT CAST(SERVERPROPERTY('productversion') AS VARCHAR)")->fetchColumn();
  72. default:
  73. throw $e;
  74. }
  75. }
  76. }
  77. }