SQLServer2008Platform.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /*
  3. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  4. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  5. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  6. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  7. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  8. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  9. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  10. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  11. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  12. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  13. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. *
  15. * This software consists of voluntary contributions made by many individuals
  16. * and is licensed under the LGPL. For more information, see
  17. * <http://www.doctrine-project.org>.
  18. */
  19. namespace Doctrine\DBAL\Platforms;
  20. /**
  21. * Platform to ensure compatibility of Doctrine with SQLServer2008 version.
  22. *
  23. * Differences to SQL Server 2005 and before are that a new DATETIME2 type was
  24. * introduced that has a higher precision.
  25. */
  26. class SQLServer2008Platform extends SQLServer2005Platform
  27. {
  28. /**
  29. * @override
  30. */
  31. public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration)
  32. {
  33. // 3 - microseconds precision length
  34. // http://msdn.microsoft.com/en-us/library/ms187819.aspx
  35. return 'DATETIME2(6)';
  36. }
  37. /**
  38. * @override
  39. */
  40. public function getDateTypeDeclarationSQL(array $fieldDeclaration)
  41. {
  42. return 'DATE';
  43. }
  44. /**
  45. * @override
  46. */
  47. public function getTimeTypeDeclarationSQL(array $fieldDeclaration)
  48. {
  49. return 'TIME(0)';
  50. }
  51. /**
  52. * @override
  53. */
  54. public function getDateTimeFormatString()
  55. {
  56. return 'Y-m-d H:i:s.u';
  57. }
  58. /**
  59. * @override
  60. */
  61. public function getDateFormatString()
  62. {
  63. return 'Y-m-d';
  64. }
  65. /**
  66. * @override
  67. */
  68. public function getTimeFormatString()
  69. {
  70. return 'H:i:s';
  71. }
  72. /**
  73. * Adding Datetime2 Type
  74. */
  75. protected function initializeDoctrineTypeMappings()
  76. {
  77. parent::initializeDoctrineTypeMappings();
  78. $this->doctrineTypeMapping['datetime2'] = 'datetime';
  79. $this->doctrineTypeMapping['date'] = 'date';
  80. $this->doctrineTypeMapping['time'] = 'time';
  81. }
  82. }