|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "sqldbtransaction.h" |
|
17 |
|
18 /** |
|
19 Stanadard factory construction method |
|
20 */ |
|
21 MDBTransaction* CSqlDbTransaction::NewL ( RSqlDatabase& aDb, const TDesC8& aQueryStmt ) |
|
22 { |
|
23 CSqlDbTransaction* self = new ( ELeave )CSqlDbTransaction (); |
|
24 CleanupStack::PushL ( self ); |
|
25 self->ConstructL ( aDb, aQueryStmt ); |
|
26 CleanupStack::Pop (); // self |
|
27 |
|
28 return self; |
|
29 } |
|
30 |
|
31 CSqlDbTransaction::~CSqlDbTransaction () |
|
32 { |
|
33 iStatement.Close (); |
|
34 } |
|
35 |
|
36 CSqlDbTransaction::CSqlDbTransaction ( ) |
|
37 { |
|
38 |
|
39 } |
|
40 |
|
41 void CSqlDbTransaction::ConstructL ( RSqlDatabase& aDb, const TDesC8& aQueryStmt ) |
|
42 { |
|
43 iStatement.PrepareL ( aDb, aQueryStmt ); |
|
44 } |
|
45 |
|
46 /** |
|
47 Binds the text value with the SQL statement |
|
48 */ |
|
49 void CSqlDbTransaction::BindTextL ( TInt aParamPos, const TDesC8& aParamValue ) |
|
50 { |
|
51 User::LeaveIfError ( iStatement.BindBinary ( aParamPos, aParamValue ) ); |
|
52 } |
|
53 |
|
54 /** |
|
55 Binds the int value with the SQL statement |
|
56 */ |
|
57 void CSqlDbTransaction::BindIntL ( TInt aParamPos, TInt aParamValue ) |
|
58 { |
|
59 User::LeaveIfError ( iStatement.BindInt ( aParamPos, aParamValue ) ); |
|
60 } |
|
61 |
|
62 /** |
|
63 Executes the SQL statement. Leaves incase of an error. Otherwise returns with |
|
64 the number of records changed during a INSERT, UPDATE or DELETE operation |
|
65 */ |
|
66 TInt CSqlDbTransaction::ExecuteL () |
|
67 { |
|
68 TInt ret = iStatement.Exec (); |
|
69 User::LeaveIfError ( ret ); |
|
70 return ret; |
|
71 } |
|
72 |
|
73 /** |
|
74 Returns the column text value from the result set, given the field position |
|
75 */ |
|
76 TPtrC8 CSqlDbTransaction::ColumnTextL ( TInt aFieldPos ) |
|
77 { |
|
78 return iStatement.ColumnBinaryL ( aFieldPos ); |
|
79 } |
|
80 |
|
81 /** |
|
82 Returns the column integer value from the result set, given the field position |
|
83 */ |
|
84 TInt CSqlDbTransaction::ColumnIntL ( TInt aFieldPos ) |
|
85 { |
|
86 return iStatement.ColumnInt ( aFieldPos ); |
|
87 } |
|
88 |
|
89 /** |
|
90 Moves to the first or next record. Returns ETrue if there is a record otherwise returns |
|
91 EFalse |
|
92 */ |
|
93 TBool CSqlDbTransaction::Next () |
|
94 { |
|
95 return ( iStatement.Next() == KSqlAtRow ); |
|
96 } |
|
97 |
|
98 void CSqlDbTransaction::Release () |
|
99 { |
|
100 delete this; |
|
101 } |
|
102 |