1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent tw=79 ft=cpp: */
4 * Copyright (C) 2007,2008 Sergey Yanovich <ynvich@gmail.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #include "xpcom-config.h"
25 #include "nsComponentManagerUtils.h"
26 #include "nsIInterfaceRequestorUtils.h"
27 #include "nsStringAPI.h"
28 #include "nsXPCOMCID.h"
29 #include "nsIMutableArray.h"
30 #include "nsISupportsPrimitives.h"
33 #include "nsIInterfaceRequestorUtils.h"
35 /* Project includes */
37 #include "aaIHandler.h"
39 #include "aaLoadQuote.h"
41 #include "aaISqlFilter.h"
42 #include "aaIColumnNameConverter.h"
43 #include "aaOrderCondition.h"
45 /**********************************************************/
46 class CQuoteNameConverter
: public aaIColumnNameConverter
49 CQuoteNameConverter() {}
50 ~CQuoteNameConverter() {}
52 NS_IMETHOD_(nsCAutoString
) convertName(const nsACString
& name
) const {
53 if (name
.Equals(NS_LITERAL_CSTRING("quote.tag"))) {
54 return NS_LITERAL_CSTRING("money.alpha_code");
55 } else if (name
.Equals(NS_LITERAL_CSTRING("quote.date"))) {
56 return NS_LITERAL_CSTRING("quote.day");
57 } else if (name
.Equals(NS_LITERAL_CSTRING("quote.rate"))) {
58 return NS_LITERAL_CSTRING("quote.rate");
60 return nsCAutoString();
63 /**********************************************************/
65 #ifndef AA_LOADQUOTE_SELECT_QUERY
66 #define AA_LOADQUOTE_SELECT_QUERY "SELECT\
69 strftime('%s',quote.day),\
73 MAX(quote.day) AS latest_day,\
74 quote.resource_id AS q_resource_id\
78 IFNULL(quote.resource_id = ?, 1)\
82 q_resource_id=quote.resource_id\
83 AND quote.day=latest_day\
85 money.id=quote.resource_id"
88 #define AA_LOADQUOTE_SELECT_QUERY_FILTERED \
89 AA_LOADQUOTE_SELECT_QUERY AA_SQL_WHERE_FILTER_MARK AA_SQL_ORDER_MARK
91 static struct aaLoadRequest::ColumnMap map
[] = {
93 ,{"money.alpha_code", 1}
100 aaLoadQuote::aaLoadQuote()
102 mSql
= AA_LOADQUOTE_SELECT_QUERY
;
103 mSqlFiltered
= AA_LOADQUOTE_SELECT_QUERY_FILTERED
;
107 NS_IMPL_ISUPPORTS_INHERITED0(aaLoadQuote
,
112 aaLoadQuote::GetParams(nsIArray
* * aParams
)
115 nsCOMPtr
<nsIMutableArray
> result
116 = do_CreateInstance(NS_ARRAY_CONTRACTID
, &rv
);
117 NS_ENSURE_SUCCESS(rv
, rv
);
119 nsCOMPtr
<nsISupportsPRInt64
> valInt64
;
122 nsCOMPtr
<aaIMoney
> money
= do_QueryInterface(mFilter
, &rv
);
124 money
= do_GetInterface(mFilter
, &rv
);
125 if (NS_NOINTERFACE
== rv
) {
126 rv
= result
->InsertElementAt(nsnull
, 0, PR_FALSE
);
127 NS_ENSURE_SUCCESS(rv
, rv
);
134 NS_ENSURE_SUCCESS(rv
, rv
);
136 valInt64
= do_CreateInstance(NS_SUPPORTS_PRINT64_CONTRACTID
, &rv
);
137 NS_ENSURE_SUCCESS(rv
, rv
);
138 rv
= valInt64
->SetData(money
->PickId());
139 NS_ENSURE_SUCCESS(rv
, rv
);
140 rv
= result
->InsertElementAt(valInt64
, 0, PR_FALSE
);
141 NS_ENSURE_SUCCESS(rv
, rv
);
144 rv
= result
->InsertElementAt(nsnull
, 0, PR_FALSE
);
145 NS_ENSURE_SUCCESS(rv
, rv
);
156 aaLoadQuote::Accept(aaIHandler
*aQuery
)
158 return aQuery
->HandleQuote(nsnull
);
162 aaLoadQuote::GetCondition(aaICondition
* pCondition
, nsACString
& aSql
)
165 CQuoteNameConverter cnvrt
;
166 NS_ENSURE_ARG_POINTER(pCondition
);
170 pCondition
->ToString(&cnvrt
, aSql
);