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) 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 "nsXPCOMCID.h"
27 #include "nsIMutableArray.h"
28 #include "nsISupportsPrimitives.h"
32 /* Project includes */
33 #include "aaAmountUtils.h"
37 #include "aaFactSideInsert.h"
39 static const char *sql
=
40 "INSERT INTO fact (day, event_id, transfer_id, side, flow_id)\
41 VALUES ((replace(round(julianday(?,'unixepoch')),'.0','')),?,?,?,?)";
43 aaFactSideInsert::aaFactSideInsert()
48 NS_IMPL_ISUPPORTS_INHERITED0(aaFactSideInsert
,
53 aaFactSideInsert::SetFilter(nsISupports
* aFilter
)
56 mState
= do_QueryInterface(aFilter
, &rv
);
57 NS_ENSURE_SUCCESS(rv
, rv
);
63 aaFactSideInsert::GetParams(nsIArray
* * aParams
)
65 NS_ENSURE_TRUE(mStatement
, NS_ERROR_NOT_INITIALIZED
);
66 NS_ENSURE_TRUE(mState
, NS_ERROR_NOT_INITIALIZED
);
67 NS_ENSURE_TRUE(mState
->PickFlow() && mState
->PickFlow()->PickId(),
68 NS_ERROR_INVALID_ARG
);
71 PRInt64 eventId
, factId
;
74 rv
= mState
->GetEventId(&eventId
);
75 NS_ENSURE_SUCCESS(rv
, rv
);
77 rv
= mState
->GetFactId(&factId
);
78 NS_ENSURE_SUCCESS(rv
, rv
);
80 rv
= mState
->GetFactSide(&factSide
);
81 NS_ENSURE_SUCCESS(rv
, rv
);
83 nsCOMPtr
<nsIMutableArray
> result
84 = do_CreateInstance(NS_ARRAY_CONTRACTID
, &rv
);
85 NS_ENSURE_SUCCESS(rv
, rv
);
87 nsCOMPtr
<nsISupportsPRInt64
> valInt64
;
88 nsCOMPtr
<nsISupportsPRInt32
> valInt32
;
90 valInt64
= do_CreateInstance(NS_SUPPORTS_PRINT64_CONTRACTID
, &rv
);
91 NS_ENSURE_SUCCESS(rv
, rv
);
92 rv
= valInt64
->SetData(mState
->PickStart() / 1000000);
93 NS_ENSURE_SUCCESS(rv
, rv
);
94 rv
= result
->InsertElementAt(valInt64
, 0, PR_FALSE
);
95 NS_ENSURE_SUCCESS(rv
, rv
);
97 valInt64
= do_CreateInstance(NS_SUPPORTS_PRINT64_CONTRACTID
, &rv
);
98 NS_ENSURE_SUCCESS(rv
, rv
);
99 rv
= valInt64
->SetData(eventId
);
100 NS_ENSURE_SUCCESS(rv
, rv
);
101 rv
= result
->InsertElementAt(valInt64
, 1, PR_FALSE
);
102 NS_ENSURE_SUCCESS(rv
, rv
);
104 valInt64
= do_CreateInstance(NS_SUPPORTS_PRINT64_CONTRACTID
, &rv
);
105 NS_ENSURE_SUCCESS(rv
, rv
);
106 rv
= valInt64
->SetData(factId
);
107 NS_ENSURE_SUCCESS(rv
, rv
);
108 rv
= result
->InsertElementAt(valInt64
, 2, PR_FALSE
);
109 NS_ENSURE_SUCCESS(rv
, rv
);
111 valInt32
= do_CreateInstance(NS_SUPPORTS_PRINT32_CONTRACTID
, &rv
);
112 NS_ENSURE_SUCCESS(rv
, rv
);
113 rv
= valInt32
->SetData(factSide
);
114 NS_ENSURE_SUCCESS(rv
, rv
);
115 rv
= result
->InsertElementAt(valInt32
, 3, PR_FALSE
);
116 NS_ENSURE_SUCCESS(rv
, rv
);
118 valInt64
= do_CreateInstance(NS_SUPPORTS_PRINT64_CONTRACTID
, &rv
);
119 NS_ENSURE_SUCCESS(rv
, rv
);
120 rv
= valInt64
->SetData(mState
->PickFlow()->PickId());
121 NS_ENSURE_SUCCESS(rv
, rv
);
122 rv
= result
->InsertElementAt(valInt64
, 4, PR_FALSE
);
123 NS_ENSURE_SUCCESS(rv
, rv
);