SoundBand/sync/mysql.h

146 lines
4.1 KiB
C
Raw Normal View History

2017-12-24 00:20:53 +03:00
#ifndef MYSQL_H
#define MYSQL_H
#include <QString>
2017-12-24 22:04:40 +03:00
#include "song.h"
2017-12-24 00:20:53 +03:00
class QSqlDatabase;
class QSqlQuery;
namespace syncLib {
class MySql
{
2017-12-24 22:04:40 +03:00
private:
QSqlDatabase *db;
QSqlQuery *qyery;
QString dataBaseName;
/**
* @brief sqlErrorLog show sql error
* @param qyery
*/
2018-03-05 01:47:07 +03:00
void sqlErrorLog(const QString& qyery) const;
2017-12-24 22:04:40 +03:00
2017-12-24 00:20:53 +03:00
public:
2017-12-24 22:04:40 +03:00
MySql(const QString& databasename);
/**
* @brief initDB initialize local database of song
*/
void initDB(const QString& database = DATABASE_NAME );
/**
* @brief load song of database;
* @brief song -
* @brief result - the resulting value;
* @return true if everything's done
*/
bool load(const SongHeader &song, Song &result);
/**
* @brief save media data into local database.
* @param song savining media data.
* @return id of song saved on local database.
*/
int save(const Song &song);
/**
* @brief save media file, bud from url.
*/
2017-12-24 22:04:40 +03:00
int save(const QString &url);
/**
* @brief fromDataBase return a song from local database by id.
* @param id of song saved in local database.
* @return song drom local database.
*/
Song fromDataBase(const int id);
/**
* @brief updateAvelableSongs will update the list of participants of songs.
* @param list - [out value] list of avelable song.
* @param playList - play list of songs.
2017-12-24 22:04:40 +03:00
* @return true if all done
*/
bool updateAvailableSongs(QList<SongHeader>& list, const QString &playList = "");
2018-01-19 15:03:07 +03:00
/**
* @brief updateAvelableSongs will update the list of participants of songs.
* @param list - [out value] list of avelable song.
* @param playList - play list of songs (string).
* @return true if all done
*/
bool updateAvailableSongs(QStringList& list, const QString &playList = "");
/**
* @brief removeSong - remove song from local database.
* @param header - heder removing song. first : song removed by id,
* if id of head = -1 then song removed by name and size, and if song no finded this finction return false.
* @return trye if all done.
*/
bool removeSong(const SongHeader& header);
/**
* @brief addPlayList add a new play list into database.
* @param newPlayList - a new paly list.
* @return trye if all done.
*/
2017-12-25 16:57:29 +03:00
bool addPlayList(const QString& newPlayList, const QString& desc = "");
2017-12-24 22:04:40 +03:00
/**
2017-12-25 16:57:29 +03:00
* @brief addToPlayList - add song to play list.
* @param header - header of song. first : song removed by id,
* if id of head = -1 then song removed by name and size, and if song no finded this finction return false.
* @param newPlaylist
* @return true if all done.
*/
2017-12-25 16:57:29 +03:00
bool addToPlayList(const SongHeader& header, const QString& playList);
/**
* @brief addToPlayList - add song to play list.
* @param header - header of song. first : song removed by id,
* if id of head = -1 then song removed by name and size, and if song no finded this finction return false.
* @param newPlaylist
* @return true if all done.
*/
bool removeFromPlayList(const SongHeader& header, const QString& playList);
/**
* @brief removePlayList - remove play list from local database.
* @param playList - removed play list.
* @return true if all done.
*/
bool removePlayList(const QString& playList);
/**
* @brief exec - execute сustom sql file.
* @param q - sql query
* @param sqlFile - sql - file with sql code.
* @return trye if all done.
*/
2017-12-24 00:20:53 +03:00
static bool exec(QSqlQuery *q, const QString& sqlFile);
2017-12-24 22:04:40 +03:00
2017-12-25 18:40:36 +03:00
/**
* @brief getPlayLists show all created playlists.
* @param list - list of play lists.
* @return trye if all done
*/
2018-03-05 01:47:07 +03:00
bool getPlayLists(QStringList &list) const;
2017-12-25 18:40:36 +03:00
2018-01-19 16:48:22 +03:00
/**
* @brief getSongId get song id by name
* @param name - name of song
* @return true if finded song,
* bud if count of finded songs is greater than 1 return false
*/
int getSongId(const QString& name);
/**
* @brief clear - clear free space in local database
*/
2017-12-25 18:40:36 +03:00
void clear();
2017-12-24 00:20:53 +03:00
~MySql();
};
}
#endif // MYSQL_H