| OLD | NEW |
| 1 /** | 1 /** |
| 2 * \file database.h MSI database | 2 * \file database.h MSI database |
| 3 */ | 3 */ |
| 4 | 4 |
| 5 #ifndef DATABASE_H | 5 #ifndef DATABASE_H |
| 6 #define DATABASE_H | 6 #define DATABASE_H |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 * Roughly speaking, outside an installation the database supports both read and
write, | 29 * Roughly speaking, outside an installation the database supports both read and
write, |
| 30 * but inside an installation the database is read-only. | 30 * but inside an installation the database is read-only. |
| 31 * The life cycle functions are not shared, in addition. | 31 * The life cycle functions are not shared, in addition. |
| 32 * Outside of these restrictions, however, the API is mostly common. | 32 * Outside of these restrictions, however, the API is mostly common. |
| 33 * This class is the base class for the common API. | 33 * This class is the base class for the common API. |
| 34 * Subclasses provide public constructors and provide access to API calls not in
common. | 34 * Subclasses provide public constructors and provide access to API calls not in
common. |
| 35 */ | 35 */ |
| 36 class Database | 36 class Database |
| 37 { | 37 { |
| 38 protected: | 38 protected: |
| 39 typedef handle< MSIHANDLE, Disallow_Null, MSI_Generic_Destruction > handle_typ
e ; | 39 typedef Handle< MSIHANDLE, DisallowNull, GenericMsiDestruction > HandleType ; |
| 40 | 40 |
| 41 /** | 41 /** |
| 42 * Protected constructor. | 42 * Protected constructor. |
| 43 * | 43 * |
| 44 * An MSI database handle is an overloaded type, used both for installation dat
abases and one opened outside an installation. | 44 * An MSI database handle is an overloaded type, used both for installation dat
abases and one opened outside an installation. |
| 45 * These database handles, while both databases, have different capabilities an
d are thus defined in subclasses. | 45 * These database handles, while both databases, have different capabilities an
d are thus defined in subclasses. |
| 46 * Each subclass has the responsibility for obtaining a database handle appropr
iate to its circumstance. | 46 * Each subclass has the responsibility for obtaining a database handle appropr
iate to its circumstance. |
| 47 * | 47 * |
| 48 * \sa MSDN "Obtaining a Database Handle" | 48 * \sa MSDN "Obtaining a Database Handle" |
| 49 * http://msdn.microsoft.com/en-us/library/windows/desktop/aa370541(v=vs.85)
.aspx | 49 * http://msdn.microsoft.com/en-us/library/windows/desktop/aa370541(v=vs.85)
.aspx |
| 50 */ | 50 */ |
| 51 Database( MSIHANDLE handle ) | 51 Database( MSIHANDLE handle ) |
| 52 : handle( handle ) | 52 : handle( handle ) |
| 53 {} | 53 {} |
| 54 | 54 |
| 55 /** | 55 /** |
| 56 */ | 56 */ |
| 57 handle_type handle ; | 57 HandleType handle ; |
| 58 | 58 |
| 59 private: | 59 private: |
| 60 /** | 60 /** |
| 61 * Private copy constructor is declared but not defined. | 61 * Private copy constructor is declared but not defined. |
| 62 */ | 62 */ |
| 63 Database( const Database & ) ; | 63 Database( const Database & ) ; |
| 64 | 64 |
| 65 /** | 65 /** |
| 66 * Private assignment operator is declared but not defined. | 66 * Private assignment operator is declared but not defined. |
| 67 */ | 67 */ |
| 68 Database & operator=( const Database & ) ; | 68 Database & operator=( const Database & ) ; |
| 69 | 69 |
| 70 /** | 70 /** |
| 71 * Open a new view for this database. | 71 * Open a new view for this database. |
| 72 * | 72 * |
| 73 * \param query | 73 * \param query |
| 74 * An SQL query using the restricted MSI syntax | 74 * An SQL query using the restricted MSI syntax |
| 75 * | 75 * |
| 76 * \sa | 76 * \sa |
| 77 * - MSDN [MsiDatabaseOpenView function](http://msdn.microsoft.com/en-us/libr
ary/aa370082%28v=vs.85%29.aspx) | 77 * - MSDN [MsiDatabaseOpenView function](http://msdn.microsoft.com/en-us/libr
ary/aa370082%28v=vs.85%29.aspx) |
| 78 */ | 78 */ |
| 79 msi_handle open_view( const wchar_t * query ) ; | 79 MsiHandle OpenView( const wchar_t * query ) ; |
| 80 | 80 |
| 81 friend class View ; | 81 friend class View ; |
| 82 } ; | 82 } ; |
| 83 | 83 |
| 84 /** | 84 /** |
| 85 * A Windows Installer database in an installation context. | 85 * A Windows Installer database in an installation context. |
| 86 */ | 86 */ |
| 87 class InstallationDatabase : public Database | 87 class InstallationDatabase : public Database |
| 88 { | 88 { |
| 89 public: | 89 public: |
| 90 /** | 90 /** |
| 91 * The constructor of a database in an installation context has no arguments be
cause the database is a part of that context. | 91 * The constructor of a database in an installation context has no arguments be
cause the database is a part of that context. |
| 92 */ | 92 */ |
| 93 InstallationDatabase( ImmediateSession & session ) ; | 93 InstallationDatabase( ImmediateSession & session ) ; |
| 94 } ; | 94 } ; |
| 95 | 95 |
| 96 //------------------------------------------------------- | 96 //------------------------------------------------------- |
| 97 // | 97 // |
| 98 //------------------------------------------------------- | 98 //------------------------------------------------------- |
| 99 /** | 99 /** |
| 100 * A Windows Installer database outside of an installation context, opened as a f
ile from the file system. | 100 * A Windows Installer database outside of an installation context, opened as a f
ile from the file system. |
| 101 * | 101 * |
| 102 * This is a read-only version of a file-system database. | 102 * This is a read-only version of a file-system database. |
| 103 * Refactor the class to obtain other open-modes. | 103 * Refactor the class to obtain other open-modes. |
| 104 * | 104 * |
| 105 */ | 105 */ |
| 106 class File_System_Database : public Database | 106 class FileSystemDatabase : public Database |
| 107 { | 107 { |
| 108 /** | 108 /** |
| 109 * Open function is separate to enable initializing base class before construct
or body. | 109 * Open function is separate to enable initializing base class before construct
or body. |
| 110 * | 110 * |
| 111 * \sa | 111 * \sa |
| 112 * - MSDN [MsiOpenDatabase function](http://msdn.microsoft.com/en-us/library/
aa370338%28v=vs.85%29.aspx) | 112 * - MSDN [MsiOpenDatabase function](http://msdn.microsoft.com/en-us/library/
aa370338%28v=vs.85%29.aspx) |
| 113 */ | 113 */ |
| 114 msi_handle handle_from_pathname( const wchar_t * pathname ) | 114 MsiHandle HandleFromPathname( const wchar_t * pathname ) |
| 115 { | 115 { |
| 116 MSIHANDLE handle ; | 116 MSIHANDLE handle ; |
| 117 UINT x = MsiOpenDatabaseW( pathname, MSIDBOPEN_READONLY, & handle ) ; | 117 UINT x = MsiOpenDatabaseW( pathname, MSIDBOPEN_READONLY, & handle ) ; |
| 118 if ( x != ERROR_SUCCESS ) | 118 if ( x != ERROR_SUCCESS ) |
| 119 { | 119 { |
| 120 throw windows_api_error( "MsiOpenDatabaseW", x, "MSI database on file syst
em" ) ; | 120 throw WindowsApiError( "MsiOpenDatabaseW", x, "MSI database on file system
" ) ; |
| 121 } | 121 } |
| 122 return msi_handle( handle ) ; | 122 return MsiHandle( handle ) ; |
| 123 } | 123 } |
| 124 | 124 |
| 125 public: | 125 public: |
| 126 File_System_Database( const wchar_t * pathname ) | 126 FileSystemDatabase( const wchar_t * pathname ) |
| 127 : Database( handle_from_pathname( pathname ) ) | 127 : Database( HandleFromPathname( pathname ) ) |
| 128 {} | 128 {} |
| 129 } ; | 129 } ; |
| 130 | 130 |
| 131 //------------------------------------------------------- | 131 //------------------------------------------------------- |
| 132 // View | 132 // View |
| 133 //------------------------------------------------------- | 133 //------------------------------------------------------- |
| 134 /* | 134 /* |
| 135 * The MSI database is accessible through a cut-down version of SQL. | 135 * The MSI database is accessible through a cut-down version of SQL. |
| 136 * There's no distinction between view and query in this dialect. | 136 * There's no distinction between view and query in this dialect. |
| 137 * | 137 * |
| 138 * \sa | 138 * \sa |
| 139 * - MSDN [Working with Queries](http://msdn.microsoft.com/en-us/library/aa3728
79%28v=vs.85%29.aspx) | 139 * - MSDN [Working with Queries](http://msdn.microsoft.com/en-us/library/aa3728
79%28v=vs.85%29.aspx) |
| 140 */ | 140 */ |
| 141 class View | 141 class View |
| 142 { | 142 { |
| 143 typedef handle< MSIHANDLE, Disallow_Null, MSI_Generic_Destruction > handle_typ
e ; | 143 typedef Handle< MSIHANDLE, DisallowNull, GenericMsiDestruction > HandleType ; |
| 144 | 144 |
| 145 /** | 145 /** |
| 146 * Handle for the MSI view object | 146 * Handle for the MSI view object |
| 147 */ | 147 */ |
| 148 handle_type _handle; | 148 HandleType handle; |
| 149 | 149 |
| 150 public: | 150 public: |
| 151 /** | 151 /** |
| 152 * Ordinary constructor | 152 * Ordinary constructor |
| 153 */ | 153 */ |
| 154 View( Database & db, wchar_t * query ) | 154 View( Database & db, wchar_t * query ) |
| 155 : _handle( db.open_view( query ) ) | 155 : handle( db.OpenView( query ) ) |
| 156 {} | 156 {} |
| 157 | 157 |
| 158 /** | 158 /** |
| 159 * Execute the query and return the first record in its results. | 159 * Execute the query and return the first record in its results. |
| 160 * | 160 * |
| 161 * \param arguments | 161 * \param arguments |
| 162 * List of parameters to supply as the query arguments (question marks). | 162 * List of parameters to supply as the query arguments (question marks). |
| 163 */ | 163 */ |
| 164 Record first( Record & arguments ) ; | 164 Record First( Record & arguments ) ; |
| 165 | 165 |
| 166 /** | 166 /** |
| 167 * Execute the query and return the first record in its results. | 167 * Execute the query and return the first record in its results. |
| 168 * | 168 * |
| 169 * With no arguments, this version of the function may only be used with a quer
y that takes no arguments. | 169 * With no arguments, this version of the function may only be used with a quer
y that takes no arguments. |
| 170 */ | 170 */ |
| 171 Record first() ; | 171 Record First() ; |
| 172 | 172 |
| 173 /** | 173 /** |
| 174 * Retrieve the next record. | 174 * Retrieve the next record. |
| 175 */ | 175 */ |
| 176 Record next() ; | 176 Record Next() ; |
| 177 | 177 |
| 178 /** | 178 /** |
| 179 * End marker | 179 * End marker |
| 180 */ | 180 */ |
| 181 inline Record end() | 181 inline Record End() |
| 182 { | 182 { |
| 183 return Record( Record::null_t() ) ; | 183 return Record( Record::NullType() ) ; |
| 184 } | 184 } |
| 185 } ; | 185 } ; |
| 186 | 186 |
| 187 | 187 |
| 188 #endif | 188 #endif |
| OLD | NEW |