00001 /*MT* 00002 00003 MediaTomb - http://www.mediatomb.cc/ 00004 00005 mysql_storage.h - this file is part of MediaTomb. 00006 00007 Copyright (C) 2005 Gena Batyan <bgeradz@mediatomb.cc>, 00008 Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc> 00009 00010 Copyright (C) 2006-2010 Gena Batyan <bgeradz@mediatomb.cc>, 00011 Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>, 00012 Leonhard Wimmer <leo@mediatomb.cc> 00013 00014 MediaTomb is free software; you can redistribute it and/or modify 00015 it under the terms of the GNU General Public License version 2 00016 as published by the Free Software Foundation. 00017 00018 MediaTomb is distributed in the hope that it will be useful, 00019 but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 GNU General Public License for more details. 00022 00023 You should have received a copy of the GNU General Public License 00024 version 2 along with MediaTomb; if not, write to the Free Software 00025 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 00026 00027 $Id: mysql_storage.h 2081 2010-03-23 20:18:00Z lww $ 00028 */ 00029 00031 00032 #ifdef HAVE_MYSQL 00033 00034 #ifndef __MYSQL_STORAGE_H__ 00035 #define __MYSQL_STORAGE_H__ 00036 00037 #include "common.h" 00038 #include "storage/sql_storage.h" 00039 #include "sync.h" 00040 #include <mysql.h> 00041 00042 class MysqlStorage : private SQLStorage 00043 { 00044 private: 00045 MysqlStorage(); 00046 friend zmm::Ref<Storage> Storage::createInstance(); 00047 virtual ~MysqlStorage(); 00048 virtual void init(); 00049 virtual void shutdownDriver(); 00050 00051 virtual zmm::String quote(zmm::String str); 00052 virtual inline zmm::String quote(int val) { return zmm::String::from(val); } 00053 virtual inline zmm::String quote(unsigned int val) { return zmm::String::from(val); } 00054 virtual inline zmm::String quote(long val) { return zmm::String::from(val); } 00055 virtual inline zmm::String quote(unsigned long val) { return zmm::String::from(val); } 00056 virtual inline zmm::String quote(bool val) { return zmm::String(val ? '1' : '0'); } 00057 virtual inline zmm::String quote(char val) { return quote(zmm::String(val)); } 00058 virtual zmm::Ref<SQLResult> select(const char *query, int length); 00059 virtual int exec(const char *query, int length, bool getLastInsertId = false); 00060 virtual void storeInternalSetting(zmm::String key, zmm::String value); 00061 00062 void _exec(const char *query, int lenth = -1); 00063 00064 MYSQL db; 00065 00066 bool mysql_connection; 00067 00068 zmm::String getError(MYSQL *db); 00069 00070 zmm::Ref<Mutex> mysqlMutex; 00071 00072 virtual void threadCleanup(); 00073 virtual bool threadCleanupRequired() { return true; } 00074 00075 pthread_key_t mysql_init_key; 00076 bool mysql_init_key_initialized; 00077 00078 void checkMysqlThreadInit(); 00079 00080 zmm::Ref<zmm::Array<zmm::StringBase> > insertBuffer; 00081 virtual void _addToInsertBuffer(zmm::Ref<zmm::StringBuffer> query); 00082 virtual void _flushInsertBuffer(); 00083 }; 00084 00085 class MysqlResult : private SQLResult 00086 { 00087 private: 00088 int nullRead; 00089 MysqlResult(MYSQL_RES *mysql_res); 00090 virtual ~MysqlResult(); 00091 virtual zmm::Ref<SQLRow> nextRow(); 00092 virtual unsigned long long getNumRows() { return mysql_num_rows(mysql_res); } 00093 MYSQL_RES *mysql_res; 00094 00095 friend class MysqlRow; 00096 friend class MysqlStorage; 00097 }; 00098 00099 class MysqlRow : private SQLRow 00100 { 00101 private: 00102 MysqlRow(MYSQL_ROW mysql_row, zmm::Ref<SQLResult> sqlResult); 00103 inline virtual char* col_c_str(int index) { return mysql_row[index]; } 00104 00105 MYSQL_ROW mysql_row; 00106 00107 friend zmm::Ref<SQLRow> MysqlResult::nextRow(); 00108 }; 00109 00110 #endif // __MYSQL_STORAGE_H__ 00111 00112 #endif // HAVE_MYSQL
1.6.1