Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: installer/src/installer-lib/database.cpp

Issue 6197445574787072: Cleaned up CA exceptions. Integrated free-standing handle class. (Closed)
Patch Set: Created March 30, 2014, 7:43 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /** 1 /**
2 * \file database.h MSI database 2 * \file database.h MSI database
3 */ 3 */
4 4
5 #include "database.h" 5 #include "database.h"
6 #include "msiquery.h" 6 #include "msiquery.h"
7 7
8 //------------------------------------------------------------------------------ ----------- 8 //------------------------------------------------------------------------------ -----------
9 // Database 9 // Database
10 //------------------------------------------------------------------------------ ----------- 10 //------------------------------------------------------------------------------ -----------
11 msi_handle Database::open_view( const wchar_t * query ) 11 msi_handle Database::open_view( const wchar_t * query )
12 { 12 {
13 MSIHANDLE view_handle ; 13 MSIHANDLE view_handle ;
14 UINT x = MsiDatabaseOpenView( handle, query, & view_handle ) ; 14 UINT x = MsiDatabaseOpenView( handle, query, & view_handle ) ;
15 if ( x == ERROR_BAD_QUERY_SYNTAX ) 15 if ( x == ERROR_BAD_QUERY_SYNTAX )
16 { 16 {
17 throw std::runtime_error( "Bad MSI query syntax" ) ; 17 throw windows_api_error( "MsiDatabaseOpenView", "ERROR_BAD_QUERY_SYNTAX" ) ;
18 } 18 }
19 else if ( x == ERROR_INVALID_HANDLE ) 19 else if ( x == ERROR_INVALID_HANDLE )
20 { 20 {
21 throw std::runtime_error( "Invalid handle" ) ; 21 throw windows_api_error( "MsiDatabaseOpenView", "ERROR_INVALID_HANDLE" ) ;
22 } 22 }
23 return msi_handle( view_handle ) ; 23 return msi_handle( view_handle ) ;
24 } 24 }
25 25
26 //------------------------------------------------------------------------------ ----------- 26 //------------------------------------------------------------------------------ -----------
27 // Installation_Database 27 // Installation_Database
28 //------------------------------------------------------------------------------ ----------- 28 //------------------------------------------------------------------------------ -----------
29 29
30 /** 30 /**
31 * Helper function for Installation_Database constructor. 31 * Helper function for Installation_Database constructor.
32 * 32 *
33 * \par Resource Allocator 33 * \par Resource Allocator
34 * Return value of this function, a handle, must be released in order to avoi d a resource leak. 34 * Return value of this function, a handle, must be released in order to avoi d a resource leak.
35 * Passing it as an argument to the Database constructor is adequate. 35 * Passing it as an argument to the Database constructor is adequate.
36 */ 36 */
37 msi_handle get_active_database( Immediate_Session & session ) 37 msi_handle get_active_database( Immediate_Session & session )
38 { 38 {
39 MSIHANDLE h( MsiGetActiveDatabase( session.handle ) ) ; 39 MSIHANDLE h( MsiGetActiveDatabase( session.handle ) ) ;
40 if ( h == 0 ) 40 if ( h == 0 )
41 { 41 {
42 throw std::runtime_error( "Failed to retrieve active databases" ) ; 42 throw windows_api_error( "MsiGetActiveDatabase", 0 ) ;
43 } 43 }
44 return msi_handle( h ) ; 44 return msi_handle( h ) ;
45 } 45 }
46 46
47 /** 47 /**
48 * \par Implementation Notes 48 * \par Implementation Notes
49 * The only thing this constructor needs to do is to initialize the base clas s. 49 * The only thing this constructor needs to do is to initialize the base clas s.
50 */ 50 */
51 Installation_Database::Installation_Database( Immediate_Session & session ) 51 Installation_Database::Installation_Database( Immediate_Session & session )
52 : Database( get_active_database( session ) ) 52 : Database( get_active_database( session ) )
53 { 53 {
54 // empty body 54 // empty body
55 } ; 55 } ;
56 56
57 //------------------------------------------------------------------------------ ----------- 57 //------------------------------------------------------------------------------ -----------
58 // View 58 // View
59 //------------------------------------------------------------------------------ ----------- 59 //------------------------------------------------------------------------------ -----------
60 /** 60 /**
61 * Implementation function for View::first(). 61 * Implementation function for View::first().
62 */ 62 */
63 void view_first_body( UINT x ) 63 void view_first_body( UINT x )
64 { 64 {
65 if ( x != ERROR_SUCCESS ) 65 if ( x != ERROR_SUCCESS )
66 { 66 {
67 throw std::runtime_error( "MsiViewExecute call failed" ) ; 67 throw windows_api_error( "MsiViewExecute", x ) ;
68 } 68 }
69 } 69 }
70 70
71 Record View::first() 71 Record View::first()
72 { 72 {
73 view_first_body( MsiViewExecute( _handle, 0 ) ) ; 73 view_first_body( MsiViewExecute( _handle, 0 ) ) ;
74 return next() ; 74 return next() ;
75 } 75 }
76 76
77 Record View::first( Record & arguments ) 77 Record View::first( Record & arguments )
78 { 78 {
79 view_first_body( MsiViewExecute( _handle, arguments._handle ) ) ; 79 view_first_body( MsiViewExecute( _handle, arguments._handle ) ) ;
80 return next() ; 80 return next() ;
81 } 81 }
82 82
83 Record View::next() 83 Record View::next()
84 { 84 {
85 MSIHANDLE h ; 85 MSIHANDLE h ;
86 UINT x = MsiViewFetch( _handle, & h ) ; 86 UINT x = MsiViewFetch( _handle, & h ) ;
87 if ( x == ERROR_NO_MORE_ITEMS ) 87 if ( x == ERROR_NO_MORE_ITEMS )
88 { 88 {
89 return Record( Record::null_t() ) ; 89 return Record( Record::null_t() ) ;
90 } 90 }
91 else if ( x == ERROR_SUCCESS ) 91 else if ( x == ERROR_SUCCESS )
92 { 92 {
93 return Record( msi_handle( h ) ) ; 93 return Record( msi_handle( h ) ) ;
94 } 94 }
95 throw std::runtime_error( "Error fetch record from view" ) ; 95 throw windows_api_error( "MsiViewFetch", x ) ;
96 } 96 }
97 97
OLDNEW

Powered by Google App Engine
This is Rietveld