tuupola Tue Jul 1 08:33:13 2003 EDT
Modified files:
/pear/DB/DB sqlite.php
Log:
* add working sequence and LIMIT support
# needs polishing but works.
Index: pear/DB/DB/sqlite.php
diff -u pear/DB/DB/sqlite.php:1.2 pear/DB/DB/sqlite.php:1.3
--- pear/DB/DB/sqlite.php:1.2 Sun Jun 22 20:07:55 2003
+++ pear/DB/DB/sqlite.php Tue Jul 1 08:33:13 2003
@@no-spam -16,7 +16,7 @@no-spam
// | Author: Urs Gehrig <urs@no-spam> |
// +----------------------------------------------------------------------+
//
-// $Id: sqlite.php,v 1.2 2003/06/23 00:07:55 cox Exp $
+// $Id: sqlite.php,v 1.3 2003/07/01 12:33:13 tuupola Exp $
//
// Database independent query interface definition for the PECL's SQLite
// extension.
@@no-spam -124,11 +124,13 @@no-spam
'prepare' => false,
'pconnect' => true,
'transactions' => false,
- 'limit' => 'emulate'
+ 'limit' => 'alter'
);
+/*
$this->options = array (
'optimize' => 'portability'
);
+*/
// SQLite data types, http://www.sqlite.org/datatypes.html
$this->keywords = array (
@@no-spam -150,8 +152,9 @@no-spam
"VARYING" => ""
);
$this->errorcode_map = array(
+ 1 => DB_ERROR_SYNTAX,
+
1004 => DB_ERROR_CANNOT_CREATE,
- 1005 => DB_ERROR_CANNOT_CREATE,
1006 => DB_ERROR_CANNOT_CREATE,
1007 => DB_ERROR_ALREADY_EXISTS,
1008 => DB_ERROR_CANNOT_DROP,
@@no-spam -248,19 +251,22 @@no-spam
$ismanip = DB::isManip($query);
$this->last_query = $query;
$query = $this->_modifyQuery($query);
-
$result = @no-spam $this->connection);
$this->result = $result;
- if (!$this->result ) {
+ if (!$this->result ) {
$errno = sqlite_last_error($this->connection );
if (!$errno) {
return null;
}
return $this->sqliteRaiseError($errno);
}
-
- if (gettype($result) === "resource") {
+
+ /* sqlite_query() seems to allways return a resource */
+ /* so cant use that */
+ if (!$ismanip) {
$numRows = $this->numRows($result);
+
+ /* if numRows() returnet PEAR_Error */
if (is_object($numRows )) {
return $numRows;
}
@@no-spam -400,7 +406,7 @@no-spam
*/
function numRows($result) {
$rows = @no-spam
- if (!$rows) {
+ if (!is_integer($rows)) {
return $this->raiseError();
}
return $rows;
@@no-spam -430,6 +436,53 @@no-spam
return sqlite_last_insert_rowid($this->connection );
}
+ function dropSequence($seq_name)
+ {
+ $seqname = $this->getSequenceName($seq_name);
+ return $this->query("DROP TABLE $seqname");
+ }
+
+
+ function createSequence($seq_name)
+ {
+ $seqname = $this->getSequenceName($seq_name);
+ $query = 'CREATE TABLE ' . $seqname .
+ ' (id INTEGER UNSIGNED PRIMARY KEY) ';
+ $result = $this->query($query);
+ if (DB::isError($result)) {
+ return($result);
+ }
+ }
+
+ function nextId($seq_name, $ondemand = true)
+ {
+ $seqname = $this->getSequenceName($seq_name);
+
+ do {
+ $repeat = 0;
+ $this->pushErrorHandling(PEAR_ERROR_RETURN);
+ $result = $this->query("INSERT INTO $seqname VALUES (NULL)");
+ $this->popErrorHandling();
+ if ($result == DB_OK) {
+ $id = sqlite_last_insert_rowid($this->connection);
+ if ($id != 0) {
+ return $id;
+ }
+ } elseif ($ondemand && DB::isError($result) &&
+ $result->getCode() == 1) {
+ $result = $this->createSequence($seq_name);
+ if (DB::isError($result)) {
+ return $this->raiseError($result);
+ } else {
+ $repeat = 1;
+ }
+ }
+ } while ($repeat);
+
+ return $this->raiseError($result);
+ }
+
+
// }}}
// {{{ getSpecialQuery()
@@no-spam -540,6 +593,12 @@no-spam
// }}}
// {{{ modifyQuery()
+
+ function modifyLimitQuery($query, $from, $count)
+ {
+ $query = $query . " LIMIT $count OFFSET $from";
+ return $query;
+ }
/**
* "DELETE FROM table" gives 0 affected rows in SQLite. This little hack