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

Unified Diff: installer/src/installer-lib/database.cpp

Issue 22887001: Custom action library, initial version (Closed)
Patch Set: Created Oct. 28, 2013, 9:37 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: installer/src/installer-lib/database.cpp
===================================================================
new file mode 100644
--- /dev/null
+++ b/installer/src/installer-lib/database.cpp
@@ -0,0 +1,58 @@
+/**
+ * \file database.h MSI database
+ */
+
+#include "database.h"
+#include "msiquery.h"
+
+//-----------------------------------------------------------------------------------------
+// Database
+//-----------------------------------------------------------------------------------------
+/**
+ * \par Implementation Notes
+ * An MSI database handle is an overloaded type, used both for installation databases and one opened outside an installation.
+ * Hence this base constructor initializes with that handle.
+ *
+ * \sa MSDN "Obtaining a Database Handle"
+ * http://msdn.microsoft.com/en-us/library/windows/desktop/aa370541(v=vs.85).aspx
+ */
+Database::Database( MSIHANDLE handle )
+ : handle( handle )
+{
+}
+
+Database::~Database()
+{
+ MsiCloseHandle( handle ) ;
+}
Wladimir Palant 2013/10/29 08:49:26 I cannot really imagine the situation where our cu
Eric 2013/10/29 14:00:58 Before I get into everything, let me start off by
Wladimir Palant 2013/10/29 15:06:38 Ok, I understand it that we will need a tool to ge
+
+//-----------------------------------------------------------------------------------------
+// Installation_Database
+//-----------------------------------------------------------------------------------------
+
+/**
+ * Helper function for Installation_Database constructor.
+ *
+ * \par Resource Allocator
+ * Return value of this function, a handle, must be released in order to avoid a resource leak.
+ * Passing it as an argument to the Database constructor is adequate.
+ */
+MSIHANDLE get_active_database( Immediate_Session & session )
+{
+ MSIHANDLE h = MsiGetActiveDatabase( session.handle ) ;
+ if ( h == 0 )
+ {
+ throw std::runtime_error( "Failed to retrieve active databases" ) ;
+ }
+ return h ;
+}
+
+/**
+ * \par Implementation Notes
+ * The only thing this constructor needs to do is to initialize the base class.
+ */
+Installation_Database::Installation_Database( Immediate_Session & session )
+ : Database( get_active_database( session ) )
+{
+ // empty body
+}

Powered by Google App Engine
This is Rietveld