gallery db query fix

This commit is contained in:
Bartek Przybylski 2011-10-05 19:32:30 +02:00
parent 28dcbe3cb0
commit d5931b8c48
4 changed files with 9 additions and 9 deletions

View File

@ -45,7 +45,7 @@ $box_size = 200;
$album_name = $_GET['album']; $album_name = $_GET['album'];
$x = $_GET['x']; $x = $_GET['x'];
$stmt = OC_DB::prepare('SELECT file_path FROM *PREFIX*gallery_photos,*PREFIX*gallery_albums WHERE *PREFIX*gallery_albums.uid_owner = ? AND album_name = ? AND *PREFIX*gallery_photos.album_id == *PREFIX*gallery_albums.album_id'); $stmt = OC_DB::prepare('SELECT `file_path` FROM *PREFIX*gallery_photos,*PREFIX*gallery_albums WHERE *PREFIX*gallery_albums.`uid_owner` = ? AND `album_name` = ? AND *PREFIX*gallery_photos.`album_id` == *PREFIX*gallery_albums.`album_id`');
$result = $stmt->execute(array(OC_User::getUser(), $album_name)); $result = $stmt->execute(array(OC_User::getUser(), $album_name));
$x = min((int)($x/($box_size/$result->numRows())), $result->numRows()-1); // get image to display $x = min((int)($x/($box_size/$result->numRows())), $result->numRows()-1); // get image to display
$result->seek($x); // never throws $result->seek($x); // never throws

View File

@ -7,12 +7,12 @@ if (!OC_User::IsLoggedIn()) {
} }
$a = array(); $a = array();
$stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_albums WHERE uid_owner = ?'); $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_albums WHERE `uid_owner` = ?');
$result = $stmt->execute(array(OC_User::getUser())); $result = $stmt->execute(array(OC_User::getUser()));
while ($r = $result->fetchRow()) { while ($r = $result->fetchRow()) {
$album_name = $r['album_name']; $album_name = $r['album_name'];
$stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_photos WHERE album_id = ?'); $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_photos WHERE `album_id` = ?');
$tmp_res = $stmt->execute(array($r['album_id'])); $tmp_res = $stmt->execute(array($r['album_id']));
$a[] = array('name' => $album_name, 'numOfItems' => min($tmp_res->numRows(), 10)); $a[] = array('name' => $album_name, 'numOfItems' => min($tmp_res->numRows(), 10));
} }

View File

@ -46,7 +46,7 @@ if( !OC_User::isLoggedIn()){
$box_size = 200; $box_size = 200;
$album_name= $_GET['album_name']; $album_name= $_GET['album_name'];
$stmt = OC_DB::prepare('SELECT file_path FROM *PREFIX*gallery_photos,*PREFIX*gallery_albums WHERE *PREFIX*gallery_albums.uid_owner = ? AND album_name = ? AND *PREFIX*gallery_photos.album_id == *PREFIX*gallery_albums.album_id'); $stmt = OC_DB::prepare('SELECT `file_path` FROM *PREFIX*gallery_photos,*PREFIX*gallery_albums WHERE *PREFIX*gallery_albums.`uid_owner` = ? AND `album_name` = ? AND *PREFIX*gallery_photos.`album_id` = *PREFIX*gallery_albums.`album_id`');
$result = $stmt->execute(array(OC_User::getUser(), $album_name)); $result = $stmt->execute(array(OC_User::getUser(), $album_name));
$numOfItems = min($result->numRows(),10); $numOfItems = min($result->numRows(),10);

View File

@ -28,21 +28,21 @@ class OC_GALLERY_SCANNER {
} }
$current_album['imagesCount'] = count($current_album['images']); $current_album['imagesCount'] = count($current_album['images']);
$albums[] = $current_album; $albums[] = $current_album;
$stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_albums WHERE "uid_owner" = ? AND "album_name" = ?'); $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_albums WHERE `uid_owner` = ? AND `album_name` = ?');
$result = $stmt->execute(array(OC_User::getUser(), $current_album['name'])); $result = $stmt->execute(array(OC_User::getUser(), $current_album['name']));
if ($result->numRows() == 0 && count($current_album['images'])) { if ($result->numRows() == 0 && count($current_album['images'])) {
$stmt = OC_DB::prepare('INSERT OR REPLACE INTO *PREFIX*gallery_albums ("uid_owner", "album_name") VALUES (?, ?)'); $stmt = OC_DB::prepare('REPLACE INTO *PREFIX*gallery_albums (`uid_owner`, `album_name`) VALUES (?, ?)');
$stmt->execute(array(OC_User::getUser(), $current_album['name'])); $stmt->execute(array(OC_User::getUser(), $current_album['name']));
} }
$stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_albums WHERE "uid_owner" = ? AND "album_name" = ?'); $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_albums WHERE `uid_owner` = ? AND `album_name` = ?');
$result = $stmt->execute(array(OC_User::getUser(), $current_album['name'])); $result = $stmt->execute(array(OC_User::getUser(), $current_album['name']));
$albumId = $result->fetchRow(); $albumId = $result->fetchRow();
$albumId = $albumId['album_id']; $albumId = $albumId['album_id'];
foreach ($current_album['images'] as $img) { foreach ($current_album['images'] as $img) {
$stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_photos WHERE "album_id" = ? AND "file_path" = ?'); $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_photos WHERE `album_id` = ? AND `file_path` = ?');
$result = $stmt->execute(array($albumId, $img)); $result = $stmt->execute(array($albumId, $img));
if ($result->numRows() == 0) { if ($result->numRows() == 0) {
$stmt = OC_DB::prepare('INSERT OR REPLACE INTO *PREFIX*gallery_photos ("album_id", "file_path") VALUES (?, ?)'); $stmt = OC_DB::prepare('INSERT OR REPLACE INTO *PREFIX*gallery_photos (`album_id`, `file_path`) VALUES (?, ?)');
$stmt->execute(array($albumId, $img)); $stmt->execute(array($albumId, $img));
} }
} }