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"
34 #include "aaIBalance.h"
36 #include "aaBalanceUpdate.h"
38 static const char *sql
=
39 "UPDATE balance SET side = ?, amount = ?, value = ? WHERE id == ?";
41 aaBalanceUpdate::aaBalanceUpdate()
46 NS_IMPL_ISUPPORTS_INHERITED0(aaBalanceUpdate
,
51 aaBalanceUpdate::SetFilter(nsISupports
* aFilter
)
54 mBalance
= do_QueryInterface(aFilter
, &rv
);
55 NS_ENSURE_SUCCESS(rv
, rv
);
61 aaBalanceUpdate::GetParams(nsIArray
* * aParams
)
63 NS_ENSURE_TRUE(mStatement
, NS_ERROR_NOT_INITIALIZED
);
64 NS_ENSURE_TRUE(mBalance
, NS_ERROR_NOT_INITIALIZED
);
68 rv
= mBalance
->GetId(&id
);
69 NS_ENSURE_SUCCESS(rv
, rv
);
71 nsCOMPtr
<nsIMutableArray
> result
72 = do_CreateInstance(NS_ARRAY_CONTRACTID
, &rv
);
73 NS_ENSURE_SUCCESS(rv
, rv
);
75 nsCOMPtr
<nsISupportsPRInt64
> valInt64
;
76 nsCOMPtr
<nsISupportsPRInt32
> valInt32
;
77 nsCOMPtr
<nsISupportsDouble
> valDouble
;
79 valInt32
= do_CreateInstance(NS_SUPPORTS_PRINT32_CONTRACTID
, &rv
);
80 NS_ENSURE_SUCCESS(rv
, rv
);
81 rv
= valInt32
->SetData(mBalance
->PickSide());
82 NS_ENSURE_SUCCESS(rv
, rv
);
83 rv
= result
->InsertElementAt(valInt32
, 0, PR_FALSE
);
84 NS_ENSURE_SUCCESS(rv
, rv
);
86 valDouble
= do_CreateInstance(NS_SUPPORTS_DOUBLE_CONTRACTID
, &rv
);
87 NS_ENSURE_SUCCESS(rv
, rv
);
88 rv
= valDouble
->SetData(mBalance
->PickAmount());
89 NS_ENSURE_SUCCESS(rv
, rv
);
90 rv
= result
->InsertElementAt(valDouble
, 1, PR_FALSE
);
91 NS_ENSURE_SUCCESS(rv
, rv
);
93 valDouble
= do_CreateInstance(NS_SUPPORTS_DOUBLE_CONTRACTID
, &rv
);
94 NS_ENSURE_SUCCESS(rv
, rv
);
95 rv
= valDouble
->SetData(mBalance
->PickValue());
96 NS_ENSURE_SUCCESS(rv
, rv
);
97 rv
= result
->InsertElementAt(valDouble
, 2, PR_FALSE
);
98 NS_ENSURE_SUCCESS(rv
, rv
);
100 valInt64
= do_CreateInstance(NS_SUPPORTS_PRINT64_CONTRACTID
, &rv
);
101 NS_ENSURE_SUCCESS(rv
, rv
);
102 rv
= valInt64
->SetData(id
);
103 NS_ENSURE_SUCCESS(rv
, rv
);
104 rv
= result
->InsertElementAt(valInt64
, 3, PR_FALSE
);
105 NS_ENSURE_SUCCESS(rv
, rv
);