sqlite.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4 |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2004 The PHP Group |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license, |
  9. // | that is bundled with this package in the file LICENSE, and is |
  10. // | available at through the world-wide-web at |
  11. // | http://www.php.net/license/2_02.txt. |
  12. // | If you did not receive a copy of the PHP license and are unable to |
  13. // | obtain it through the world-wide-web, please send a note to |
  14. // | license@php.net so we can mail you a copy immediately. |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Urs Gehrig <urs@circle.ch> |
  17. // | Mika Tuupola <tuupola@appelsiini.net> |
  18. // | Maintainer: Daniel Convissor <danielc@php.net> |
  19. // +----------------------------------------------------------------------+
  20. //
  21. // $Id: sqlite.php,v 1.58 2004/02/19 18:15:38 danielc Exp $
  22. // SQLite function set:
  23. // sqlite_open, sqlite_popen, sqlite_close, sqlite_query
  24. // sqlite_libversion, sqlite_libencoding, sqlite_changes
  25. // sqlite_num_rows, sqlite_num_fields, sqlite_field_name, sqlite_seek
  26. // sqlite_escape_string, sqlite_busy_timeout, sqlite_last_error
  27. // sqlite_error_string, sqlite_unbuffered_query, sqlite_create_aggregate
  28. // sqlite_create_function, sqlite_last_insert_rowid, sqlite_fetch_array
  29. //
  30. // Formatting:
  31. // # astyle --style=kr < sqlite.php > out.php
  32. //
  33. // Status:
  34. // EXPERIMENTAL
  35. /*
  36. * Example:
  37. *
  38. <?php
  39. require_once 'DB.php';
  40. // Define a DSN
  41. $dsn = 'sqlite://dummy:@localhost/' . getcwd() . '/test.db?mode=0644';
  42. $db = DB::connect($dsn, false);
  43. // Give a new table name
  44. $table = 'tbl_' . md5(uniqid(rand()));
  45. $table = substr($table, 0, 10);
  46. // Create a new table
  47. $result = $db->query("CREATE TABLE $table (comment varchar(50),
  48. datetime varchar(50));");
  49. $result = $db->query("INSERT INTO $table VALUES ('Date and Time', '" .
  50. date('Y-m-j H:i:s') . "');");
  51. // Get results
  52. printf("affectedRows:\t\t%s\n", $db->affectedRows());
  53. $result = $db->query("SELECT FROM $table;");
  54. $arr = $db->fetchRow($result);
  55. print_r($arr);
  56. $db->disconnect();
  57. ?>
  58. *
  59. */
  60. require_once 'DB/common.php';
  61. /**
  62. * Database independent query interface definition for the SQLite
  63. * PECL extension.
  64. *
  65. * @package DB
  66. * @version $Id: sqlite.php,v 1.58 2004/02/19 18:15:38 danielc Exp $
  67. * @category Database
  68. * @author Urs Gehrig <urs@circle.ch>
  69. * @author Mika Tuupola <tuupola@appelsiini.net>
  70. */
  71. class DB_sqlite extends DB_common
  72. {
  73. // {{{ properties
  74. var $connection;
  75. var $phptype, $dbsyntax;
  76. var $prepare_tokens = array();
  77. var $prepare_types = array();
  78. var $_lasterror = '';
  79. // }}}
  80. // {{{ constructor
  81. /**
  82. * Constructor for this class.
  83. *
  84. * Error codes according to sqlite_exec. Error Codes specification is
  85. * in the {@link http://sqlite.org/c_interface.html online manual}.
  86. *
  87. * This errorhandling based on sqlite_exec is not yet implemented.
  88. *
  89. * @access public
  90. */
  91. function DB_sqlite()
  92. {
  93. $this->DB_common();
  94. $this->phptype = 'sqlite';
  95. $this->dbsyntax = 'sqlite';
  96. $this->features = array (
  97. 'prepare' => false,
  98. 'pconnect' => true,
  99. 'transactions' => false,
  100. 'limit' => 'alter'
  101. );
  102. // SQLite data types, http://www.sqlite.org/datatypes.html
  103. $this->keywords = array (
  104. 'BLOB' => '',
  105. 'BOOLEAN' => '',
  106. 'CHARACTER' => '',
  107. 'CLOB' => '',
  108. 'FLOAT' => '',
  109. 'INTEGER' => '',
  110. 'KEY' => '',
  111. 'NATIONAL' => '',
  112. 'NUMERIC' => '',
  113. 'NVARCHAR' => '',
  114. 'PRIMARY' => '',
  115. 'TEXT' => '',
  116. 'TIMESTAMP' => '',
  117. 'UNIQUE' => '',
  118. 'VARCHAR' => '',
  119. 'VARYING' => ''
  120. );
  121. $this->errorcode_map = array(
  122. );
  123. }
  124. // }}}
  125. // {{{ connect()
  126. /**
  127. * Connect to a database represented by a file.
  128. *
  129. * @param $dsn the data source name; the file is taken as
  130. * database; "sqlite://root:@host/test.db?mode=0644"
  131. * @param $persistent (optional) whether the connection should
  132. * be persistent
  133. * @access public
  134. * @return int DB_OK on success, a DB error on failure
  135. */
  136. function connect($dsninfo, $persistent = false)
  137. {
  138. if (!DB::assertExtension('sqlite')) {
  139. return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
  140. }
  141. $this->dsn = $dsninfo;
  142. if ($dsninfo['database']) {
  143. if (!file_exists($dsninfo['database'])) {
  144. if (!touch($dsninfo['database'])) {
  145. return $this->sqliteRaiseError(DB_ERROR_NOT_FOUND);
  146. }
  147. if (!isset($dsninfo['mode']) ||
  148. !is_numeric($dsninfo['mode']))
  149. {
  150. $mode = 0644;
  151. } else {
  152. $mode = octdec($dsninfo['mode']);
  153. }
  154. if (!chmod($dsninfo['database'], $mode)) {
  155. return $this->sqliteRaiseError(DB_ERROR_NOT_FOUND);
  156. }
  157. if (!file_exists($dsninfo['database'])) {
  158. return $this->sqliteRaiseError(DB_ERROR_NOT_FOUND);
  159. }
  160. }
  161. if (!is_file($dsninfo['database'])) {
  162. return $this->sqliteRaiseError(DB_ERROR_INVALID);
  163. }
  164. if (!is_readable($dsninfo['database'])) {
  165. return $this->sqliteRaiseError(DB_ERROR_ACCESS_VIOLATION);
  166. }
  167. } else {
  168. return $this->sqliteRaiseError(DB_ERROR_ACCESS_VIOLATION);
  169. }
  170. $connect_function = $persistent ? 'sqlite_popen' : 'sqlite_open';
  171. if (!($conn = @$connect_function($dsninfo['database']))) {
  172. return $this->sqliteRaiseError(DB_ERROR_NODBSELECTED);
  173. }
  174. $this->connection = $conn;
  175. return DB_OK;
  176. }
  177. // }}}
  178. // {{{ disconnect()
  179. /**
  180. * Log out and disconnect from the database.
  181. *
  182. * @access public
  183. * @return bool TRUE on success, FALSE if not connected.
  184. * @todo fix return values
  185. */
  186. function disconnect()
  187. {
  188. $ret = @sqlite_close($this->connection);
  189. $this->connection = null;
  190. return $ret;
  191. }
  192. // }}}
  193. // {{{ simpleQuery()
  194. /**
  195. * Send a query to SQLite and returns the results as a SQLite resource
  196. * identifier.
  197. *
  198. * @param the SQL query
  199. * @access public
  200. * @return mixed returns a valid SQLite result for successful SELECT
  201. * queries, DB_OK for other successful queries. A DB error is
  202. * returned on failure.
  203. */
  204. function simpleQuery($query)
  205. {
  206. $ismanip = DB::isManip($query);
  207. $this->last_query = $query;
  208. $query = $this->_modifyQuery($query);
  209. ini_set('track_errors', true);
  210. $result = @sqlite_query($query, $this->connection);
  211. ini_restore('track_errors');
  212. $this->_lasterror = isset($php_errormsg) ? $php_errormsg : '';
  213. $this->result = $result;
  214. if (!$this->result) {
  215. return $this->sqliteRaiseError(null);
  216. }
  217. /* sqlite_query() seems to allways return a resource */
  218. /* so cant use that. Using $ismanip instead */
  219. if (!$ismanip) {
  220. $numRows = $this->numRows($result);
  221. /* if numRows() returned PEAR_Error */
  222. if (is_object($numRows)) {
  223. return $numRows;
  224. }
  225. return $result;
  226. }
  227. return DB_OK;
  228. }
  229. // }}}
  230. // {{{ nextResult()
  231. /**
  232. * Move the internal sqlite result pointer to the next available result.
  233. *
  234. * @param a valid sqlite result resource
  235. * @access public
  236. * @return true if a result is available otherwise return false
  237. */
  238. function nextResult($result)
  239. {
  240. return false;
  241. }
  242. // }}}
  243. // {{{ fetchInto()
  244. /**
  245. * Fetch a row and insert the data into an existing array.
  246. *
  247. * Formating of the array and the data therein are configurable.
  248. * See DB_result::fetchInto() for more information.
  249. *
  250. * @param resource $result query result identifier
  251. * @param array $arr (reference) array where data from the row
  252. * should be placed
  253. * @param int $fetchmode how the resulting array should be indexed
  254. * @param int $rownum the row number to fetch
  255. *
  256. * @return mixed DB_OK on success, NULL when end of result set is
  257. * reached or on failure
  258. *
  259. * @see DB_result::fetchInto()
  260. * @access private
  261. */
  262. function fetchInto($result, &$arr, $fetchmode, $rownum=null)
  263. {
  264. if ($rownum !== null) {
  265. if (!@sqlite_seek($this->result, $rownum)) {
  266. return null;
  267. }
  268. }
  269. if ($fetchmode & DB_FETCHMODE_ASSOC) {
  270. $arr = sqlite_fetch_array($result, SQLITE_ASSOC);
  271. if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
  272. $arr = array_change_key_case($arr, CASE_LOWER);
  273. }
  274. } else {
  275. $arr = sqlite_fetch_array($result, SQLITE_NUM);
  276. }
  277. if (!$arr) {
  278. /* See: http://bugs.php.net/bug.php?id=22328 */
  279. return null;
  280. }
  281. if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
  282. /*
  283. * Even though this DBMS already trims output, we do this because
  284. * a field might have intentional whitespace at the end that
  285. * gets removed by DB_PORTABILITY_RTRIM under another driver.
  286. */
  287. $this->_rtrimArrayValues($arr);
  288. }
  289. if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
  290. $this->_convertNullArrayValuesToEmpty($arr);
  291. }
  292. return DB_OK;
  293. }
  294. // }}}
  295. // {{{ freeResult()
  296. /**
  297. * Free the internal resources associated with $result.
  298. *
  299. * @param $result SQLite result identifier
  300. * @access public
  301. * @return bool TRUE on success, FALSE if $result is invalid
  302. */
  303. function freeResult(&$result)
  304. {
  305. // XXX No native free?
  306. if (!is_resource($result)) {
  307. return false;
  308. }
  309. $result = null;
  310. return true;
  311. }
  312. // }}}
  313. // {{{ numCols()
  314. /**
  315. * Gets the number of columns in a result set.
  316. *
  317. * @return number of columns in a result set
  318. */
  319. function numCols($result)
  320. {
  321. $cols = @sqlite_num_fields($result);
  322. if (!$cols) {
  323. return $this->sqliteRaiseError();
  324. }
  325. return $cols;
  326. }
  327. // }}}
  328. // {{{ numRows()
  329. /**
  330. * Gets the number of rows affected by a query.
  331. *
  332. * @return number of rows affected by the last query
  333. */
  334. function numRows($result)
  335. {
  336. $rows = @sqlite_num_rows($result);
  337. if (!is_integer($rows)) {
  338. return $this->raiseError();
  339. }
  340. return $rows;
  341. }
  342. // }}}
  343. // {{{ affected()
  344. /**
  345. * Gets the number of rows affected by a query.
  346. *
  347. * @return number of rows affected by the last query
  348. */
  349. function affectedRows()
  350. {
  351. return sqlite_changes($this->connection);
  352. }
  353. // }}}
  354. // {{{ errorNative()
  355. /**
  356. * Get the native error string of the last error (if any) that
  357. * occured on the current connection.
  358. *
  359. * This is used to retrieve more meaningfull error messages DB_pgsql
  360. * way since sqlite_last_error() does not provide adequate info.
  361. *
  362. * @return string native SQLite error message
  363. */
  364. function errorNative()
  365. {
  366. return($this->_lasterror);
  367. }
  368. // }}}
  369. // {{{ errorCode()
  370. /**
  371. * Determine PEAR::DB error code from the database's text error message.
  372. *
  373. * @param string $errormsg error message returned from the database
  374. * @return integer an error number from a DB error constant
  375. */
  376. function errorCode($errormsg)
  377. {
  378. static $error_regexps;
  379. if (!isset($error_regexps)) {
  380. $error_regexps = array(
  381. '/^no such table:/' => DB_ERROR_NOSUCHTABLE,
  382. '/^table .* already exists$/' => DB_ERROR_ALREADY_EXISTS,
  383. '/PRIMARY KEY must be unique/i' => DB_ERROR_CONSTRAINT,
  384. '/is not unique/' => DB_ERROR_CONSTRAINT,
  385. '/uniqueness constraint failed/' => DB_ERROR_CONSTRAINT,
  386. '/may not be NULL/' => DB_ERROR_CONSTRAINT_NOT_NULL,
  387. '/^no such column:/' => DB_ERROR_NOSUCHFIELD,
  388. '/^near ".*": syntax error$/' => DB_ERROR_SYNTAX
  389. );
  390. }
  391. foreach ($error_regexps as $regexp => $code) {
  392. if (preg_match($regexp, $errormsg)) {
  393. return $code;
  394. }
  395. }
  396. // Fall back to DB_ERROR if there was no mapping.
  397. return DB_ERROR;
  398. }
  399. // }}}
  400. // {{{ dropSequence()
  401. /**
  402. * Deletes a sequence
  403. *
  404. * @param string $seq_name name of the sequence to be deleted
  405. *
  406. * @return int DB_OK on success. DB_Error if problems.
  407. *
  408. * @internal
  409. * @see DB_common::dropSequence()
  410. * @access public
  411. */
  412. function dropSequence($seq_name)
  413. {
  414. $seqname = $this->getSequenceName($seq_name);
  415. return $this->query("DROP TABLE $seqname");
  416. }
  417. /**
  418. * Creates a new sequence
  419. *
  420. * @param string $seq_name name of the new sequence
  421. *
  422. * @return int DB_OK on success. A DB_Error object is returned if
  423. * problems arise.
  424. *
  425. * @internal
  426. * @see DB_common::createSequence()
  427. * @access public
  428. */
  429. function createSequence($seq_name)
  430. {
  431. $seqname = $this->getSequenceName($seq_name);
  432. $query = 'CREATE TABLE ' . $seqname .
  433. ' (id INTEGER UNSIGNED PRIMARY KEY) ';
  434. $result = $this->query($query);
  435. if (DB::isError($result)) {
  436. return($result);
  437. }
  438. $query = "CREATE TRIGGER ${seqname}_cleanup AFTER INSERT ON $seqname
  439. BEGIN
  440. DELETE FROM $seqname WHERE id<LAST_INSERT_ROWID();
  441. END ";
  442. $result = $this->query($query);
  443. if (DB::isError($result)) {
  444. return($result);
  445. }
  446. }
  447. // }}}
  448. // {{{ nextId()
  449. /**
  450. * Returns the next free id in a sequence
  451. *
  452. * @param string $seq_name name of the sequence
  453. * @param boolean $ondemand when true, the seqence is automatically
  454. * created if it does not exist
  455. *
  456. * @return int the next id number in the sequence. DB_Error if problem.
  457. *
  458. * @internal
  459. * @see DB_common::nextID()
  460. * @access public
  461. */
  462. function nextId($seq_name, $ondemand = true)
  463. {
  464. $seqname = $this->getSequenceName($seq_name);
  465. do {
  466. $repeat = 0;
  467. $this->pushErrorHandling(PEAR_ERROR_RETURN);
  468. $result = $this->query("INSERT INTO $seqname VALUES (NULL)");
  469. $this->popErrorHandling();
  470. if ($result == DB_OK) {
  471. $id = sqlite_last_insert_rowid($this->connection);
  472. if ($id != 0) {
  473. return $id;
  474. }
  475. } elseif ($ondemand && DB::isError($result) &&
  476. $result->getCode() == DB_ERROR_NOSUCHTABLE)
  477. {
  478. $result = $this->createSequence($seq_name);
  479. if (DB::isError($result)) {
  480. return $this->raiseError($result);
  481. } else {
  482. $repeat = 1;
  483. }
  484. }
  485. } while ($repeat);
  486. return $this->raiseError($result);
  487. }
  488. // }}}
  489. // {{{ getSpecialQuery()
  490. /**
  491. * Returns the query needed to get some backend info.
  492. *
  493. * Refer to the online manual at http://sqlite.org/sqlite.html.
  494. *
  495. * @param string $type What kind of info you want to retrieve
  496. * @return string The SQL query string
  497. */
  498. function getSpecialQuery($type, $args=array())
  499. {
  500. if(!is_array($args))
  501. return $this->raiseError('no key specified', null, null, null,
  502. 'Argument has to be an array.');
  503. switch (strtolower($type)) {
  504. case 'master':
  505. return 'SELECT * FROM sqlite_master;';
  506. case 'tables':
  507. return "SELECT name FROM sqlite_master WHERE type='table' "
  508. . 'UNION ALL SELECT name FROM sqlite_temp_master '
  509. . "WHERE type='table' ORDER BY name;";
  510. case 'schema':
  511. return 'SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL '
  512. . 'SELECT * FROM sqlite_temp_master) '
  513. . "WHERE type!='meta' ORDER BY tbl_name, type DESC, name;";
  514. case 'schemax':
  515. case 'schema_x':
  516. /*
  517. * Use like:
  518. * $res = $db->query($db->getSpecialQuery('schema_x', array('table' => 'table3')));
  519. */
  520. return 'SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL '
  521. . 'SELECT * FROM sqlite_temp_master) '
  522. . "WHERE tbl_name LIKE '{$args['table']}' AND type!='meta' "
  523. . 'ORDER BY type DESC, name;';
  524. case 'alter':
  525. /*
  526. * SQLite does not support ALTER TABLE; this is a helper query
  527. * to handle this. 'table' represents the table name, 'rows'
  528. * the news rows to create, 'save' the row(s) to keep _with_
  529. * the data.
  530. *
  531. * Use like:
  532. * $args = array(
  533. * 'table' => $table,
  534. * 'rows' => "id INTEGER PRIMARY KEY, firstname TEXT, surname TEXT, datetime TEXT",
  535. * 'save' => "NULL, titel, content, datetime"
  536. * );
  537. * $res = $db->query( $db->getSpecialQuery('alter', $args));
  538. */
  539. $rows = strtr($args['rows'], $this->keywords);
  540. $q = array(
  541. 'BEGIN TRANSACTION',
  542. "CREATE TEMPORARY TABLE {$args['table']}_backup ({$args['rows']})",
  543. "INSERT INTO {$args['table']}_backup SELECT {$args['save']} FROM {$args['table']}",
  544. "DROP TABLE {$args['table']}",
  545. "CREATE TABLE {$args['table']} ({$args['rows']})",
  546. "INSERT INTO {$args['table']} SELECT {$rows} FROM {$args['table']}_backup",
  547. "DROP TABLE {$args['table']}_backup",
  548. 'COMMIT',
  549. );
  550. // This is a dirty hack, since the above query will no get executed with a single
  551. // query call; so here the query method will be called directly and return a select instead.
  552. foreach($q as $query) {
  553. $this->query($query);
  554. }
  555. return "SELECT * FROM {$args['table']};";
  556. default:
  557. return null;
  558. }
  559. }
  560. // }}}
  561. // {{{ getDbFileStats()
  562. /**
  563. * Get the file stats for the current database.
  564. *
  565. * Possible arguments are dev, ino, mode, nlink, uid, gid, rdev, size,
  566. * atime, mtime, ctime, blksize, blocks or a numeric key between
  567. * 0 and 12.
  568. *
  569. * @param string $arg Array key for stats()
  570. * @return mixed array on an unspecified key, integer on a passed arg and
  571. * FALSE at a stats error.
  572. */
  573. function getDbFileStats($arg = '')
  574. {
  575. $stats = stat($this->dsn['database']);
  576. if ($stats == false) {
  577. return false;
  578. }
  579. if (is_array($stats)) {
  580. if(is_numeric($arg)) {
  581. if (((int)$arg <= 12) & ((int)$arg >= 0)) {
  582. return false;
  583. }
  584. return $stats[$arg ];
  585. }
  586. if (array_key_exists(trim($arg), $stats)) {
  587. return $stats[$arg ];
  588. }
  589. }
  590. return $stats;
  591. }
  592. // }}}
  593. // {{{ modifyLimitQuery()
  594. function modifyLimitQuery($query, $from, $count)
  595. {
  596. $query = $query . " LIMIT $count OFFSET $from";
  597. return $query;
  598. }
  599. // }}}
  600. // {{{ modifyQuery()
  601. /**
  602. * "DELETE FROM table" gives 0 affected rows in SQLite.
  603. *
  604. * This little hack lets you know how many rows were deleted.
  605. *
  606. * @param string $query The SQL query string
  607. * @return string The SQL query string
  608. */
  609. function _modifyQuery($query)
  610. {
  611. if ($this->options['portability'] & DB_PORTABILITY_DELETE_COUNT) {
  612. if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $query)) {
  613. $query = preg_replace('/^\s*DELETE\s+FROM\s+(\S+)\s*$/',
  614. 'DELETE FROM \1 WHERE 1=1', $query);
  615. }
  616. }
  617. return $query;
  618. }
  619. // }}}
  620. // {{{ sqliteRaiseError()
  621. /**
  622. * Gather information about an error, then use that info to create a
  623. * DB error object and finally return that object.
  624. *
  625. * @param integer $errno PEAR error number (usually a DB constant) if
  626. * manually raising an error
  627. * @return object DB error object
  628. * @see errorNative()
  629. * @see errorCode()
  630. * @see DB_common::raiseError()
  631. */
  632. function sqliteRaiseError($errno = null)
  633. {
  634. $native = $this->errorNative();
  635. if ($errno === null) {
  636. $errno = $this->errorCode($native);
  637. }
  638. $errorcode = @sqlite_last_error($this->connection);
  639. $userinfo = "$errorcode ** $this->last_query";
  640. return $this->raiseError($errno, null, null, $userinfo, $native);
  641. }
  642. // }}}
  643. }
  644. /*
  645. * Local variables:
  646. * tab-width: 4
  647. * c-basic-offset: 4
  648. * End:
  649. */
  650. ?>