/library/Doctrine/Doctrine/Connection/Sqlite.php

https://github.com/ostric/e-learning · PHP · 141 lines · 71 code · 14 blank · 56 comment · 4 complexity · 1b509c7c45b8a99bb1b933a501441ae8 MD5 · raw file

  1. <?php
  2. /*
  3. * $Id: Sqlite.php 4252 2008-04-19 07:37:53Z 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.phpdoctrine.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: 4252 $
  30. * @link www.phpdoctrine.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', 'time', 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', 'time', 0);
  90. }
  91. /**
  92. * createDatabase
  93. *
  94. * @return void
  95. */
  96. public function createDatabase()
  97. {
  98. try {
  99. if ( ! $dsn = $this->getOption('dsn')) {
  100. 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');
  101. }
  102. $info = $this->getManager()->parseDsn($dsn);
  103. $this->export->createDatabase($info['database']);
  104. return 'Successfully created database for connection "' . $this->getName() . '" at path "' . $info['database'] . '"';
  105. } catch (Exception $e) {
  106. return $e;
  107. }
  108. }
  109. /**
  110. * dropDatabase
  111. *
  112. * @return void
  113. */
  114. public function dropDatabase()
  115. {
  116. try {
  117. if ( ! $dsn = $this->getOption('dsn')) {
  118. 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');
  119. }
  120. $info = $this->getManager()->parseDsn($dsn);
  121. $this->export->dropDatabase($info['database']);
  122. return 'Successfully dropped database for connection "' . $this->getName() . '" at path "' . $info['database'] . '"';
  123. } catch (Exception $e) {
  124. return $e;
  125. }
  126. }
  127. }