Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

More work done on the plugins so they are all compatible with MySQL now.

  • Loading branch information...
commit c2992379a0b46d78c427f3da1c0a1242f9f3d70c 1 parent bf91e80
Elliot Chance authored
View
2  backend/example.pl
@@ -45,6 +45,8 @@ sub backend_NAME_update_index {
# mbz_table_exists($table_name)
# Check if a table already exists.
+# @note This must support searching for VIEWs as well. mbz_table_exists() is used for testing if
+# tables and views exist.
# @param $table_name The name of the table to look for.
# @return 1 if the table exists, otherwise 0.
sub backend_NAME_table_exists {
View
2  backend/mysql.pl
@@ -135,6 +135,8 @@ sub backend_mysql_table_column_exists {
# backend_mysql_table_exists($table_name)
# Check if a table already exists.
+# @note This must support searching for VIEWs as well. mbz_table_exists() is used for testing if
+# tables and views exist.
# @param $table_name The name of the table to look for.
# @return 1 if the table exists, otherwise 0.
sub backend_mysql_table_exists {
View
3  backend/postgresql.pl
@@ -135,9 +135,12 @@ sub backend_postgresql_update_schema {
# backend_postgresql_table_exists($tablename)
# Check if a table already exists.
+# @note This must support searching for VIEWs as well. mbz_table_exists() is used for testing if
+# tables and views exist.
# @param $table_name The name of the table to look for.
# @return 1 if the table exists, otherwise 0.
sub backend_postgresql_table_exists {
+ # TODO: I don't know if this is checking for views.
my $sth = $dbh->prepare("select count(1) as count from information_schema.tables ".
"where table_name='$_[0]'");
$sth->execute();
View
162 plugins/fulltext.pl
@@ -6,30 +6,72 @@
#
sub fulltext_description {
- return "InnoDB doesn't support fulltext indexing, but with this\n"
- . "plugin it will keep a managed copy of the artist, album and\n"
- . "track tables as MyISAM so you can use the fulltext index.";
+ return "InnoDB doesn't support fulltext indexing, but with this\n".
+ "plugin it will keep a managed copy of the artist, album and\n".
+ "track tables as MyISAM so you can use the fulltext index.";
}
sub fulltext_init {
+ # this plugin is only available to MySQL
+ if($g_db_rdbms ne 'mysql') {
+ warn("fulltext plugin is only supported by MySQL.\n\n");
+ return 0;
+ }
+
# drop existing tables
print "Dropping fulltext tables...";
- mbz_do_sql("DROP TABLE IF EXISTS album_fulltext");
- mbz_do_sql("DROP TABLE IF EXISTS artist_fulltext");
- mbz_do_sql("DROP TABLE IF EXISTS artistalias_fulltext");
- mbz_do_sql("DROP TABLE IF EXISTS track_fulltext");
- mbz_do_sql("DROP TABLE IF EXISTS label_fulltext");
- mbz_do_sql("DROP TABLE IF EXISTS labelalias_fulltext");
+ mbz_do_sql("DROP TABLE album_fulltext") if(mbz_table_exists("album_fulltext"));
+ mbz_do_sql("DROP TABLE artist_fulltext") if(mbz_table_exists("artist_fulltext"));
+ mbz_do_sql("DROP TABLE artistalias_fulltext") if(mbz_table_exists("artistalias_fulltext"));
+ mbz_do_sql("DROP TABLE track_fulltext") if(mbz_table_exists("track_fulltext"));
+ mbz_do_sql("DROP TABLE label_fulltext") if(mbz_table_exists("label_fulltext"));
+ mbz_do_sql("DROP TABLE labelalias_fulltext") if(mbz_table_exists("labelalias_fulltext"));
print " Done\n";
# create tables.
print "Creating fulltext tables...";
- mbz_do_sql("CREATE TABLE album_fulltext (albumid int not null, name varchar(255)) engine=MyISAM");
- mbz_do_sql("CREATE TABLE artist_fulltext (artistid int not null, name varchar(255), sortname varchar(255), resolution varchar(255)) engine=MyISAM");
- mbz_do_sql("CREATE TABLE artistalias_fulltext (id int not null, artistid int not null, name varchar(255)) engine=MyISAM");
- mbz_do_sql("CREATE TABLE track_fulltext (trackid int not null, name varchar(255)) engine=MyISAM");
- mbz_do_sql("CREATE TABLE label_fulltext (labelid int not null, name varchar(255), sortname varchar(255), resolution varchar(255)) engine=MyISAM");
- mbz_do_sql("CREATE TABLE labelalias_fulltext (id int not null, labelid int not null, name varchar(255)) engine=MyISAM");
+ mbz_do_sql(qq|
+ CREATE TABLE album_fulltext (
+ albumid int not null,
+ name varchar(255)
+ ) engine=MyISAM
+ |);
+ mbz_do_sql(qq|
+ CREATE TABLE artist_fulltext (
+ artistid int not null,
+ name varchar(255),
+ sortname varchar(255),
+ resolution varchar(255)
+ ) engine=MyISAM
+ |);
+ mbz_do_sql(qq|
+ CREATE TABLE artistalias_fulltext (
+ id int not null,
+ artistid int not null,
+ name varchar(255)
+ ) engine=MyISAM
+ |);
+ mbz_do_sql(qq|
+ CREATE TABLE track_fulltext (
+ trackid int not null,
+ name varchar(255)
+ ) engine=MyISAM
+ |);
+ mbz_do_sql(qq|
+ CREATE TABLE label_fulltext (
+ labelid int not null,
+ name varchar(255),
+ sortname varchar(255),
+ resolution varchar(255)
+ ) engine=MyISAM
+ |);
+ mbz_do_sql(qq|
+ CREATE TABLE labelalias_fulltext (
+ id int not null,
+ labelid int not null,
+ name varchar(255)
+ ) engine=MyISAM
+ |);
print " Done\n";
# load raw data in from original tables
@@ -54,22 +96,52 @@ sub fulltext_init {
# apply index
print "Indexing album fulltext...";
- mbz_do_sql("alter table album_fulltext add primary key(albumid), add fulltext(name)");
+ mbz_do_sql(qq|
+ alter table album_fulltext
+ add primary key(albumid),
+ add fulltext(name)
+ |);
print " Done\n";
print "Indexing artist fulltext...";
- mbz_do_sql("alter table artist_fulltext add primary key(artistid), add fulltext(name), add fulltext(sortname), add fulltext(resolution)");
+ mbz_do_sql(qq|
+ alter table artist_fulltext
+ add primary key(artistid),
+ add fulltext(name),
+ add fulltext(sortname),
+ add fulltext(resolution)
+ |);
print " Done\n";
print "Indexing track fulltext...";
- mbz_do_sql("alter table track_fulltext add primary key(trackid), add fulltext(name)");
+ mbz_do_sql(qq|
+ alter table track_fulltext
+ add primary key(trackid),
+ add fulltext(name)
+ |);
print " Done\n";
print "Indexing label fulltext...";
- mbz_do_sql("alter table label_fulltext add primary key(labelid), add fulltext(name), add fulltext(sortname), add fulltext(resolution)");
+ mbz_do_sql(qq|
+ alter table label_fulltext
+ add primary key(labelid),
+ add fulltext(name),
+ add fulltext(sortname),
+ add fulltext(resolution)
+ |);
print " Done\n";
print "Indexing artistalias fulltext...";
- mbz_do_sql("alter table artistalias_fulltext add primary key(id), add index(artistid), add fulltext(name)");
+ mbz_do_sql(qq|
+ alter table artistalias_fulltext
+ add primary key(id),
+ add index(artistid),
+ add fulltext(name)
+ |);
print " Done\n";
print "Indexing labelalias fulltext...";
- mbz_do_sql("alter table labelalias_fulltext add primary key(id), add index(labelid), add fulltext(name)");
+ mbz_do_sql(qq|
+ alter table labelalias_fulltext
+ add primary key(id),
+ add index(labelid),
+ add fulltext(name)
+ |);
print " Done\n";
return 1;
@@ -103,17 +175,53 @@ sub fulltext_afterstatement {
}
} else {
if($table eq "artist" && $data->{'id'} != 0) {
- mbz_do_sql("INSERT INTO artist_fulltext SET artistid='" . $data->{'id'} . "', name=" . $dbh->quote($data->{'name'}) . ", sortname=" . $dbh->quote($data->{'sortname'}) . ", resolution=" . $dbh->quote($data->{'resolution'}) . " ON DUPLICATE KEY UPDATE name=" . $dbh->quote($data->{'name'}) . ", sortname=" . $dbh->quote($data->{'sortname'})) . ", resolution=" . $dbh->quote($data->{'resolution'});
+ mbz_do_sql("INSERT INTO artist_fulltext SET ".
+ "artistid='" . $data->{'id'} . "', ".
+ "name=" . $dbh->quote($data->{'name'}) . ", ".
+ "sortname=" . $dbh->quote($data->{'sortname'}) . ", ".
+ "resolution=" . $dbh->quote($data->{'resolution'}) .
+ " ON DUPLICATE KEY UPDATE ".
+ "name=" . $dbh->quote($data->{'name'}) . ", ".
+ "sortname=" . $dbh->quote($data->{'sortname'})) . ", ".
+ "resolution=" . $dbh->quote($data->{'resolution'});
} elsif($table eq "album" && $data->{'id'} != 0) {
- mbz_do_sql("INSERT INTO album_fulltext SET albumid='" . $data->{'id'} . "', name=" . $dbh->quote($data->{'name'}) . " ON DUPLICATE KEY UPDATE name=" . $dbh->quote($data->{'name'}));
+ mbz_do_sql("INSERT INTO album_fulltext SET ".
+ "albumid='" . $data->{'id'} . "', ".
+ "name=" . $dbh->quote($data->{'name'}) .
+ " ON DUPLICATE KEY UPDATE ".
+ "name=" . $dbh->quote($data->{'name'}));
} elsif($table eq "track" && $data->{'id'} != 0) {
- mbz_do_sql("INSERT INTO track_fulltext SET trackid='" . $data->{'id'} . "', name=" . $dbh->quote($data->{'name'}) . " ON DUPLICATE KEY UPDATE name=" . $dbh->quote($data->{'name'}));
+ mbz_do_sql("INSERT INTO track_fulltext SET ".
+ "trackid='" . $data->{'id'} . "', ".
+ "name=" . $dbh->quote($data->{'name'}) .
+ " ON DUPLICATE KEY UPDATE ".
+ "name=" . $dbh->quote($data->{'name'}));
} elsif($table eq "label" && $data->{'id'} != 0) {
- mbz_do_sql("INSERT INTO label_fulltext SET labelid='" . $data->{'id'} . "', name=" . $dbh->quote($data->{'name'}) . ", sortname=" . $dbh->quote($data->{'sortname'}) . ", resolution=" . $dbh->quote($data->{'resolution'}) . " ON DUPLICATE KEY UPDATE name=" . $dbh->quote($data->{'name'}) . ", sortname=" . $dbh->quote($data->{'sortname'})) . ", resolution=" . $dbh->quote($data->{'resolution'});
+ mbz_do_sql("INSERT INTO label_fulltext SET ".
+ "labelid='" . $data->{'id'} . "', ".
+ "name=" . $dbh->quote($data->{'name'}) . ", ".
+ "sortname=" . $dbh->quote($data->{'sortname'}) . ", ".
+ "resolution=" . $dbh->quote($data->{'resolution'}) .
+ " ON DUPLICATE KEY UPDATE ".
+ "name=" . $dbh->quote($data->{'name'}) . ", ".
+ "sortname=" . $dbh->quote($data->{'sortname'})) . ", ".
+ "resolution=" . $dbh->quote($data->{'resolution'});
} elsif($table eq "artistalias" && $data->{'id'} != 0) {
- mbz_do_sql("INSERT INTO artistalias_fulltext SET id='" . $data->{'id'} . "', artistid='" . $data->{'ref'} . "', name=" . $dbh->quote($data->{'name'}) . " ON DUPLICATE KEY UPDATE artistid='" . $data->{'ref'} . "', name=" . $dbh->quote($data->{'name'}));
+ mbz_do_sql("INSERT INTO artistalias_fulltext SET ".
+ "id='" . $data->{'id'} . "', ".
+ "artistid='" . $data->{'ref'} . "', ".
+ "name=" . $dbh->quote($data->{'name'}) .
+ " ON DUPLICATE KEY UPDATE ".
+ "artistid='" . $data->{'ref'} . "', ".
+ "name=" . $dbh->quote($data->{'name'}));
} elsif($table eq "labelalias" && $data->{'id'} != 0) {
- mbz_do_sql("INSERT INTO labelalias_fulltext SET id='" . $data->{'id'} . "', labelid='" . $data->{'ref'} . "', name=" . $dbh->quote($data->{'name'}) . " ON DUPLICATE KEY UPDATE labelid='" . $data->{'ref'} . "', name=" . $dbh->quote($data->{'name'}));
+ mbz_do_sql("INSERT INTO labelalias_fulltext SET ".
+ "id='" . $data->{'id'} . "', ".
+ "labelid='" . $data->{'ref'} . "', ".
+ "name=" . $dbh->quote($data->{'name'}) .
+ " ON DUPLICATE KEY UPDATE ".
+ "labelid='" . $data->{'ref'} . "', ".
+ "name=" . $dbh->quote($data->{'name'}));
}
}
return 1;
View
101 plugins/livestats.pl
@@ -1,62 +1,92 @@
#
-# LiveStats keeps a live count of the table sizes. This is important because InnoDB
-# is transactional and count(*) requires an expensive full table scan.
+# LiveStats keeps a live count of the table sizes. This is important for any transactional database
+# like InnoDB, PostgreSQL etc because count(*) requires an expensive full table scan.
#
# SEE example.pl FOR DOCUMENTATION
#
sub livestats_description {
- return "LiveStats keeps a live count of the table sizes. This is\n"
- . "important because InnoDB is transactional and count(*)\n"
- . "requires an expensive full table scan."
+ return "LiveStats keeps a live count of the table sizes. This is\n".
+ "important because InnoDB is transactional and count(*)\n".
+ "requires an expensive full table scan."
}
sub livestats_init {
+ # live stats has many elements that are RDBMS specific, so if the user is using a RDBMS we don't
+ # understand its better to warn and exit
+ if($g_db_rdbms ne 'mysql' and $g_db_rdbms ne 'postgresql') {
+ warn("'$g_db_rdbms' is not supported for livestats.\n\n");
+ return 0;
+ }
+
# for PostgreSQL we need to CREATE LANGUAGE
if($g_db_rdbms eq 'postgresql') {
mbz_do_sql("CREATE LANGUAGE plpgsql");
}
# create tables
- print "Creating livestats table...";
- mbz_do_sql("CREATE OR REPLACE FUNCTION update_livestats(newname varchar(255), newval bigint)\n".
- "RETURNS VOID AS \$\$\n".
- "BEGIN\n".
- " UPDATE livestats SET val = newval WHERE name = newname;\n".
- " IF found THEN\n".
- " RETURN;\n".
- " END IF;\n".
- " INSERT INTO livestats(name, val) VALUES (newname, newval);\n".
- "END;".
- "\$\$\n".
- "LANGUAGE plpgsql;");
- mbz_do_sql("DROP TABLE livestats cascade");
- mbz_do_sql("DROP VIEW livestats_count");
- mbz_do_sql("DROP VIEW livestats_sql");
- mbz_do_sql("CREATE TABLE livestats (name varchar(255) not null primary key, val bigint)");
- mbz_do_sql("CREATE VIEW livestats_count as SELECT sum(val) as total FROM livestats WHERE name like 'count.%'");
- mbz_do_sql("CREATE VIEW livestats_sql as SELECT name, val FROM livestats WHERE name like 'sql.%' ".
- "UNION SELECT 'sql.all', sum(val) FROM livestats WHERE name like 'sql.%'");
+ print "Creating livestats tables and views...";
+ if(mbz_table_exists("livestats")) {
+ if($g_db_rdbms eq 'postgresql') {
+ # PostgreSQL requires a cascaded DROP
+ mbz_do_sql("DROP TABLE livestats cascade");
+ } else {
+ # some other generic-SQL like mysql
+ mbz_do_sql("DROP TABLE livestats");
+ }
+ }
+ mbz_do_sql("DROP VIEW livestats_count") if(mbz_table_exists("livestats_count"));
+ mbz_do_sql("DROP VIEW livestats_sql") if(mbz_table_exists("livestats_sql"));
+
+ # the actual livestats table
+ mbz_do_sql(qq|
+ CREATE TABLE livestats (
+ name varchar(255) not null primary key,
+ val bigint
+ )
+ |);
+
+ # a couple of extra views
+ mbz_do_sql(qq|
+ CREATE VIEW livestats_count AS
+ SELECT sum(val) as total FROM livestats WHERE name like 'count.%'
+ |);
+ mbz_do_sql(qq|
+ CREATE VIEW livestats_sql AS
+ SELECT name, val FROM livestats WHERE name like 'sql.%'
+ UNION SELECT 'sql.all', sum(val) FROM livestats WHERE name like 'sql.%'
+ |);
+
print " Done\n";
# count tables
if($g_db_rdbms eq 'postgresql') {
- $sth = $dbh->prepare("select table_name from information_schema.tables where table_schema='public'");
+ $sth = $dbh->prepare("select table_name from information_schema.tables ".
+ "where table_schema='public'");
}
if($g_db_rdbms eq 'mysql') {
$sth = $dbh->prepare("show tables");
}
$sth->execute();
$start = time();
+
while(@result = $sth->fetchrow_array()) {
if($result[0] ne "livestats") {
print " Counting records for table $result[0]... ";
+ $table = $result[0];
+ $table = "\"$table\"" if($g_db_rdbms eq 'postgresql');
+ $table = "`$table`" if($g_db_rdbms eq 'mysql');
+
+ # create the key if it doesn't exist
+ $sth2 = $dbh->prepare("select count(1) from livestats where name='count.$result[0]'");
+ $sth2->execute();
+ $key_exists = $sth->fetchrow_array();
+ if($key_exists[0] == 0) {
+ mbz_do_sql("insert into livestats (name, val) values ".
+ "('count.$result[0]', 0)");
+ }
- # we do a insert then update in case the record alredy exists we make sure the value is
- # updated
- mbz_do_sql("insert into livestats (name, val) values ".
- "('count.$result[0]', (select count(1) from \"$result[0]\"))");
- mbz_do_sql("update livestats set val=(select count(1) from \"$result[0]\") ".
+ mbz_do_sql("update livestats set val=(select count(1) from $table) ".
"where name='count.$result[0]'");
print "Done\n";
@@ -64,7 +94,16 @@ sub livestats_init {
}
# default data
- mbz_do_sql("insert into livestats values ('sql.insert', 0), ('sql.update', 0), ('sql.delete', 0), ('count.pendinglog', 0)");
+ mbz_do_sql(qq|
+ insert into livestats values
+ ('sql.insert', 0),
+ ('sql.update', 0),
+ ('sql.delete', 0),
+ ('count.pendinglog', 0)
+ |);
+
+ # TODO: The name of the pending tables depends on if this is NGS or not, there should be extra
+ # options in settings.pl or builtins.pl to configure these table names.
mbz_do_sql("update livestats set val=0 where name='Pending' or name='PendingData'");
return 1;
View
49 plugins/pendinglog.pl
@@ -9,25 +9,48 @@ sub pendinglog_description {
}
sub pendinglog_init {
- # create table
- print "Creating pendinglog table...";
- mbz_do_sql("CREATE TABLE pendinglog (seqid int not null primary key, repid int not null, tablename varchar(255), op char(1), xid int, data text, keyclause text)");
- mbz_do_sql("create index pendinglog_repid on pendinglog (repid)");
- mbz_do_sql("create index pendinglog_xid on pendinglog (xid)");
- print " Done\n";
+ if(!mbz_table_exists("pendinglog")) {
+ # create table, we will not drop the table if it already exists so there no risk of losing data.
+ print "Creating pendinglog table...";
+ mbz_do_sql(qq|
+ CREATE TABLE pendinglog (
+ seqid int not null primary key,
+ repid int not null,
+ tablename varchar(255),
+ op char(1),
+ xid int,
+ data text,
+ keyclause text
+ )
+ |);
+
+ # create some indexes
+ mbz_do_sql("create index pendinglog_repid on pendinglog (repid)");
+ mbz_do_sql("create index pendinglog_xid on pendinglog (xid)");
+
+ print " Done\n";
+ } else {
+ print "pendinglog table already exists - skipping\n";
+ }
return 1;
}
sub pendinglog_beforereplication {
my ($repID) = @_;
- mbz_do_sql("insert into pendinglog " .
- "select \"Pending\".\"SeqId\", '$repID', substring(\"TableName\" from 11 for length(\"TableName\") - 11) as \"TableName\", " .
- "\"Op\", \"XID\", \"P1\".\"Data\", \"P2\".\"Data\" as keyclause " .
- "from \"Pending\" " .
- "left join \"PendingData\" as \"P1\" on \"Pending\".\"SeqId\"=\"P1\".\"SeqId\" and \"P1\".\"IsKey\"='f' " .
- "left join \"PendingData\" as \"P2\" on \"Pending\".\"SeqId\"=\"P2\".\"SeqId\" and \"P2\".\"IsKey\"='t' ");
- mbz_do_sql("update livestats set val=val+(select count(1) from \"Pending\") where name='count.pendinglog'");
+ mbz_do_sql(qq|
+ INSERT INTO pendinglog
+ SELECT Pending.SeqId, '$repID',
+ substring(TableName from 11 for length(TableName) - 11) as TableName, Op, XID, P1.Data,
+ P2.Data as keyclause
+ FROM Pending
+ LEFT JOIN PendingData as P1 on Pending.SeqId=P1.SeqId and P1.IsKey='f'
+ LEFT JOIN PendingData as P2 on Pending.SeqId=P2.SeqId and P2.IsKey='t'
+ |);
+ mbz_do_sql(qq|
+ UPDATE livestats set val=val+(select count(1) from Pending)
+ where name='count.pendinglog'
+ |);
return 1;
}
View
80 plugins/soundex.pl
@@ -1,30 +1,50 @@
#
-# Soundex provides 4 extra tables for searching based on the
-# soundex algorithm for what words sound like, rather than the
-# physical letters they contain.
+# Soundex provides 4 extra tables for searching based on the soundex algorithm for what words sound
+# like, rather than the physical letters they contain.
#
# SEE example.pl FOR DOCUMENTATION
#
sub soundex_description {
- return "Soundex provides 4 extra tables for searching based on the\n"
- . "soundex algorithm for what words sound like, rather than the\n"
- . "physical letters they contain.";
+ return "Soundex provides 4 extra tables for searching based on the\n".
+ "soundex algorithm for what words sound like, rather than the\n".
+ "physical letters they contain.";
}
sub soundex_init {
+ # this plugin is only available to MySQL
+ if($g_db_rdbms ne 'mysql') {
+ warn("soundex plugin is only supported by MySQL.\n\n");
+ return 0;
+ }
+
# drop existing tables
print "Dropping soundex tables...";
- mbz_do_sql("DROP TABLE IF EXISTS album_soundex");
- mbz_do_sql("DROP TABLE IF EXISTS artist_soundex");
- mbz_do_sql("DROP TABLE IF EXISTS track_soundex");
+ mbz_do_sql("DROP TABLE album_soundex") if(mbz_table_exists("album_soundex"));
+ mbz_do_sql("DROP TABLE artist_soundex") if(mbz_table_exists("artist_soundex"));
+ mbz_do_sql("DROP TABLE track_soundex") if(mbz_table_exists("track_soundex"));
print " Done\n";
# create tables.
print "Creating soundex tables...";
- mbz_do_sql("CREATE TABLE album_soundex (albumid int not null, soundindex varchar(255)) engine=$g_engine");
- mbz_do_sql("CREATE TABLE artist_soundex (artistid int not null, soundindex varchar(255)) engine=$g_engine");
- mbz_do_sql("CREATE TABLE track_soundex (trackid int not null, soundindex varchar(255)) engine=$g_engine");
+ mbz_do_sql(qq|
+ CREATE TABLE album_soundex (
+ albumid int not null,
+ soundindex varchar(255)
+ ) engine=$g_mysql_engine
+ |);
+ mbz_do_sql(qq|
+ CREATE TABLE artist_soundex (
+ artistid int not null,
+ soundindex varchar(255)
+ ) engine=$g_mysql_engine
+ |);
+ mbz_do_sql(qq|
+ CREATE TABLE track_soundex (
+ trackid int not null,
+ soundindex varchar(255)
+ ) engine=$g_mysql_engine
+ |);
print " Done\n";
# load raw data in from original tables
@@ -40,13 +60,25 @@ sub soundex_init {
# apply index
print "Indexing album soundex...";
- mbz_do_sql("alter table album_soundex add primary key(albumid), add index(soundindex)");
+ mbz_do_sql(qq|
+ alter table album_soundex
+ add primary key(albumid),
+ add index(soundindex)
+ |);
print " Done\n";
print "Indexing artist soundex...";
- mbz_do_sql("alter table artist_soundex add primary key(artistid), add index(soundindex)");
+ mbz_do_sql(qq|
+ alter table artist_soundex
+ add primary key(artistid),
+ add index(soundindex)
+ |);
print " Done\n";
print "Indexing track soundex...";
- mbz_do_sql("alter table track_soundex add primary key(trackid), add index(soundindex)");
+ mbz_do_sql(qq|
+ alter table track_soundex
+ add primary key(trackid),
+ add index(soundindex)
+ |);
print " Done\n";
return 1;
@@ -74,11 +106,23 @@ sub soundex_afterstatement {
}
} else {
if($table eq "artist" && $data->{'id'} != 0) {
- mbz_do_sql("INSERT INTO artist_soundex SET artistid='" . $data->{'id'} . "', soundindex=soundex(" . $dbh->quote($data->{'name'}) . ") ON DUPLICATE KEY UPDATE soundindex=soundex(" . $dbh->quote($data->{'name'}) . ")");
+ mbz_do_sql("INSERT INTO artist_soundex SET ".
+ "artistid='" . $data->{'id'} . "', ".
+ "soundindex=soundex(" . $dbh->quote($data->{'name'}) . ") ".
+ "ON DUPLICATE KEY UPDATE ".
+ "soundindex=soundex(" . $dbh->quote($data->{'name'}) . ")");
} elsif($table eq "album" && $data->{'id'} != 0) {
- mbz_do_sql("INSERT INTO album_soundex SET albumid='" . $data->{'id'} . "', soundindex=soundex(" . $dbh->quote($data->{'name'}) . ") ON DUPLICATE KEY UPDATE soundindex=soundex(" . $dbh->quote($data->{'name'}) . ")");
+ mbz_do_sql("INSERT INTO album_soundex SET ".
+ "albumid='" . $data->{'id'} . "', ".
+ "soundindex=soundex(" . $dbh->quote($data->{'name'}) . ") ".
+ "ON DUPLICATE KEY UPDATE ".
+ "soundindex=soundex(" . $dbh->quote($data->{'name'}) . ")");
} elsif($table eq "track" && $data->{'id'} != 0) {
- mbz_do_sql("INSERT INTO track_soundex SET trackid='" . $data->{'id'} . "', soundindex=soundex(" . $dbh->quote($data->{'name'}) . ") ON DUPLICATE KEY UPDATE soundindex=soundex(" . $dbh->quote($data->{'name'}) . ")");
+ mbz_do_sql("INSERT INTO track_soundex SET ".
+ "trackid='" . $data->{'id'} . "', ".
+ "soundindex=soundex(" . $dbh->quote($data->{'name'}) . ") ".
+ "ON DUPLICATE KEY UPDATE ".
+ "soundindex=soundex(" . $dbh->quote($data->{'name'}) . ")");
}
}
return 1;
Please sign in to comment.
Something went wrong with that request. Please try again.