We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit a8536a15 authored by Mike Sheldon's avatar Mike Sheldon

Use DBMS' lower() function for switching to lowercase wherever possible...

Use DBMS' lower() function for switching to lowercase wherever possible (supports utf-8 and faster than mb_strtolower)
parent 75926c2a
......@@ -47,8 +47,8 @@ class Album {
$adodb->SetFetchMode(ADODB_FETCH_ASSOC);
$r = $adodb->CacheGetRow(1200,
'SELECT name, artist_name, mbid, image, releasedate FROM Album WHERE '
. 'lower(name) = ' . strtolower($adodb->qstr($name)) . ' AND '
. 'lower(artist_name) = ' . strtolower($adodb->qstr($artist)));
. 'lower(name) = lower(' . $adodb->qstr($name) . ') AND '
. 'lower(artist_name) = lower(' . $adodb->qstr($artist) . ')');
if(!$r) {
$this->name = 'No such album: ' . $name;
} else {
......
......@@ -56,7 +56,7 @@ class Artist {
}
$this->query = 'SELECT name, mbid, streamable, bio_published, bio_content, bio_summary, image_small, image_medium, image_large, homepage, hashtag, flattr_uid FROM Artist WHERE '
. $mbidquery
. 'lower(name) = ' . strtolower($adodb->qstr($name));
. 'lower(name) = lower(' . $adodb->qstr($name) . ')';
$row = $adodb->CacheGetRow(1200, $this->query);
if(!$row) {
throw new Exception('No such artist' . $name);
......
......@@ -53,7 +53,7 @@ class Group {
global $adodb;
$adodb->SetFetchMode(ADODB_FETCH_ASSOC);
try {
$res = $adodb->GetRow('SELECT * FROM Groups WHERE lower(groupname) = ' . $adodb->qstr(strtolower($name)));
$res = $adodb->GetRow('SELECT * FROM Groups WHERE lower(groupname) = lower(' . $adodb->qstr($name) . ')');
}
catch (exception $e) {
header('Content-Type: text/plain');
......
......@@ -543,7 +543,6 @@ class Server {
static function search($search_term, $search_type, $limit=40) {
global $adodb;
$search_term = strtolower($search_term);
switch($search_type) {
case 'artist':
$table = 'Artist';
......@@ -583,7 +582,7 @@ class Server {
if ($i > 0) {
$sql .= ' OR ';
}
$sql .= 'LOWER(' . $search_fields[$i] . ') LIKE ' . $adodb->qstr('%' . $search_term . '%');
$sql .= 'LOWER(' . $search_fields[$i] . ') LIKE LOWER(' . $adodb->qstr('%' . $search_term . '%') . ')';
}
$sql .= 'LIMIT ' . $limit;
......
......@@ -50,8 +50,8 @@ class Track {
global $adodb;
$adodb->SetFetchMode(ADODB_FETCH_ASSOC);
$this->query = 'SELECT name, artist_name, album_name, duration, streamable, license, downloadurl, streamurl, mbid FROM Track WHERE '
. 'lower(name) = ' . strtolower($adodb->qstr($name)) . ' AND '
. 'lower(artist_name) = ' . strtolower($adodb->qstr($artist))
. 'lower(name) = lower(' . $adodb->qstr($name) . ') AND '
. 'lower(artist_name) = lower(' . $adodb->qstr($artist) . ')'
. 'ORDER BY streamable DESC';
$res = $adodb->CacheGetRow(600, $this->query);
if(!$res) {
......
......@@ -50,7 +50,7 @@ class User {
$row = $data;
} else {
global $adodb;
$query = 'SELECT * FROM Users WHERE lower(username) = ' . $adodb->qstr(strtolower($name)) . ' LIMIT 1';
$query = 'SELECT * FROM Users WHERE lower(username) = lower(' . $adodb->qstr($name) . ') LIMIT 1';
$adodb->SetFetchMode(ADODB_FETCH_ASSOC);
$row = $adodb->CacheGetRow(7200,$query);
if (!$row) {
......@@ -153,7 +153,7 @@ class User {
exit;
}
$query = 'SELECT * FROM Users WHERE lower(username) = ' . $adodb->qstr(strtolower($this->name)) . ' LIMIT 1';
$query = 'SELECT * FROM Users WHERE lower(username) = lower(' . $adodb->qstr($this->name) . ') LIMIT 1';
$adodb->CacheFlush($query);
return 1;
......
......@@ -42,7 +42,7 @@ if(isset($_POST['login'])) {
if(empty($errors)) {
try {
$sql = 'SELECT uniqueid, active FROM Users WHERE '
. ' lower(username) = ' . $adodb->qstr(strtolower($username))
. ' lower(username) = lower(' . $adodb->qstr($username) . ')'
. ' AND password = ' . $adodb->qstr(md5($password));
$row = $adodb->GetRow($sql);
$userid = $row['uniqueid'];
......
......@@ -95,7 +95,7 @@ if(isset($_POST['register'])) {
//Check this username is available
try {
$res = $adodb->GetOne('SELECT username FROM Users WHERE lower(username) = ' . $adodb->qstr(strtolower($username)));
$res = $adodb->GetOne('SELECT username FROM Users WHERE lower(username) = lower(' . $adodb->qstr($username) . ')');
}
catch (exception $e) {
$errors .= 'Database error.<br />';
......
......@@ -46,7 +46,7 @@ $smarty->assign('url', $track->getURL());
$smarty->assign('pagetitle', $artist->name . ' : ' . $track->name);
$adodb->SetFetchMode(ADODB_FETCH_ASSOC);
$res = $adodb->GetAll('SELECT * FROM Track WHERE lower(artist_name) = ' . $adodb->qstr(mb_strtolower($track->artist_name, 'UTF-8')) . ' AND lower(name) = ' . $adodb->qstr(mb_strtolower($track->name, 'UTF-8')));
$res = $adodb->GetAll('SELECT * FROM Track WHERE lower(artist_name) = lower(' . $adodb->qstr($track->artist_name) . ') AND lower(name) = lower(' . $adodb->qstr($track->name) . ')');
$aOtherAlbums = array();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment