summaryrefslogtreecommitdiff
path: root/src/Bridge.php
diff options
context:
space:
mode:
authoruckelman <uckelman@nomic.net>2010-03-23 22:38:14 +0000
committeruckelman <uckelman@nomic.net>2010-03-23 22:38:14 +0000
commit3b888ef4cddf97d2f51953b4dd33e1d35eb02930 (patch)
tree7af19b31f69c4174bbe9909a550cbf8a01dfd875 /src/Bridge.php
parent23a2d3251d88061bce9ff02ca426b1e175767d4b (diff)
* Added getMessageId(), getPostId().
* Build posts table for tests. git-svn-id: https://vassalengine.svn.sourceforge.net/svnroot/vassalengine/site-src/trunk@6629 67b53d14-2c14-4ace-a08f-0dab2b34000c
Diffstat (limited to 'src/Bridge.php')
-rw-r--r--src/Bridge.php64
1 files changed, 48 insertions, 16 deletions
diff --git a/src/Bridge.php b/src/Bridge.php
index ab627d7..81f80b6 100644
--- a/src/Bridge.php
+++ b/src/Bridge.php
@@ -8,31 +8,63 @@ class Bridge {
public function __construct($db = FALSE) {
$this->db = $db ? $db :
new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB, DB_USER, DB_PASS);
+
+ $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
public function getPostId($messageId) {
- $sql = 'SELECT post_id FROM posts' .
- 'WHERE message_id = "' . $this->db->quote($message_id) . '"';
+ $sql = 'SELECT post_id FROM posts ' .
+ 'WHERE message_id = ' . $this->db->quote($messageId);
$result = $this->db->query($sql);
- if (!$result) {
- trigger_error("Unknown message id: $message_id", E_USER_ERROR);
- }
- // FIXME: what to do if more than one row is returned?
- $row = $result->fetch(PDO::FETCH_ASSOC);
+ $rows = $result->fetchAll(PDO::FETCH_ASSOC);
$result->closeCursor();
- return $row['post_id'];
+ switch (count($rows)) {
+ case 0:
+ trigger_error("Unknown message id: $messageId", E_USER_ERROR);
+ break;
+
+ case 1:
+ return $rows[0]['post_id'];
+
+ default:
+ trigger_error("Too many rows returned: $messageId", E_USER_ERROR);
+ break;
+ }
+ }
+
+ public function getMessageId($postId) {
+ $sql = 'SELECT message_id FROM posts ' .
+ 'WHERE post_id = ' . $this->db->quote($postId);
+
+ $result = $this->db->query($sql);
+
+ $rows = $result->fetchAll(PDO::FETCH_ASSOC);
+ $result->closeCursor();
+
+ switch (count($rows)) {
+ case 0:
+ trigger_error("Unknown post id: $postId", E_USER_ERROR);
+ break;
+
+ case 1:
+ return $rows[0]['message_id'];
+
+ default:
+ trigger_error("Too many rows returned: $postId", E_USER_ERROR);
+ break;
+ }
}
public function registerMessage($msg, $parentId) {
- $sql = 'INSERT INTO posts' .
- '(post_id, message_id, parent_message_id, references)' .
- 'VALUES(' . $msg->getPostId() . ', '
- '"' . $this->db->quote($msg->getMessageId()) . '", '
- '"' . $this->db->quote() . '", '
- '"' . $this->db->quote($msg->getReferences()) . '")';
+ $sql = 'INSERT INTO posts ' .
+ '(post_id, message_id, in_reply_to, refs) ' .
+ 'VALUES (' . $msg->getPostId() . ', '
+ . $this->db->quote($msg->getMessageId()) . ', '
+ . $this->db->quote() . ', '
+ . $this->db->quote($msg->getReferences()) . ')';
$count = $this->db->exec($sql);
@@ -44,8 +76,8 @@ class Bridge {
}
public function getDefaultForumId($list) {
- $sql = 'SELECT forum_id FROM bridge' .
- 'WHERE list_name = "' . $this->db->quote($list) . '"';
+ $sql = 'SELECT forum_id FROM bridge ' .
+ 'WHERE list_name = ' . $this->db->quote($list);
$result = $this->db->query($sql);
if (!$result) {