/src/libtomahawk/database/DatabaseCommand_GenericSelect.h

http://github.com/tomahawk-player/tomahawk · C Header · 90 lines · 37 code · 14 blank · 39 comment · 0 complexity · 87592fcc698536cac73266199ed9a6a7 MD5 · raw file

  1. /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2. *
  3. * Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
  4. *
  5. * Tomahawk is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * Tomahawk is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef DATABASECOMMAND_GENERICSELECT_H
  19. #define DATABASECOMMAND_GENERICSELECT_H
  20. #include <QVariantMap>
  21. #include "DatabaseCommand.h"
  22. #include "Typedefs.h"
  23. #include <QStringList>
  24. #include <QMetaType>
  25. #include "DllMacro.h"
  26. namespace Tomahawk
  27. {
  28. /**
  29. * This dbcmd takes a generic SELECT command that operates on the database and returns a list of query_ptrs
  30. * that match.
  31. *
  32. * In order for the conversion to query_ptr to work, the SELECT command should select the following items:
  33. *
  34. * track query:
  35. * track.name, artist.name [, optional extra values ]
  36. *
  37. * artist query:
  38. * artist.id, artist.name [, optional extra values ]
  39. *
  40. * album query:
  41. * album.id, album.name, artist.id, artist.name [, optional extra values ]
  42. *
  43. * Any extra values in the resultset will be returned as a QVariantList attached to the "data" property of each query_ptr
  44. *
  45. * Notes:
  46. * * Do not trail your SQL command with ;
  47. * * Do not use the LIMIT command if you pass limitResults > -1
  48. *
  49. */
  50. class DLLEXPORT DatabaseCommand_GenericSelect : public DatabaseCommand
  51. {
  52. Q_OBJECT
  53. public:
  54. enum QueryType {
  55. Track,
  56. Artist,
  57. Album
  58. };
  59. explicit DatabaseCommand_GenericSelect( const QString& sqlSelect, QueryType type, int limitResults = -1, QObject* parent = 0 );
  60. explicit DatabaseCommand_GenericSelect( const QString& sqlSelect, QueryType type, bool rawData, QObject* parent = 0 );
  61. virtual void exec( DatabaseImpl* lib );
  62. virtual bool doesMutates() const { return false; }
  63. virtual QString commandname() const { return "genericselect"; }
  64. signals:
  65. void tracks( const QList< Tomahawk::query_ptr >& tracks );
  66. void artists( const QList< Tomahawk::artist_ptr >& artists );
  67. void albums( const QList< Tomahawk::album_ptr >& albums );
  68. void rawData( const QList< QStringList >& data );
  69. private:
  70. QString m_sqlSelect;
  71. QueryType m_queryType;
  72. int m_limit;
  73. bool m_raw;
  74. };
  75. }
  76. #endif // DATABASECOMMAND_GENERICSELECT_H