cvs: pear /Log package.xml /Log/Log sql.php
| From: | Jon Parise | Date: | Mon, 17 Feb 2003 21:03:52 +0000 |
| Subject: | cvs: pear /Log package.xml /Log/Log sql.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-8919@lists.php.net to get a copy of this message | ||
jon Mon Feb 17 16:03:52 2003 EDT
Modified files:
/pear/Log package.xml
/pear/Log/Log sql.php
Log:
The SQL handler now uses sequences instead of timestamps to uniquely
identify log entries.
We were using the NOW() function to generate quasi-unique timestamps, but
NOW() is now portable. Instead, we generate timestamps using PHP's date()
function. However, this results in a loss of timing granularity (times
are only accurate to the second), so we needed to add an 'id' column to
maintain a unique primary key.
This closes bug #20731.
I've also officially registered the dependency on the DB package.
Index: pear/Log/package.xml
diff -u pear/Log/package.xml:1.21 pear/Log/package.xml:1.22
--- pear/Log/package.xml:1.21 Mon Jan 27 22:45:39 2003
+++ pear/Log/package.xml Mon Feb 17 16:03:51 2003
@@ -15,10 +15,11 @@
</maintainer>
</maintainers>
<release>
- <version>1.5.4</version>
- <date>2003-XX-XX</date>
+ <version>1.6.0</version>
+ <date>2003-02-17</date>
<state>stable</state>
<notes>
+- The SQL handler now uses sequences instead of timestamps as unique identifiers.
- The time format used by the file handler is now configurable.
</notes>
<filelist>
@@ -36,6 +37,9 @@
</dir>
</dir>
</filelist>
+ <deps>
+ <dep type="pkg" rel="has">DB</dep>
+ </deps>
</release>
<changelog>
<release>
Index: pear/Log/Log/sql.php
diff -u pear/Log/Log/sql.php:1.15 pear/Log/Log/sql.php:1.16
--- pear/Log/Log/sql.php:1.15 Mon Feb 17 15:37:43 2003
+++ pear/Log/Log/sql.php Mon Feb 17 16:03:52 2003
@@ -1,5 +1,5 @@
<?php
-// $Id: sql.php,v 1.15 2003/02/17 20:37:43 jon Exp $
+// $Id: sql.php,v 1.16 2003/02/17 21:03:52 jon Exp $
// $Horde: horde/lib/Log/sql.php,v 1.12 2000/08/16 20:27:34 chuck Exp $
require_once 'DB.php';
@@ -12,15 +12,16 @@
* This implementation uses PHP's PEAR database abstraction layer.
*
* CREATE TABLE log_table (
+ * id INT NOT NULL,
* logtime TIMESTAMP NOT NULL,
- * ident char(16) NOT NULL,
- * priority int,
- * message varchar(200),
- * primary key (logtime, ident)
+ * ident CHAR(16) NOT NULL,
+ * priority INT NOT NULL,
+ * message VARCHAR(200),
+ * PRIMARY KEY (id)
* );
*
* @author Jon Parise <jon@php.net>
- * @version $Revision: 1.15 $
+ * @version $Revision: 1.16 $
* @since Horde 1.3
* @package Log
*/
@@ -138,10 +139,14 @@
$this->open();
}
+ $id = $this->_db->nextId('log_id');
+ $now = date('Y-m-d H:i:s');
+
/* Build the SQL query for this log entry insertion. */
- $q = sprintf("insert into %s values(NOW(), %s, %d, %s)",
- $this->_table, $this->_db->quote($this->_ident),
- $priority, $this->_db->quote($message));
+ $q = sprintf('insert into %s values(%d, %s, %s, %d, %s)',
+ $this->_table, $id, $this->_db->quote($now),
+ $this->_db->quote($this->_ident), $priority,
+ $this->_db->quote($message));
$result = $this->_db->query($q);
if (DB::isError($result)) {