PageRenderTime 69ms CodeModel.GetById 36ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection/Sqlite.php

https://bitbucket.org/pycmam/symfony
PHP | 129 lines | 61 code | 12 blank | 56 comment | 4 complexity | a66a35d0b753a2427b98a149628e4c0c MD5 | raw file
Possible License(s): AGPL-3.0, LGPL-2.1, BSD-3-Clause, LGPL-3.0, ISC
  1. <?php
  2. /*
  3. * $Id: Sqlite.php 7490 2010-03-29 19:53:27Z jwage $
  4. *
  5. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. *
  17. * This software consists of voluntary contributions made by many individuals
  18. * and is licensed under the LGPL. For more information, see
  19. * <http://www.doctrine-project.org>.
  20. */
  21. /**
  22. * Doctrine_Connection_Sqlite
  23. *
  24. * @package Doctrine
  25. * @subpackage Connection
  26. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  27. * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
  28. * @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
  29. * @version $Revision: 7490 $
  30. * @link www.doctrine-project.org
  31. * @since 1.0
  32. */
  33. class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common
  34. {
  35. /**
  36. * @var string $driverName the name of this connection driver
  37. */
  38. protected $driverName = 'Sqlite';
  39. /**
  40. * the constructor
  41. *
  42. * @param Doctrine_Manager $manager
  43. * @param PDO $pdo database handle
  44. */
  45. public function __construct(Doctrine_Manager $manager, $adapter)
  46. {
  47. $this->supported = array('sequences' => 'emulated',
  48. 'indexes' => true,
  49. 'affected_rows' => true,
  50. 'summary_functions' => true,
  51. 'order_by_text' => true,
  52. 'current_id' => 'emulated',
  53. 'limit_queries' => true,
  54. 'LOBs' => true,
  55. 'replace' => true,
  56. 'transactions' => true,
  57. 'savepoints' => false,
  58. 'sub_selects' => true,
  59. 'auto_increment' => true,
  60. 'primary_key' => true,
  61. 'result_introspection' => false, // not implemented
  62. 'prepared_statements' => 'emulated',
  63. 'identifier_quoting' => true,
  64. 'pattern_escaping' => false,
  65. );
  66. parent::__construct($manager, $adapter);
  67. if ($this->isConnected) {
  68. $this->dbh->sqliteCreateFunction('mod', array('Doctrine_Expression_Sqlite', 'modImpl'), 2);
  69. $this->dbh->sqliteCreateFunction('concat', array('Doctrine_Expression_Sqlite', 'concatImpl'));
  70. $this->dbh->sqliteCreateFunction('md5', 'md5', 1);
  71. $this->dbh->sqliteCreateFunction('now', array('Doctrine_Expression_Sqlite', 'nowImpl'), 0);
  72. }
  73. }
  74. /**
  75. * initializes database functions missing in sqlite
  76. *
  77. * @see Doctrine_Expression
  78. * @return void
  79. */
  80. public function connect()
  81. {
  82. if ($this->isConnected) {
  83. return false;
  84. }
  85. parent::connect();
  86. $this->dbh->sqliteCreateFunction('mod', array('Doctrine_Expression_Sqlite', 'modImpl'), 2);
  87. $this->dbh->sqliteCreateFunction('concat', array('Doctrine_Expression_Sqlite', 'concatImpl'));
  88. $this->dbh->sqliteCreateFunction('md5', 'md5', 1);
  89. $this->dbh->sqliteCreateFunction('now', array('Doctrine_Expression_Sqlite', 'nowImpl'), 0);
  90. }
  91. /**
  92. * createDatabase
  93. *
  94. * @return void
  95. */
  96. public function createDatabase()
  97. {
  98. if ( ! $dsn = $this->getOption('dsn')) {
  99. throw new Doctrine_Connection_Exception('You must create your Doctrine_Connection by using a valid Doctrine style dsn in order to use the create/drop database functionality');
  100. }
  101. $info = $this->getManager()->parseDsn($dsn);
  102. $this->export->createDatabase($info['database']);
  103. }
  104. /**
  105. * dropDatabase
  106. *
  107. * @return void
  108. */
  109. public function dropDatabase()
  110. {
  111. if ( ! $dsn = $this->getOption('dsn')) {
  112. throw new Doctrine_Connection_Exception('You must create your Doctrine_Connection by using a valid Doctrine style dsn in order to use the create/drop database functionality');
  113. }
  114. $info = $this->getManager()->parseDsn($dsn);
  115. $this->export->dropDatabase($info['database']);
  116. }
  117. }