RE: [PEAR-DEV] DB::sqlite update

From: Date: Tue, 01 Jul 2003 12:10:28 +0000
Subject: RE: [PEAR-DEV] DB::sqlite update
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-17876@lists.php.net to get a copy of this message
hi mika no objection from my side. do you have access? -urs > -----Original Message----- > From: Mika Tuupola [mailto:tuupola@appelsiini.net] > Sent: Tuesday, July 01, 2003 12:46 PM > To: pear-dev@lists.php.net > Cc: Urs Gehrig > Subject: [PEAR-DEV] DB::sqlite update > > > > I have working support for sequences for DB::sqlite driver > waiting for commit. Should I go ahead? > > The test for sequences fails only because of differing error > message > > -cut- > tests/driver#cat 05sequences.diff > 001- DB Error: no such table > 001+ DB Error: no error > 002- DB Error: no such table <- good error catched > 002+ DB Error: no error <- good error catched > -cut- > > AFAIK sqlite returns > > #define SQLITE_ERROR 1 > > trying to query again nonexistant table. Here are the rest > of the tests. > > Running selected tests. > PASS DB_driver::connect test [01connect.phpt] > PASS DB_driver::fetch test [02fetch.phpt] > PASS DB_driver::simpleQuery test [03simplequery.phpt] > PASS DB_driver::numCols test [04numcols.phpt] > FAIL DB_driver::sequences [05sequences.phpt] > PASS DB_driver::prepare/execute test [06prepexec.phpt] > PASS DB_driver::affectedRows test [08affectedrows.phpt] > PASS DB_driver::numRows test [09numrows.phpt] > FAIL DB_driver::error mapping [10errormap.phpt] > FAIL DB_driver::row limit [13limit.phpt] > PASS DB_driver::fetchmode object [14fetchmode_object.phpt] > FAIL DB_driver::escape data test [15quote.phpt] > FAIL DB_driver::bug22328 [bug22328.phpt] > > Patch follows (i know it still needs some polishing, but > atleast provides working sequences): > > -cut- > --- sqlite.php.org 2003-07-01 13:42:46.970000000 +0300 > +++ sqlite.php 2003-07-01 13:30:37.370013000 +0300 > @@ -126,9 +126,11 @@ > 'transactions' => false, > 'limit' => 'emulate' > ); > +/* > $this->options = array ( > 'optimize' => 'portability' > ); > +*/ > > // SQLite data types, > http://www.sqlite.org/datatypes.html > $this->keywords = array ( > @@ -150,8 +152,9 @@ > "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, @@ -248,19 +251,22 @@ > $ismanip = DB::isManip($query); > $this->last_query = $query; > $query = $this->_modifyQuery($query); > - > $result = @sqlite_query($query, $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; > } > @@ -400,7 +406,7 @@ > */ > function numRows($result) { > $rows = @sqlite_num_rows($result); > - if (!$rows) { > + if (!is_integer($rows)) { > return $this->raiseError(); > } > return $rows; > @@ -430,6 +436,53 @@ > 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() > -cut- > > -- > Mika Tuupola õ ºñæd?™5 > yKÁ http://www.appelsiini.net/~tuupola/ > > > -- > PEAR Development Mailing List (http://pear.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.pear.dev (#17876) next »