summaryrefslogtreecommitdiff
path: root/mg_db_gd_mysql.h
blob: fa1dd539e6781996eb8171505be7c7f4561a4e58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*!
 * \file   mg_db_gd_mysql.h
 * \brief  A capsule around giantdisc database access
 *
 * \version $Revision: 1.2 $
 * \date    $Date: 2005-04-13 17:42:54 +0100 (Thu, 13 Apr 2005) $
 * \author  Wolfgang Rohdewald
 * \author  Responsible author: $Author: wolfgang61 $
 */

#ifndef __MG_DB_GD_H
#define __MG_DB_GD_H

#include <string>
#include <tag.h>
#include <map>
#include <mysql/mysql.h>

using namespace std;

#include "mg_db.h"

class mgDbGd : public mgDb
{
	public:
		mgDbGd (bool SeparateThread=false);
		~mgDbGd();
		bool ServerConnect();
		bool ConnectDatabase();
		bool Create();
		bool Clear();
		int AddToCollection( const string Name,const vector<mgItem*>&items,mgParts* what);
		int  RemoveFromCollection( const string Name,const vector<mgItem*>&items,mgParts* what);

		bool NeedGenre2();
		long thread_id() { return mysql_thread_id(m_db); }
		bool FieldExists(string table, string field);
		void ServerEnd();
		bool Threadsafe();
		const char* HelpText() const;
		const char *Options() const;
		const char *DecadeExpr();
		string Now() const { return "CURRENT_TIMESTAMP"; }
		string Directory() const
		{
			return "substr(tracks.mp3file,1,length(tracks.mp3file)"
				"-instr(reverse(tracks.mp3file),'/'))";
		}
	protected:
		void StartTransaction();
		void Commit();
		void *ImplDbHandle() const { return (void*)m_db; }
	private:
		MYSQL *m_db;
		void CreateFolderFields();
		MYSQL_RES* Query( const string sql);
		bool sql_query(string sql);
		bool SetCharset();
};

class mgDbServerMySQL : public mgDbServerImp
{
	public:
		mgDbServerMySQL();
		~mgDbServerMySQL();
};

class mgSQLStringMySQL : public mgSQLStringImp
{
	public:
		mgSQLStringMySQL(const char* s);
		~mgSQLStringMySQL();
		char *unquoted() const;
	private:
		mutable char* m_unquoted;
};

class mgQueryMySQL : public mgQueryImp
{
	public:
		mgQueryMySQL(void* db,string sql,mgQueryNoise noise);
		~mgQueryMySQL();
		char ** Next();
	private:
		MYSQL_RES *m_table;
		int m_rc;
		MYSQL *m_db;
};
#endif