[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Librefm-commits] [1503] use adodb exceptions in gnukebox instead of PEA
From: |
Clint Adams |
Subject: |
[Librefm-commits] [1503] use adodb exceptions in gnukebox instead of PEAR stuff |
Date: |
Tue, 12 May 2009 00:37:40 +0000 |
Revision: 1503
http://svn.sv.gnu.org/viewvc/?view=rev&root=librefm&revision=1503
Author: clint
Date: 2009-05-12 00:37:40 +0000 (Tue, 12 May 2009)
Log Message:
-----------
use adodb exceptions in gnukebox instead of PEAR stuff
Modified Paths:
--------------
trunk/gnukebox/scrobble-utils.php
trunk/gnukebox/submissions/1.1/handshake.php
trunk/gnukebox/submissions/1.2/handshake.php
trunk/gnukebox/submissions/1.2/index.php
Modified: trunk/gnukebox/scrobble-utils.php
===================================================================
--- trunk/gnukebox/scrobble-utils.php 2009-05-12 00:26:47 UTC (rev 1502)
+++ trunk/gnukebox/scrobble-utils.php 2009-05-12 00:37:40 UTC (rev 1503)
@@ -31,10 +31,11 @@
// Delete any expired session ids
$adodb->Execute("DELETE FROM Scrobble_Sessions WHERE expires < " .
time());
- $res = $adodb->GetOne("SELECT username FROM Scrobble_Sessions WHERE
sessionid = " . $adodb->qstr($session_id)); // get the username from the table
-
- if(PEAR::isError($res)) {
- die("FAILED ufs " . $res->getMessage() . "\n");
+ try {
+ $res = $adodb->GetOne("SELECT username FROM Scrobble_Sessions
WHERE sessionid = " . $adodb->qstr($session_id)); // get the username from the
table
+ }
+ catch (exception $e) {
+ die("FAILED ufs " . $e->getMessage() . "\n");
// die is there is an error, printing the error
}
@@ -54,32 +55,40 @@
$artist = NoSpamTracks($artist);
- $res = $adodb->Execute("SELECT name FROM Artist WHERE name = " .
($artist));
- if(PEAR::isError($res)) {
- die("FAILED art " . $res->getMessage() . "\n");
+ try {
+ $res = $adodb->Execute("SELECT name FROM Artist WHERE name = "
. ($artist));
}
+ catch (exception $e) {
+ die("FAILED art " . $e->getMessage() . "\n");
+ }
if(!$res) {
// Artist doesn't exist, so we create them
- $res = $adodb->Execute("INSERT INTO Artist (name) VALUES (" .
($artist) . ")");
- if(PEAR::isError($res)) {
- die("FAILED artc " . $res->getMessage() . "\n");
+ try {
+ $res = $adodb->Execute("INSERT INTO Artist (name)
VALUES (" . ($artist) . ")");
}
+ catch (exception $e) {
+ die("FAILED artc " . $e->getMessage() . "\n");
+ }
}
}
function createAlbumIfNew($artist, $album) {
global $adodb;
+ try {
$res = $adodb->Execute("SELECT name FROM Album WHERE name = " .
($album) . " AND artist_name = " . ($artist));
- if(PEAR::isError($res)) {
- die("FAILED alb " . $res->getMessage() . "\n");
}
+ catch (exception $e) {
+ die("FAILED alb " . $e->getMessage() . "\n");
+ }
if(!$res) {
// Album doesn't exist, so create it
$art = $adodb->qstr(getAlbumArt($artist, $album));
+
+ try {
if ($art !="") {
$license = $adodb->qstr("amazon");
@@ -90,11 +99,11 @@
$res = $adodb->Execute("INSERT INTO Album (name, artist_name)
VALUES (" . ($album) . ", " . ($artist) . ")");
}
-
- if(PEAR::isError($res)) {
- die("FAILED albc " . $res->getMessage() . "\n");
- }
}
+ catch (exception $e) {
+ die("FAILED albc " . $e->getMessage() . "\n");
+ }
+ }
}
function getTrackCreateIfNew($artist, $album, $track, $mbid) {
@@ -103,25 +112,29 @@
$track = NoSpamTracks($track);
$artist = NoSpamTracks($artist);
+ try {
if($album != 'NULL') {
$res = $adodb->GetOne("SELECT id FROM Track WHERE lower(name) = lower("
. ($track) . ") AND lower(artist_name) = lower(" . ($artist) . ") AND
lower(album_name) = lower(" . ($album) . ")");
} else {
$res = $adodb->GetOne("SELECT id FROM Track WHERE lower(name) = lower("
. ($track) . ") AND lower(artist_name) = lower(" . ($artist) . ") AND
album_name IS NULL");
}
- if(PEAR::isError($res)) {
- die("FAILED trk " . $res->getMessage() . "\n");
}
+ catch (exception $e) {
+ die("FAILED trk " . $e->getMessage() . "\n");
+ }
if(!$res) {
// Create new track
+ try {
$res = $adodb->Execute("INSERT INTO Track (name, artist_name,
album_name, mbid) VALUES ("
. ($track) . ", "
. ($artist) . ", "
. ($album) . ", "
. ($mbid) . ")");
- if(PEAR::isError($res)) {
- die("FAILED trkc " . $res->getMessage() . "\n");
}
+ catch (exception $e) {
+ die("FAILED trkc " . $e->getMessage() . "\n");
+ }
return getTrackCreateIfNew($artist, $album, $track, $mbid);
} else {
return $res;
@@ -131,13 +144,15 @@
function getScrobbleTrackCreateIfNew($artist, $album, $track, $mbid, $tid) {
global $adodb;
+ try {
$res = $adodb->GetOne("SELECT id FROM Scrobble_Track WHERE name =
lower("
. ($track) . ") AND artist = lower(" . ($artist) . ") AND album
"
. (($album == 'NULL') ? "IS NULL" : ("= lower(" . ($album) .
")")) . " AND mbid "
. (($mbid == 'NULL') ? "IS NULL" : ("= lower(" . ($mbid) .
")")));
- if(PEAR::isError($res)) {
- die("FAILED st " . $res->getMessage() . "\n");
}
+ catch (exception $e) {
+ die("FAILED st " . $e->getMessage() . "\n");
+ }
if(!$res) {
$sql = "INSERT INTO Scrobble_Track (name, artist, album, mbid,
track) VALUES ("
@@ -146,9 +161,11 @@
. (($album == 'NULL') ? "NULL" : "lower(" . ($album) .
")") . ", "
. (($mbid == 'NULL') ? "NULL" : "lower(" . ($mbid) .
")") . ", "
. ($tid) . ")";
- $res = $adodb->Execute($sql);
- if(PEAR::isError($res)) {
- $msg = $res->getMessage() . " - " . $res->getUserInfo();
+ try {
+ $res = $adodb->Execute($sql);
+ }
+ catch (exception $e) {
+ $msg = $e->getMessage() . " - " . $e->getUserInfo();
reportError($msg, $sql);
die("FAILED stc " . $res->getMessage() . "\n");
@@ -162,10 +179,12 @@
function scrobbleExists($username, $artist, $track, $time) {
global $adodb;
+ try {
$res = $adodb->GetOne("SELECT time FROM Scrobbles WHERE username = " .
($username) . " AND artist = " . ($artist) . " AND track = " . ($track) . " AND
time = " . ($time));
- if(PEAR::isError($res)) {
- die("FAILED se " . $res->getMessage() . "\n");
}
+ catch (exception $e) {
+ die("FAILED se " . $e->getMessage() . "\n");
+ }
if(!$res) {
return false;
Modified: trunk/gnukebox/submissions/1.1/handshake.php
===================================================================
--- trunk/gnukebox/submissions/1.1/handshake.php 2009-05-12 00:26:47 UTC
(rev 1502)
+++ trunk/gnukebox/submissions/1.1/handshake.php 2009-05-12 00:37:40 UTC
(rev 1503)
@@ -42,24 +42,27 @@
$timestamp = time();
-$res = $adodb->GetOne("SELECT password FROM Users WHERE username = ".
$adodb->qstr($username));
-if(PEAR::isError($res)) {
- die("FAILED " . $res->getMessage() . "\n");
+try {
+ $res = $adodb->GetOne("SELECT password FROM Users WHERE username = ".
$adodb->qstr($username));
}
+catch (exception $e) {
+ die("FAILED " . $e->getMessage() . "\n");
+}
if(!$res->numRows()) {
die("BADUSER\n");
}
$password = $res;
$session_id = md5($password . $timestamp);
+try {
$res = $adodb->Execute("INSERT INTO Scrobble_Sessions(username, sessionid,
client, expires) VALUES ("
. $adodb->qstr($username, "text") . ","
. $adodb->qstr($session_id, "text") . ","
. $adodb->qstr($client, "text") . ","
. $adodb->qstr(time() + 86400) . ")");
-
-if(PEAR::isError($res)) {
- die("FAILED " . $res->getMessage() . "\n");
}
+catch (exception $e) {
+ die("FAILED " . $e->getMessage() . "\n");
+}
echo "UPTODATE\n";
echo $timestamp . "\n";
Modified: trunk/gnukebox/submissions/1.2/handshake.php
===================================================================
--- trunk/gnukebox/submissions/1.2/handshake.php 2009-05-12 00:26:47 UTC
(rev 1502)
+++ trunk/gnukebox/submissions/1.2/handshake.php 2009-05-12 00:37:40 UTC
(rev 1503)
@@ -61,10 +61,11 @@
. $adodb->qstr($client) . ","
. (time() + 86400) . ")";
+try {
$res = $adodb->Execute($sql);
-
-if(PEAR::isError($res)) {
- $msg = $res->getMessage();
+}
+catch (exception $e) {
+ $msg = $e->getMessage();
reportError($msg, $sql);
die("FAILED " . $msg . "\n");
}
Modified: trunk/gnukebox/submissions/1.2/index.php
===================================================================
--- trunk/gnukebox/submissions/1.2/index.php 2009-05-12 00:26:47 UTC (rev
1502)
+++ trunk/gnukebox/submissions/1.2/index.php 2009-05-12 00:37:40 UTC (rev
1503)
@@ -146,9 +146,11 @@
// Scrobble!
$sql = "INSERT INTO Scrobbles (username, artist, album, track,
time, mbid, source, rating, length, stid) VALUES " . $rowvalues[$j];
+ try {
$res =& $adodb->Execute($sql);
- if(PEAR::isError($res)) {
- $msg = $res->getMessage() . " - " . $res->getUserInfo();
+ }
+ catch (exception $e) {
+ $msg = $e->getMessage() . " - " . $e->getUserInfo();
$adodb->FailTrans();
$adodb->CompleteTrans();
reportError($msg, $sql);
@@ -157,15 +159,14 @@
}
- $adodb->CompleteTrans();
-
- if(PEAR::isError($res)) {
- $msg = $res->getMessage() . " - " . $res->getUserInfo();
- $adodb->FailTrans();
- $adodb->CompleteTrans();
- reportError($msg, $sql);
- die("FAILED " . $msg . "\nError has been reported to site
administrators.\n");
+ try {
+ $adodb->CompleteTrans();
}
+ catch (exception $e) {
+ die("FAILED " . $e->getMessage() . "\n";
+ }
+
+ }
// Destroy now_playing since it is almost certainly obsolescent
$adodb->Execute("DELETE FROM Now_Playing WHERE sessionid = " .
$adodb->qstr($session_id));
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Librefm-commits] [1503] use adodb exceptions in gnukebox instead of PEAR stuff,
Clint Adams <=