|
1 /** @file |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description : SQLite Connection class |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef UPNPSECURITYDBCONNECTION_H |
|
19 #define UPNPSECURITYDBCONNECTION_H |
|
20 |
|
21 // INCLUDES |
|
22 #include <e32base.h> |
|
23 #include <sqldb.h> |
|
24 #include <f32file.h> //TDriveNumber |
|
25 |
|
26 class TInetAddr; |
|
27 |
|
28 // CLASS DECLARATION |
|
29 |
|
30 /** |
|
31 * |
|
32 */ |
|
33 class CUpnpSecurityDbConnection : public CBase |
|
34 { |
|
35 |
|
36 public: |
|
37 |
|
38 /* Constructors and destructor. */ |
|
39 |
|
40 /** |
|
41 * Creates new CUpnpSecurityDbConnection class and initializes |
|
42 * connection to SQLite. |
|
43 * @return pointer to CUpnpSecurityDbConnection class |
|
44 */ |
|
45 static CUpnpSecurityDbConnection* NewL(); |
|
46 |
|
47 /** |
|
48 * Creates new CUpnpSecurityDbConnection class and initializes |
|
49 * connection to SQLite and |
|
50 * leaves the instance in the cleanup stack. |
|
51 * @return pointer to CUpnpSecurityDbConnection class |
|
52 */ |
|
53 static CUpnpSecurityDbConnection* NewLC(); |
|
54 |
|
55 /** |
|
56 * Destructor. |
|
57 */ |
|
58 virtual ~CUpnpSecurityDbConnection(); |
|
59 |
|
60 public: |
|
61 /** |
|
62 * Open database. |
|
63 */ |
|
64 TInt OpenDb( const TDesC& aDb ); |
|
65 |
|
66 /** |
|
67 * Close opened database |
|
68 */ |
|
69 void CloseDb(); |
|
70 |
|
71 /** |
|
72 * Creates db file. |
|
73 * @param aDb, Database filename and path |
|
74 * @return error code |
|
75 */ |
|
76 TInt CreateDbFile( const TDesC& aDb ); |
|
77 |
|
78 /** |
|
79 * Validates database existence and format. |
|
80 * |
|
81 * @return ETrue if db valid |
|
82 */ |
|
83 TBool Validate(); |
|
84 |
|
85 /** |
|
86 * Executes sql command. |
|
87 * |
|
88 * @param aCommand, command to be executed |
|
89 */ |
|
90 void ExecuteL( const TDesC8& aCommand ); |
|
91 |
|
92 /** |
|
93 * Create tables. |
|
94 */ |
|
95 void CreateTablesL(); |
|
96 |
|
97 /** |
|
98 * Add item (IP address) to DB. |
|
99 */ |
|
100 void AddIpAddressL( const TInetAddr& aIpAddress ); |
|
101 |
|
102 /** |
|
103 * Add item (file name) to DB. |
|
104 */ |
|
105 void AddFilenameL( const TDesC& aFilename ); |
|
106 |
|
107 /** |
|
108 * Delete item (IP address) from DB. |
|
109 */ |
|
110 void DeleteIpAddressL( const TInetAddr& aIpAddress ); |
|
111 |
|
112 /** |
|
113 * Delete item (file name) from DB. |
|
114 */ |
|
115 void DeleteFilenameL( const TDesC& aFilename ); |
|
116 |
|
117 /** |
|
118 * Delete all items (IP addresses) from DB. |
|
119 */ |
|
120 void DeleteAllIpAddressesL(); |
|
121 |
|
122 /** |
|
123 * Delete all items (file names) from DB. |
|
124 */ |
|
125 void DeleteAllFilenamesL(); |
|
126 |
|
127 /** |
|
128 * Retreive data from DB. |
|
129 */ |
|
130 void GetAllIpAddressesL( RArray<TInetAddr>& aAddressArray ); |
|
131 |
|
132 /** |
|
133 * Retreive data from DB. |
|
134 */ |
|
135 void GetAllFilenamesL( RPointerArray<HBufC>& aFilenameArray ); |
|
136 |
|
137 /** |
|
138 * Prepare database for use, create new if not exist. |
|
139 */ |
|
140 void OpenDatabaseL(); |
|
141 |
|
142 private: |
|
143 |
|
144 /** |
|
145 * Constructor. |
|
146 */ |
|
147 CUpnpSecurityDbConnection(); |
|
148 |
|
149 /** |
|
150 * Second-phase constructor. |
|
151 */ |
|
152 void ConstructL(); |
|
153 |
|
154 /** |
|
155 * Leaves if there is not enough disk space |
|
156 */ |
|
157 void EnsureDiskSpaceL(); |
|
158 |
|
159 /** |
|
160 * Returns drive where db files are stored |
|
161 */ |
|
162 TDriveNumber DatabaseDrive(); |
|
163 |
|
164 /** |
|
165 * Execute given db command |
|
166 * |
|
167 * @param aCommand command do execute |
|
168 * @param aType type of statement |
|
169 */ |
|
170 void ExecStatementL( const TDesC8& aCommand ); |
|
171 |
|
172 /** |
|
173 * Execute given db command |
|
174 * |
|
175 * @param aCommand command do execute |
|
176 * @param aTextToBind command text argument |
|
177 */ |
|
178 void ExecStatementL( const TDesC8& aCommand, const TDesC& aTextToBind ); |
|
179 |
|
180 /** |
|
181 * Execute given db command |
|
182 * |
|
183 * @param aCommand command do execute |
|
184 * @param aType command int argument |
|
185 */ |
|
186 void ExecStatementL( const TDesC8& aCommand, const TInt aIntToBind ); |
|
187 |
|
188 private: |
|
189 // data |
|
190 |
|
191 // iDatabase, interface to Sqlite database |
|
192 RSqlDatabase iDatabase; |
|
193 |
|
194 // database file name |
|
195 TFileName iDbFileName; |
|
196 |
|
197 // |
|
198 RFs iFs; |
|
199 |
|
200 }; |
|
201 |
|
202 #endif // UPNPSECURITYDBCONNECTION |
|
203 // End of File |