File indexing completed on 2025-02-23 04:27:58
0001 /**************************************************************************************** 0002 * Copyright (c) 2008 Edward Toroshchin <edward.hades@gmail.com> * 0003 * Copyright (c) 2009 Jeff Mitchell <mitchell@kde.org> * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify it under * 0006 * the terms of the GNU General Public License as published by the Free Software * 0007 * Foundation; either version 2 of the License, or (at your option) any later * 0008 * version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0011 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0012 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU General Public License along with * 0015 * this program. If not, see <http://www.gnu.org/licenses/>. * 0016 ****************************************************************************************/ 0017 0018 #ifndef AMAROK_STORAGE_MYSQLSTORAGE_H 0019 #define AMAROK_STORAGE_MYSQLSTORAGE_H 0020 0021 #include "core/storage/SqlStorage.h" 0022 #include <mysql.h> 0023 0024 0025 #include <QMutex> 0026 #include <QString> 0027 0028 #ifdef Q_WS_WIN 0029 #include <winsock2.h> 0030 #endif 0031 0032 #if !defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 80000 0033 using my_bool = bool; 0034 #endif 0035 0036 /** 0037 * Implements a SqlStorage using a MySQL backend 0038 */ 0039 class MySqlStorage: public SqlStorage 0040 { 0041 public: 0042 MySqlStorage(); 0043 ~MySqlStorage() override; 0044 0045 QStringList query( const QString &query ) override; 0046 int insert( const QString &statement, const QString &table = QString() ) override; 0047 0048 QString escape( const QString &text ) const override; 0049 QString randomFunc() const override; 0050 0051 QString boolTrue() const override; 0052 QString boolFalse() const override; 0053 QString idType() const override; 0054 QString textColumnType( int length = 255 ) const override; 0055 QString exactTextColumnType( int length = 1000 ) const override; 0056 //the below value may have to be decreased even more for different indexes; only time will tell 0057 QString exactIndexableTextColumnType( int length = 324 ) const override; 0058 QString longTextColumnType() const override; 0059 0060 /** Returns a list of the last sql errors. 0061 The list might not include every one error if the number 0062 is beyond a sensible limit. 0063 */ 0064 QStringList getLastErrors() const override; 0065 0066 /** Clears the list of the last errors. */ 0067 void clearLastErrors() override; 0068 0069 protected: 0070 /** Adds an error message to the m_lastErrors. 0071 * 0072 * Adds a message including the mysql error number and message 0073 * to the last error messages. 0074 * @param message Usually the query statement being executed. 0075 */ 0076 void reportError( const QString &message ); 0077 0078 void initThreadInitializer(); 0079 0080 /** Sends the first sql commands to setup the connection. 0081 * 0082 * Sets things like the used database and charset. 0083 * @returns false if something fatal was wrong. 0084 */ 0085 bool sharedInit( const QString &databaseName ); 0086 0087 MYSQL* m_db; 0088 0089 /** Mutex protecting the m_lastErrors list */ 0090 mutable QMutex m_mutex; 0091 0092 QString m_debugIdent; 0093 QStringList m_lastErrors; 0094 }; 0095 0096 #endif