|
1 // Copyright (c) 2005-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 #ifndef __SQLSRVFILEDATA_H__ |
|
17 #define __SQLSRVFILEDATA_H__ |
|
18 |
|
19 #include <f32file.h> //TParse, RFs |
|
20 #include "SqlSrvStrings.h" //KFileHandleSeparator |
|
21 #include "SqlSrvConfig.h" //TSqlSrvConfig & TSqlSrvConfigParams |
|
22 |
|
23 |
|
24 /** |
|
25 TSqlSrvFileData class. |
|
26 |
|
27 TSqlSrvFileData class owns two sets of data: |
|
28 - data, which never changes during the life time of TSqlSrvFileData object - file session instance, |
|
29 system drive name, SQL server private data path, config file parameters, a store of names of existing |
|
30 database configuration files. These permanent TSqlSrvFileData properties are initialized by calling |
|
31 TSqlSrvFileData::InitL(). |
|
32 The SQL server owns only one TSqlSrvFileData instance whose permanent properties are initialized during |
|
33 the server startup and that TSqlSrvFileData instance is available to the other SQL server classes |
|
34 via a call to CSqServer::FileData(); |
|
35 - data, which changes with every call to TSqlSrvFileData::SetL(const RMessage2& aMessage, TInt aArgNum). |
|
36 The TSqlSrvFileData instance expects that argument aArgNum of aMessage object contains a file name. |
|
37 The file name will be parsed by the TSqlSrvFileData instance and then the full file name is made available |
|
38 through TSqlSrvFileData::FileName() and TSqlSrvFileData::FileNameZ() (zero-terminated file name); |
|
39 |
|
40 The TSqlSrvFileData instance also can be used for (after calling TSqlSrvFileData::SetL() or TSqlSrvFileData::SetFromHandleL()): |
|
41 - retrieving the full file name; |
|
42 - retrieving the system drive name; |
|
43 - retrieving the server private path; |
|
44 - checking the file name format type - secure or non-secure; |
|
45 - retrieving the SID of the file name, if that is a secure file name; |
|
46 |
|
47 With TSqlSrvFileData class we can: |
|
48 - Minimize the stack usage (there is only one, heap based TSqlSrvFileData instance, owned by the SQL server); |
|
49 - Keep in one place all data needed for opening/creating/attaching/copying/deleting a database file; |
|
50 |
|
51 @see CSqlServer |
|
52 @see CSqlServer::FileData() |
|
53 @see TSqlSrvFileData::SetL() |
|
54 @see TSqlSrvFileData::SetFromHandleL() |
|
55 @see TSqlSrvFileData::Fs() |
|
56 @see TSqlSrvFileData::PrivatePath() |
|
57 @see TSqlSrvFileData::Drive() |
|
58 @see TSqlSrvFileData::FileName() |
|
59 @see TSqlSrvFileData::FileNameZ() |
|
60 @see TSqlSrvFileData::IsSecureFileNameFmt() |
|
61 @see TSqlSrvFileData::SecureUid() |
|
62 @see TSqlSrvFileData::IsCreated() |
|
63 @see TSqlSrvFileData::IsReadOnly() |
|
64 @see TSqlSrvFileData::ContainHandles() |
|
65 @see TSqlSrvFileData::ConfigParams() |
|
66 @see TSqlSrvFileData::DbConfigFiles() |
|
67 |
|
68 @internalComponent |
|
69 */ |
|
70 NONSHARABLE_CLASS(TSqlSrvFileData) |
|
71 { |
|
72 public: |
|
73 inline void InitL(RFs& aFs, const TDriveName& aSysDriveName, const TDesC& aServerPrivatePath, |
|
74 const TDesC& aConfigFileName, const CDbConfigFiles* aDbConfigFiles); |
|
75 void SetL(const RMessage2& aMessage, TInt aFileNameLen, TInt aFileNameArgNum, const TDesC8* aConfigStr = NULL); |
|
76 void SetFromHandleL(const RMessage2& aMessage, const TDesC& aDbFileName, TBool aCreated, TBool aReadOnly, const TDesC8* aConfigStr = NULL); |
|
77 |
|
78 inline RFs& Fs() const; |
|
79 inline TPtrC PrivatePath() const; |
|
80 inline TDriveNumber Drive() const; |
|
81 inline TPtrC FileName() const; |
|
82 inline TPtrC FileNameZ() const; |
|
83 inline TBool IsSecureFileNameFmt() const; |
|
84 inline TUid SecureUid() const; |
|
85 inline TBool IsCreated() const; |
|
86 inline TBool IsReadOnly() const; |
|
87 inline TBool ContainHandles() const; |
|
88 inline const TSqlSrvConfigParams& ConfigParams() const; |
|
89 inline const CDbConfigFiles* DbConfigFiles() const; |
|
90 |
|
91 private: |
|
92 RFs iFs; |
|
93 TParse iSysDrivePrivatePath;// <System drive name> + <Private directory> |
|
94 TSqlSrvConfig iConfig; // Contains the config file parameters (not used directly. TSqlSrvConfig::GetConfigParamsL() |
|
95 // should be used to get the right set of configuration parameters) |
|
96 TBuf<KMaxFileName + 1> iFileName; |
|
97 TDriveNumber iDrive; |
|
98 TBool iIsSecureFileNameFmt; |
|
99 TUid iSecureUid; |
|
100 TBool iCreated; // If the file is a private database, iCreated is true if the file was created, |
|
101 // false if the file was opened by the client side |
|
102 TBool iReadOnly; |
|
103 TSqlSrvConfigParams iConfigParams; // Contains the configuration parameters, which shall be used |
|
104 // for the database connection (when creating/openning) |
|
105 const CDbConfigFiles* iDbConfigFilesPtr; // Pointer to server's store of existing database config file names, NULL if there are no config files |
|
106 }; |
|
107 |
|
108 /** |
|
109 Initializes the permanent data of TSqlSrvFileData instance. |
|
110 This type of initialization happens during the SQL server startup. |
|
111 Once initialized, the permanent set of data stays unchanged for the whole life time of TSqlSrvFileData instance. |
|
112 |
|
113 @code |
|
114 The permanent set of data includes: |
|
115 - a file session instance; |
|
116 - system drive name; |
|
117 - SQL server private data path; |
|
118 - config file parameters; |
|
119 - a store of names of existing database configuration files |
|
120 @endcode |
|
121 |
|
122 @param aFs A reference to a file session instance |
|
123 @param aSysDriveName A reference to the system drive name |
|
124 @param aServerPrivatePath A reference to SQL server private data path |
|
125 @param aConfigFileName SQL server configuration file name |
|
126 @param aDbConfigFiles A pointer to the server's store of existing database configuration file names |
|
127 */ |
|
128 inline void TSqlSrvFileData::InitL(RFs& aFs, const TDriveName& aSysDriveName, const TDesC& aServerPrivatePath, |
|
129 const TDesC& aConfigFileName, const CDbConfigFiles* aDbConfigFiles) |
|
130 { |
|
131 iFs = aFs; |
|
132 iSysDrivePrivatePath.Set(aSysDriveName, &aServerPrivatePath, 0); |
|
133 iConfig.InitL(aFs, aConfigFileName); |
|
134 iConfig.GetConfigParamsL(KNullDesC8, iConfigParams);//iConfigParams initialized with the config file params |
|
135 //(because an empty configuration string is passed as an argument) |
|
136 iDbConfigFilesPtr = aDbConfigFiles; |
|
137 } |
|
138 |
|
139 /** |
|
140 @return A reference to the file session instance |
|
141 */ |
|
142 inline RFs& TSqlSrvFileData::Fs() const |
|
143 { |
|
144 return const_cast <RFs&> (iFs); |
|
145 } |
|
146 |
|
147 /** |
|
148 @return SQL server private path. |
|
149 */ |
|
150 inline TPtrC TSqlSrvFileData::PrivatePath() const |
|
151 { |
|
152 return iSysDrivePrivatePath.Path(); |
|
153 } |
|
154 |
|
155 /** |
|
156 @return The file drive. |
|
157 */ |
|
158 inline TDriveNumber TSqlSrvFileData::Drive() const |
|
159 { |
|
160 return iDrive; |
|
161 } |
|
162 |
|
163 /** |
|
164 @return A read-only descriptor pointing to the file name. |
|
165 */ |
|
166 inline TPtrC TSqlSrvFileData::FileName() const |
|
167 { |
|
168 return iFileName.Left(iFileName.Length() - 1); |
|
169 } |
|
170 |
|
171 /** |
|
172 @return A read-only descriptor pointing to the file name, zero-terminated. |
|
173 */ |
|
174 inline TPtrC TSqlSrvFileData::FileNameZ() const |
|
175 { |
|
176 return iFileName; |
|
177 } |
|
178 |
|
179 /** |
|
180 @return True if the file name format refers to a secure file name. |
|
181 */ |
|
182 inline TBool TSqlSrvFileData::IsSecureFileNameFmt() const |
|
183 { |
|
184 return iIsSecureFileNameFmt; |
|
185 } |
|
186 |
|
187 /** |
|
188 @return The secure UID, if the file name is a secure file name, KNullUid otherwise. |
|
189 */ |
|
190 inline TUid TSqlSrvFileData::SecureUid() const |
|
191 { |
|
192 return iSecureUid; |
|
193 } |
|
194 |
|
195 /** |
|
196 Returns true if the file was created, false if the file was opened by the client side. |
|
197 This function should be used only for private databases, e.g. for which ContainHandles() returns true. |
|
198 @return True if the file was created, false if the file was opened by the client side. |
|
199 |
|
200 @see TSqlSrvFileData::ContainHandles() |
|
201 */ |
|
202 inline TBool TSqlSrvFileData::IsCreated() const |
|
203 { |
|
204 return iCreated; |
|
205 } |
|
206 |
|
207 /** |
|
208 @return True if the file is a read-only file. |
|
209 */ |
|
210 inline TBool TSqlSrvFileData::IsReadOnly() const |
|
211 { |
|
212 return iReadOnly; |
|
213 } |
|
214 |
|
215 /** |
|
216 @return True if the file name contains file and session handles |
|
217 */ |
|
218 inline TBool TSqlSrvFileData::ContainHandles() const |
|
219 { |
|
220 return iFileName[0] == KFileHandleSeparator; |
|
221 } |
|
222 |
|
223 /** |
|
224 @return A reference to the configuration parameters. |
|
225 */ |
|
226 inline const TSqlSrvConfigParams& TSqlSrvFileData::ConfigParams() const |
|
227 { |
|
228 return iConfigParams; |
|
229 } |
|
230 |
|
231 /** |
|
232 @return A pointer to the server's store of existing database configuration file names |
|
233 (will be NULL if there are no existing configuration files) |
|
234 */ |
|
235 inline const CDbConfigFiles* TSqlSrvFileData::DbConfigFiles() const |
|
236 { |
|
237 return iDbConfigFilesPtr; |
|
238 } |
|
239 |
|
240 #endif//__SQLSRVFILEDATA_H__ |