summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwr61 <wr61@e10066b5-e1e2-0310-b819-94efdf66514b>2005-09-05 18:29:51 +0000
committerwr61 <wr61@e10066b5-e1e2-0310-b819-94efdf66514b>2005-09-05 18:29:51 +0000
commitb086b77de6391bcea3b7dc8a15182b22690049a3 (patch)
tree3b4584b48389e504090550a5891d5d9f71faeaf7
parent0149a5461a8c63932555e31d2a8470eac8e00a1d (diff)
downloadvdr-plugin-muggle-b086b77de6391bcea3b7dc8a15182b22690049a3.tar.gz
vdr-plugin-muggle-b086b77de6391bcea3b7dc8a15182b22690049a3.tar.bz2
more merges from muggle-0.1.8-BETA
git-svn-id: https://vdr-muggle.svn.sourceforge.net/svnroot/vdr-muggle/trunk/muggle-plugin@815 e10066b5-e1e2-0310-b819-94efdf66514b
-rw-r--r--mg_db.c139
-rw-r--r--mg_db.h16
-rw-r--r--mg_db_gd_mysql.c14
-rw-r--r--mg_db_gd_mysql.h2
-rw-r--r--mg_db_gd_pg.h3
-rw-r--r--mg_db_gd_sqlite.h3
6 files changed, 94 insertions, 83 deletions
diff --git a/mg_db.c b/mg_db.c
index 9081217..1f767cf 100644
--- a/mg_db.c
+++ b/mg_db.c
@@ -38,6 +38,25 @@ static map <mgKeyTypes, map<string,string> > map_ids;
mgDbServer* DbServer;
+mgDbServer::mgDbServer()
+{
+ printf("mgDbServer\n");
+#ifdef HAVE_SQLITE
+ m_server = new mgDbServerSQLite;
+#elif HAVE_PG
+ m_server = new mgDbServerPG;
+#else
+ m_server = new mgDbServerMySQL;
+#endif
+}
+
+mgDbServer::~mgDbServer()
+{
+ printf("~mgDbServer\n");
+ delete m_server;
+ m_server = 0;
+}
+
mgSQLString::~mgSQLString()
{
delete m_str;
@@ -138,6 +157,8 @@ void
mgSQLString::operator=(const char* b)
{
delete m_str;
+ free(m_original);
+ m_original = 0;
Init(b);
}
@@ -145,6 +166,8 @@ void
mgSQLString::operator=(const mgSQLString& b)
{
delete m_str;
+ free(m_original);
+ m_original = 0;
Init(b.original());
}
@@ -882,7 +905,9 @@ mgDb::Build_cddbid(const mgSQLString& artist) const
{
char *s;
asprintf(&s,"%ld-%.9s",random(),artist.original());
- return mgSQLString(s);
+ mgSQLString result = mgSQLString(s);
+ free(s);
+ return result;
}
mgSQLString
@@ -942,8 +967,10 @@ mgDb::getAlbum(const char *filename,const mgSQLString& c_album,
asprintf(&b,"INSERT INTO album (title,artist,cddbid) "
"VALUES(%s,%s,%s)",
c_album.quoted(),c_artist.quoted(),result.quoted());
- Execute(b);
+ int rows = Execute(b);
free(b);
+ if (!rows)
+ result="NULL";
}
free(where);
}
@@ -1077,65 +1104,7 @@ mgDb::SyncFile(const char *filename)
}
TagLib::FileRef f( filename) ;
- if( f.isNull() || !f.tag() )
- {
- if( !strcasecmp( ext, "wav" ) )
- {
- mgDebug(2,"Importing %s",filename);
- char *folders[4];
- char *fbuf=SeparateFolders(filename,folders,4);
- mgSQLString c_folder1(folders[0]);
- mgSQLString c_folder2(folders[1]);
- mgSQLString c_folder3(folders[2]);
- mgSQLString c_folder4(folders[3]);
- free(fbuf);
-
- mgSQLString c_artist("Unknown");
- mgSQLString c_title("Unknown");
- mgSQLString c_album("Unassigned");
- mgSQLString c_lang("");
- mgSQLString c_genre1("");
- mgSQLString c_cddbid( getAlbum(filename, c_album, c_artist) );
- mgSQLString c_mp3file(cfilename);
- sprintf(sql,"SELECT id from tracks WHERE mp3file=%s",c_mp3file.quoted());
-
- string id = get_col0(sql);
- if (id!="NULL")
- {
- sprintf( sql,"UPDATE tracks SET artist=%s, title=%s,year=%d,sourceid=%s,"
- "tracknb=%d,length=%d,bitrate=%d,samplerate=%d,"
- "channels=%d,genre1=%s,lang=%s WHERE id=%ld",
- c_artist.quoted(),c_title.quoted(),f.tag()->year(),c_cddbid.quoted(),
- f.tag()->track(), 0, 0, 0,
- 2, c_genre1.quoted(), c_lang.quoted(), atol(id.c_str() ) );
- }
- else
- {
- sprintf( sql,"INSERT INTO tracks "
- "(artist,title,year,sourceid,"
- "tracknb,mp3file,length,bitrate,samplerate,"
- "channels,genre1,genre2,lang,folder1,folder2,"
- "folder3,folder4) "
- "VALUES (%s,%s,%u,%s,"
- "%u,%s,%d,%d,%d,"
- "%d,%s,'',%s,%s,%s,%s,%s)",
- c_artist.quoted(),c_title.quoted(), 0, c_cddbid.quoted(),
- 0, c_mp3file.quoted(), 0,
- 0, 0,
- 2, c_genre1.quoted(), c_lang.quoted(),
- c_folder1.quoted(),c_folder2.quoted(),
- c_folder3.quoted(),c_folder4.quoted());
- }
- Execute(sql);
- return true;
- }
- else
- {
- return false;
- }
- }
mgDebug(2,"Importing %s",filename);
- TagLib::AudioProperties *ap = f.audioProperties();
get_ID3v2_Tags(filename);
char *folders[4];
char *fbuf=SeparateFolders(filename,folders,4);
@@ -1144,13 +1113,39 @@ mgDb::SyncFile(const char *filename)
mgSQLString c_folder3(folders[2]);
mgSQLString c_folder4(folders[3]);
free(fbuf);
- mgSQLString c_artist(f.tag()->artist());
- mgSQLString c_title(f.tag()->title());
- mgSQLString c_album(f.tag()->album());
+ mgSQLString c_artist("Unknown");
+ mgSQLString c_album("Unassigned");
+ mgSQLString c_title("Unknown");
+ mgSQLString c_genre1("NULL");
+ int year = 0;
+ int track = 0;
+ int length = 0;
+ int bitrate = 0;
+ int samplerate = 0;
+ int channels = 0;
+ if (!f.isNull())
+ {
+ TagLib::AudioProperties *ap = f.audioProperties();
+ if (ap)
+ {
+ length = ap->length();
+ bitrate = ap->bitrate();
+ samplerate = ap->sampleRate();
+ channels = ap->channels();
+ }
+ }
+ if (!f.isNull() && f.tag())
+ {
+ c_artist = f.tag()->artist();
+ c_album = f.tag()->album();
+ c_title = f.tag()->title();
+ c_genre1 = getGenre1(f);
+ year = f.tag()->year();
+ year = f.tag()->track();
+ }
if (strlen(c_album.original())==0)
c_album = "Unassigned";
mgSQLString c_lang(m_TLAN);
- mgSQLString c_genre1(getGenre1(f));
mgSQLString c_cddbid(getAlbum(filename,c_album,c_artist));
mgSQLString c_mp3file(cfilename);
sprintf(sql,"SELECT id from tracks WHERE mp3file=%s",c_mp3file.quoted());
@@ -1160,9 +1155,9 @@ mgDb::SyncFile(const char *filename)
sprintf(sql,"UPDATE tracks SET artist=%s, title=%s,year=%d,sourceid=%s,"
"tracknb=%d,length=%d,bitrate=%d,samplerate=%d,"
"channels=%d,genre1=%s,lang=%s WHERE id=%ld",
- c_artist.quoted(),c_title.quoted(),f.tag()->year(),c_cddbid.quoted(),
- f.tag()->track(),ap->length(),ap->bitrate(),ap->sampleRate(),
- ap->channels(),c_genre1.quoted(),c_lang.quoted(),atol(id.c_str()));
+ c_artist.quoted(),c_title.quoted(),year,c_cddbid.quoted(),
+ track,length,bitrate,samplerate,
+ channels,c_genre1.quoted(),c_lang.quoted(),atol(id.c_str()));
}
else
{
@@ -1174,15 +1169,13 @@ mgDb::SyncFile(const char *filename)
"VALUES (%s,%s,%u,%s,"
"%u,%s,%d,%d,%d,"
"%d,%s,'',%s,%s,%s,%s,%s)",
- c_artist.quoted(),c_title.quoted(),f.tag()->year(),c_cddbid.quoted(),
- f.tag()->track(),c_mp3file.quoted(),ap->length(),
- ap->bitrate(),ap->sampleRate(),
- ap->channels(),c_genre1.quoted(),c_lang.quoted(),
+ c_artist.quoted(),c_title.quoted(),year,c_cddbid.quoted(),
+ track,c_mp3file.quoted(),length,bitrate,samplerate,
+ channels,c_genre1.quoted(),c_lang.quoted(),
c_folder1.quoted(),c_folder2.quoted(),
c_folder3.quoted(),c_folder4.quoted());
}
- Execute(sql);
- return true;
+ return Execute(sql) == 1;
}
string
diff --git a/mg_db.h b/mg_db.h
index 73ea605..934d372 100644
--- a/mg_db.h
+++ b/mg_db.h
@@ -300,14 +300,24 @@ class mgKeyMaps {
extern mgKeyMaps KeyMaps;
-class mgDbServer {
+class mgDbServerImp {
public:
- mgDbServer() {};
- mgDb* EscapeDb() const { return m_escape_db; }
+ mgDbServerImp() {m_escape_db = 0;}
+ virtual ~mgDbServerImp() {delete m_escape_db;}
+ mgDb* EscapeDb() const { return m_escape_db;}
protected:
mgDb* m_escape_db;
};
+class mgDbServer {
+ private:
+ mgDbServerImp *m_server;
+ public:
+ mgDbServer();
+ ~mgDbServer();
+ mgDb* EscapeDb() { return m_server->EscapeDb(); }
+};
+
extern mgDbServer* DbServer;
#endif
diff --git a/mg_db_gd_mysql.c b/mg_db_gd_mysql.c
index 75fe7fb..2393441 100644
--- a/mg_db_gd_mysql.c
+++ b/mg_db_gd_mysql.c
@@ -72,12 +72,16 @@ mgQueryMySQL::mgQueryMySQL(void* db,string sql,mgQueryNoise noise)
mgQueryMySQL::~mgQueryMySQL()
{
mysql_free_result (m_table);
+ m_table = 0;
}
char **
mgQueryMySQL::Next()
{
- return mysql_fetch_row(m_table);
+ if (!m_table)
+ return 0;
+ else
+ return mysql_fetch_row(m_table);
}
const char*
@@ -222,8 +226,6 @@ mgDbServerMySQL::mgDbServerMySQL()
mgDbServerMySQL::~mgDbServerMySQL()
{
- delete m_escape_db;
- m_escape_db=0;
#ifndef HAVE_ONLY_SERVER
mgDebug(3,"calling mysql_server_end");
mysql_server_end();
@@ -331,7 +333,7 @@ static char *db_cmds[] =
"reclength int(11) default NULL, "
"enddate date default NULL, "
"endtime time default NULL, "
- "repeat varchar(10) default NULL, "
+ "repeating varchar(10) default NULL, "
"initcmd varchar(255) default NULL, "
"parameters varchar(255) default NULL, "
"atqjob int(11) default NULL, "
@@ -367,7 +369,7 @@ static char *db_cmds[] =
"sourceid varchar(20) default NULL, "
"tracknb tinyint(3) unsigned default NULL, "
"mp3file varchar(255) default NULL, "
- "condition tinyint(3) unsigned default NULL, "
+ "conditions tinyint(3) unsigned default NULL, "
"voladjust smallint(6) default '0', "
"lengthfrm mediumint(9) default '0', "
"startfrm mediumint(9) default '0', "
@@ -464,7 +466,7 @@ mgDbGd::ServerConnect ()
return false;
m_connect_time=time(0);
if (!DbServer)
- DbServer = new mgDbServerMySQL;
+ DbServer = new mgDbServer;
m_db = mysql_init (0);
if (!m_db)
return false;
diff --git a/mg_db_gd_mysql.h b/mg_db_gd_mysql.h
index ba8f08c..d5516c2 100644
--- a/mg_db_gd_mysql.h
+++ b/mg_db_gd_mysql.h
@@ -54,7 +54,7 @@ class mgDbGd : public mgDb {
};
-class mgDbServerMySQL : public mgDbServer {
+class mgDbServerMySQL : public mgDbServerImp {
public:
mgDbServerMySQL();
~mgDbServerMySQL();
diff --git a/mg_db_gd_pg.h b/mg_db_gd_pg.h
index 0eb3f0e..73996db 100644
--- a/mg_db_gd_pg.h
+++ b/mg_db_gd_pg.h
@@ -20,6 +20,9 @@ using namespace std;
#include "mg_db.h"
+class mgDbServerPG : public mgDbServerImp {
+};
+
class mgSQLStringPG : public mgSQLStringImp {
public:
mgSQLStringPG(const char* s);
diff --git a/mg_db_gd_sqlite.h b/mg_db_gd_sqlite.h
index 17de670..81d8516 100644
--- a/mg_db_gd_sqlite.h
+++ b/mg_db_gd_sqlite.h
@@ -20,6 +20,9 @@ using namespace std;
#include "mg_db.h"
+class mgDbServerSQLite : public mgDbServerImp {
+};
+
class mgSQLStringSQLite : public mgSQLStringImp {
public:
mgSQLStringSQLite(const char* s);