DatabaseQuery.h
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25  */
26 
32 #ifndef __DATABASE_QUERY_H__
33 #define __DATABASE_QUERY_H__
34 
35 // FORWARD REFERENCES =========================================================
36 class CDatabaseQuery;
37 
38 // INCLUDES ===================================================================
39 #include <string>
40 #include <vector>
41 #include <deque>
42 #include <set>
43 
44 #include <sqlite3.h>
45 
46 #include <prlock.h>
47 #include <prmon.h>
48 
49 #include <nsAutoPtr.h>
50 #include <nsCOMPtr.h>
51 #include <nsCOMArray.h>
52 #include <nsTArray.h>
53 #include <nsStringGlue.h>
54 #include <nsIClassInfo.h>
55 #include <nsInterfaceHashtable.h>
56 #include <nsHashKeys.h>
57 
58 #include "sbIDatabaseQuery.h"
59 #include "sbIDatabasePreparedStatement.h"
60 #include "DatabaseResult.h"
61 
62 // DEFINES ====================================================================
63 #define SONGBIRD_DATABASEQUERY_CONTRACTID \
64  "@songbirdnest.com/Songbird/DatabaseQuery;1"
65 #define SONGBIRD_DATABASEQUERY_CLASSNAME \
66  "Songbird Database Query Interface"
67 #define SONGBIRD_DATABASEQUERY_CID \
68 { /* 377a6592-64bd-4a6b-a941-d488abb5a8aa */ \
69  0x377a6592, \
70  0x64bd, \
71  0x4a6b, \
72  {0xa9, 0x41, 0xd4, 0x88, 0xab, 0xb5, 0xa8, 0xaa} \
73 }
74 // CLASSES ====================================================================
75 typedef enum {
83 
85 {
87  type(ISNULL),
88  doubleValue(0),
89  int32Value(0),
90  int64Value(0) {
91  }
92 
94  }
95 
96  CQueryParameter(const CQueryParameter &queryParameter) :
97  type(queryParameter.type),
98  utf8StringValue(queryParameter.utf8StringValue),
99  stringValue(queryParameter.stringValue),
100  doubleValue(queryParameter.doubleValue),
101  int32Value(queryParameter.int32Value),
102  int64Value(queryParameter.int64Value) {
103  }
104 
106  nsCString utf8StringValue;
107  nsString stringValue;
108  double doubleValue;
109  PRInt32 int32Value;
110  PRInt64 int64Value;
111 };
112 
113 typedef std::vector< CQueryParameter > bindParameterArray_t;
114 
115 class CDatabaseEngine;
116 class QueryProcessorThread;
117 class nsIEventTarget;
118 class nsIURI;
119 class sbIDatabaseEngine;
120 
122  public nsIClassInfo
123 {
124 friend class CDatabaseEngine;
125 friend class QueryProcessorThread;
126 
127 public:
128  CDatabaseQuery();
129  virtual ~CDatabaseQuery();
130 
131 public:
133  NS_DECL_SBIDATABASEQUERY
134  NS_DECL_NSICLASSINFO
135 
136  nsresult Init();
137 
143  nsresult GetDatabaseLocation(nsACString& aURISpec);
144 
145 protected:
147  void SetResultObject(CDatabaseResult *aResultObject);
148 
149  nsresult PopQuery(sbIDatabasePreparedStatement **_retval);
150  bindParameterArray_t* GetQueryParameters(PRUint32 aQueryIndex);
152 
153  PRLock *m_pLock;
154 
156 
157  PRBool m_IsAborting;
159  PRBool m_AsyncQuery;
160 
161  PRUint32 m_CurrentQuery;
162  PRInt32 m_LastError;
163 
164  nsRefPtr<CDatabaseResult> m_QueryResult;
165  nsString m_DatabaseGUID;
166  std::deque< nsCOMPtr<sbIDatabasePreparedStatement> > m_DatabaseQueryList;
167 
170 
171  nsInterfaceHashtableMT<nsISupportsHashKey, sbIDatabaseSimpleQueryCallback> m_CallbackList;
172  std::deque< bindParameterArray_t > m_BindParameters;
173 
174  PRUint64 m_RollingLimit;
177 
178  nsCOMPtr<sbIDatabaseEngine> mDatabaseEngine;
179 
180 private:
181  nsresult EnsureLastQueryParameter(PRUint32 aParamIndex);
182 };
183 
184 #endif // __DATABASE_QUERY_H__
185 
PRUint64 m_RollingLimit
ParameterType type
std::vector< CQueryParameter > bindParameterArray_t
std::deque< bindParameterArray_t > m_BindParameters
ParameterType
Definition: DatabaseQuery.h:75
Songbird Database Object Definition.
PRBool m_QueryHasCompleted
[USER CODE SHOULD NOT REFERENCE THIS CLASS]
nsCString m_LocationURIString
PRUint32 m_CurrentQuery
NS_DECL_ISUPPORTS NS_DECL_SBIDATABASEQUERY NS_DECL_NSICLASSINFO nsresult Init()
nsresult GetDatabaseLocation(nsACString &aURISpec)
friend class QueryProcessorThread
virtual ~CDatabaseQuery()
PRMonitor * m_pQueryRunningMonitor
bindParameterArray_t * GetQueryParameters(PRUint32 aQueryIndex)
void SetResultObject(CDatabaseResult *aResultObject)
nsRefPtr< CDatabaseResult > m_QueryResult
nsCString utf8StringValue
nsresult PopQuery(sbIDatabasePreparedStatement **_retval)
nsString m_DatabaseGUID
nsInterfaceHashtableMT< nsISupportsHashKey, sbIDatabaseSimpleQueryCallback > m_CallbackList
PRBool m_IsExecuting
PRLock * m_pLock
nsString stringValue
nsCOMPtr< sbIDatabaseEngine > mDatabaseEngine
PRUint32 m_RollingLimitColumnIndex
An object responsible for executing SQL queries on the database.
PRUint32 m_RollingLimitResult
std::deque< nsCOMPtr< sbIDatabasePreparedStatement > > m_DatabaseQueryList
CQueryParameter(const CQueryParameter &queryParameter)
Definition: DatabaseQuery.h:96
PRInt32 m_LastError
CDatabaseResult * GetResultObject()
A prepared database statement.
bindParameterArray_t * PopQueryParameters()