sl@0: // Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #ifndef __SQLSRVFILEDATA_H__ sl@0: #define __SQLSRVFILEDATA_H__ sl@0: sl@0: #include //TParse, RFs sl@0: #include "SqlSrvStrings.h" //KFileHandleSeparator sl@0: #include "SqlSrvConfig.h" //TSqlSrvConfig & TSqlSrvConfigParams sl@0: sl@0: sl@0: /** sl@0: TSqlSrvFileData class. sl@0: sl@0: TSqlSrvFileData class owns two sets of data: sl@0: - data, which never changes during the life time of TSqlSrvFileData object - file session instance, sl@0: system drive name, SQL server private data path, config file parameters, a store of names of existing sl@0: database configuration files. These permanent TSqlSrvFileData properties are initialized by calling sl@0: TSqlSrvFileData::InitL(). sl@0: The SQL server owns only one TSqlSrvFileData instance whose permanent properties are initialized during sl@0: the server startup and that TSqlSrvFileData instance is available to the other SQL server classes sl@0: via a call to CSqServer::FileData(); sl@0: - data, which changes with every call to TSqlSrvFileData::SetL(const RMessage2& aMessage, TInt aArgNum). sl@0: The TSqlSrvFileData instance expects that argument aArgNum of aMessage object contains a file name. sl@0: The file name will be parsed by the TSqlSrvFileData instance and then the full file name is made available sl@0: through TSqlSrvFileData::FileName() and TSqlSrvFileData::FileNameZ() (zero-terminated file name); sl@0: sl@0: The TSqlSrvFileData instance also can be used for (after calling TSqlSrvFileData::SetL() or TSqlSrvFileData::SetFromHandleL()): sl@0: - retrieving the full file name; sl@0: - retrieving the system drive name; sl@0: - retrieving the server private path; sl@0: - checking the file name format type - secure or non-secure; sl@0: - retrieving the SID of the file name, if that is a secure file name; sl@0: sl@0: With TSqlSrvFileData class we can: sl@0: - Minimize the stack usage (there is only one, heap based TSqlSrvFileData instance, owned by the SQL server); sl@0: - Keep in one place all data needed for opening/creating/attaching/copying/deleting a database file; sl@0: sl@0: @see CSqlServer sl@0: @see CSqlServer::FileData() sl@0: @see TSqlSrvFileData::SetL() sl@0: @see TSqlSrvFileData::SetFromHandleL() sl@0: @see TSqlSrvFileData::Fs() sl@0: @see TSqlSrvFileData::PrivatePath() sl@0: @see TSqlSrvFileData::Drive() sl@0: @see TSqlSrvFileData::FileName() sl@0: @see TSqlSrvFileData::FileNameZ() sl@0: @see TSqlSrvFileData::IsSecureFileNameFmt() sl@0: @see TSqlSrvFileData::SecureUid() sl@0: @see TSqlSrvFileData::IsCreated() sl@0: @see TSqlSrvFileData::IsReadOnly() sl@0: @see TSqlSrvFileData::ContainHandles() sl@0: @see TSqlSrvFileData::ConfigParams() sl@0: @see TSqlSrvFileData::DbConfigFiles() sl@0: sl@0: @internalComponent sl@0: */ sl@0: NONSHARABLE_CLASS(TSqlSrvFileData) sl@0: { sl@0: public: sl@0: inline void InitL(RFs& aFs, const TDriveName& aSysDriveName, const TDesC& aServerPrivatePath, sl@0: const TDesC& aConfigFileName, const CDbConfigFiles* aDbConfigFiles); sl@0: void SetL(const RMessage2& aMessage, TInt aFileNameLen, TInt aFileNameArgNum, sl@0: #ifdef SQLSRV_STARTUP_TEST sl@0: const TDesC& aDbFileName, sl@0: #endif sl@0: const TDesC8* aConfigStr = NULL); sl@0: void SetFromHandleL(const RMessage2& aMessage, const TDesC& aDbFileName, TBool aCreated, TBool aReadOnly, const TDesC8* aConfigStr = NULL); sl@0: sl@0: inline RFs& Fs() const; sl@0: inline TPtrC PrivatePath() const; sl@0: inline TDriveNumber Drive() const; sl@0: inline TPtrC FileName() const; sl@0: inline TPtrC FileNameZ() const; sl@0: inline TBool IsSecureFileNameFmt() const; sl@0: inline TUid SecureUid() const; sl@0: inline TBool IsCreated() const; sl@0: inline TBool IsReadOnly() const; sl@0: inline TBool ContainHandles() const; sl@0: inline const TSqlSrvConfigParams& ConfigParams() const; sl@0: inline const CDbConfigFiles* DbConfigFiles() const; sl@0: sl@0: private: sl@0: RFs iFs; sl@0: TParse iSysDrivePrivatePath;// + sl@0: TSqlSrvConfig iConfig; // Contains the config file parameters (not used directly. TSqlSrvConfig::GetConfigParamsL() sl@0: // should be used to get the right set of configuration parameters) sl@0: TBuf iFileName; sl@0: TDriveNumber iDrive; sl@0: TBool iIsSecureFileNameFmt; sl@0: TUid iSecureUid; sl@0: TBool iCreated; // If the file is a private database, iCreated is true if the file was created, sl@0: // false if the file was opened by the client side sl@0: TBool iReadOnly; sl@0: TSqlSrvConfigParams iConfigParams; // Contains the configuration parameters, which shall be used sl@0: // for the database connection (when creating/openning) sl@0: const CDbConfigFiles* iDbConfigFilesPtr; // Pointer to server's store of existing database config file names, NULL if there are no config files sl@0: }; sl@0: sl@0: /** sl@0: Initializes the permanent data of TSqlSrvFileData instance. sl@0: This type of initialization happens during the SQL server startup. sl@0: Once initialized, the permanent set of data stays unchanged for the whole life time of TSqlSrvFileData instance. sl@0: sl@0: @code sl@0: The permanent set of data includes: sl@0: - a file session instance; sl@0: - system drive name; sl@0: - SQL server private data path; sl@0: - config file parameters; sl@0: - a store of names of existing database configuration files sl@0: @endcode sl@0: sl@0: @param aFs A reference to a file session instance sl@0: @param aSysDriveName A reference to the system drive name sl@0: @param aServerPrivatePath A reference to SQL server private data path sl@0: @param aConfigFileName SQL server configuration file name sl@0: @param aDbConfigFiles A pointer to the server's store of existing database configuration file names sl@0: */ sl@0: inline void TSqlSrvFileData::InitL(RFs& aFs, const TDriveName& aSysDriveName, const TDesC& aServerPrivatePath, sl@0: const TDesC& aConfigFileName, const CDbConfigFiles* aDbConfigFiles) sl@0: { sl@0: iFs = aFs; sl@0: __SQLLEAVE_IF_ERROR(iSysDrivePrivatePath.Set(aSysDriveName, &aServerPrivatePath, 0)); sl@0: iConfig.InitL(aFs, aConfigFileName); sl@0: iConfig.GetConfigParamsL(KNullDesC8, iConfigParams);//iConfigParams initialized with the config file params sl@0: //(because an empty configuration string is passed as an argument) sl@0: iDbConfigFilesPtr = aDbConfigFiles; sl@0: } sl@0: sl@0: /** sl@0: @return A reference to the file session instance sl@0: */ sl@0: inline RFs& TSqlSrvFileData::Fs() const sl@0: { sl@0: return const_cast (iFs); sl@0: } sl@0: sl@0: /** sl@0: @return SQL server private path. sl@0: */ sl@0: inline TPtrC TSqlSrvFileData::PrivatePath() const sl@0: { sl@0: return iSysDrivePrivatePath.Path(); sl@0: } sl@0: sl@0: /** sl@0: @return The file drive. sl@0: */ sl@0: inline TDriveNumber TSqlSrvFileData::Drive() const sl@0: { sl@0: return iDrive; sl@0: } sl@0: sl@0: /** sl@0: @return A read-only descriptor pointing to the file name. sl@0: */ sl@0: inline TPtrC TSqlSrvFileData::FileName() const sl@0: { sl@0: return iFileName.Left(iFileName.Length() - 1); sl@0: } sl@0: sl@0: /** sl@0: @return A read-only descriptor pointing to the file name, zero-terminated. sl@0: */ sl@0: inline TPtrC TSqlSrvFileData::FileNameZ() const sl@0: { sl@0: return iFileName; sl@0: } sl@0: sl@0: /** sl@0: @return True if the file name format refers to a secure file name. sl@0: */ sl@0: inline TBool TSqlSrvFileData::IsSecureFileNameFmt() const sl@0: { sl@0: return iIsSecureFileNameFmt; sl@0: } sl@0: sl@0: /** sl@0: @return The secure UID, if the file name is a secure file name, KNullUid otherwise. sl@0: */ sl@0: inline TUid TSqlSrvFileData::SecureUid() const sl@0: { sl@0: return iSecureUid; sl@0: } sl@0: sl@0: /** sl@0: Returns true if the file was created, false if the file was opened by the client side. sl@0: This function should be used only for private databases, e.g. for which ContainHandles() returns true. sl@0: @return True if the file was created, false if the file was opened by the client side. sl@0: sl@0: @see TSqlSrvFileData::ContainHandles() sl@0: */ sl@0: inline TBool TSqlSrvFileData::IsCreated() const sl@0: { sl@0: return iCreated; sl@0: } sl@0: sl@0: /** sl@0: @return True if the file is a read-only file. sl@0: */ sl@0: inline TBool TSqlSrvFileData::IsReadOnly() const sl@0: { sl@0: return iReadOnly; sl@0: } sl@0: sl@0: /** sl@0: @return True if the file name contains file and session handles sl@0: */ sl@0: inline TBool TSqlSrvFileData::ContainHandles() const sl@0: { sl@0: return iFileName[0] == KFileHandleSeparator; sl@0: } sl@0: sl@0: /** sl@0: @return A reference to the configuration parameters. sl@0: */ sl@0: inline const TSqlSrvConfigParams& TSqlSrvFileData::ConfigParams() const sl@0: { sl@0: return iConfigParams; sl@0: } sl@0: sl@0: /** sl@0: @return A pointer to the server's store of existing database configuration file names sl@0: (will be NULL if there are no existing configuration files) sl@0: */ sl@0: inline const CDbConfigFiles* TSqlSrvFileData::DbConfigFiles() const sl@0: { sl@0: return iDbConfigFilesPtr; sl@0: } sl@0: sl@0: #endif//__SQLSRVFILEDATA_H__