more sqlite fixes

This commit is contained in:
Shish 2009-01-22 09:08:33 -08:00
parent 4e4f0be4e5
commit 35cc1aad48
3 changed files with 21 additions and 9 deletions

View File

@ -255,13 +255,25 @@ class Image {
// insert each new tags // insert each new tags
foreach($tags as $tag) { foreach($tags as $tag) {
$id = $this->database->db->GetOne(
"SELECT id FROM tags WHERE tag = ?",
array($tag));
if(empty($id)) {
// a new tag
$this->database->execute( $this->database->execute(
"INSERT IGNORE INTO tags(tag) VALUES (?)", "INSERT INTO tags(tag) VALUES (?)",
array($tag)); array($tag));
$this->database->execute( $this->database->execute(
"INSERT INTO image_tags(image_id, tag_id) ". "INSERT INTO image_tags(image_id, tag_id)
"VALUES(?, (SELECT id FROM tags WHERE tag = ?))", VALUES(?, (SELECT id FROM tags WHERE tag = ?))",
array($this->id, $tag)); array($this->id, $tag));
}
else {
// user of an existing tag
$this->database->execute(
"INSERT INTO image_tags(image_id, tag_id) VALUES(?, ?)",
array($this->id, $id));
}
$this->database->execute( $this->database->execute(
"UPDATE tags SET count = count + 1 WHERE tag = ?", "UPDATE tags SET count = count + 1 WHERE tag = ?",
array($tag)); array($tag));

View File

@ -210,7 +210,7 @@ class TagList implements Extension {
global $config; global $config;
$query = " $query = "
SELECT COUNT(it3.image_id) as count, t3.tag AS tag SELECT COUNT(it3.image_id) as calc_count, t3.tag AS tag
FROM FROM
image_tags AS it1, image_tags AS it1,
image_tags AS it2, image_tags AS it2,
@ -226,7 +226,7 @@ class TagList implements Extension {
AND t1.id = it1.tag_id AND t1.id = it1.tag_id
AND t3.id = it3.tag_id AND t3.id = it3.tag_id
GROUP BY it3.tag_id GROUP BY it3.tag_id
ORDER BY count DESC ORDER BY calc_count DESC
LIMIT ? LIMIT ?
"; ";
$args = array($image->id, $config->get_int('tag_list_length')); $args = array($image->id, $config->get_int('tag_list_length'));

View File

@ -40,7 +40,7 @@ class TagListTheme extends Themelet {
$tag = $row['tag']; $tag = $row['tag'];
$h_tag = html_escape($tag); $h_tag = html_escape($tag);
$h_tag_no_underscores = str_replace("_", " ", $h_tag); $h_tag_no_underscores = str_replace("_", " ", $h_tag);
$count = $row['count']; $count = $row['calc_count'];
if($n++) $html .= "\n<br/>"; if($n++) $html .= "\n<br/>";
if(!is_null($config->get_string('info_link'))) { if(!is_null($config->get_string('info_link'))) {
$link = str_replace('$tag', $tag, $config->get_string('info_link')); $link = str_replace('$tag', $tag, $config->get_string('info_link'));