1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
#include "precomp.h"
// prototypes
static HRESULT ConfigureSqlData(
__in SCA_ACTION saAction
);
/********************************************************************
InstallSqlData - CUSTOM ACTION ENTRY POINT for installing
SQL data
********************************************************************/
extern "C" UINT __stdcall InstallSqlData(
__in MSIHANDLE hInstall
)
{
HRESULT hr = S_OK;
UINT er = ERROR_SUCCESS;
// initialize
hr = WcaInitialize(hInstall, "InstallSqlData");
ExitOnFailure(hr, "Failed to initialize");
hr = ConfigureSqlData(SCA_ACTION_INSTALL);
LExit:
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
return WcaFinalize(er);
}
/********************************************************************
UninstallSqlData - CUSTOM ACTION ENTRY POINT for uninstalling
SQL data
********************************************************************/
extern "C" UINT __stdcall UninstallSqlData(
__in MSIHANDLE hInstall
)
{
HRESULT hr = S_OK;
UINT er = ERROR_SUCCESS;
// initialize
hr = WcaInitialize(hInstall, "UninstallSqlData");
ExitOnFailure(hr, "Failed to initialize");
hr = ConfigureSqlData(SCA_ACTION_UNINSTALL);
LExit:
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
return WcaFinalize(er);
}
static HRESULT ConfigureSqlData(
__in SCA_ACTION saAction
)
{
//AssertSz(FALSE, "debug ConfigureSqlData()");
HRESULT hr = S_OK;
SCA_DB* psdList = NULL;
SCA_SQLSTR* psssList = NULL;
// check for the prerequsite tables
if (S_OK != WcaTableExists(L"Wix4SqlDatabase"))
{
WcaLog(LOGMSG_VERBOSE, "skipping SQL CustomAction, no Wix4SqlDatabase table");
ExitFunction1(hr = S_FALSE);
}
// read tables
hr = ScaDbsRead(&psdList, saAction);
ExitOnFailure(hr, "failed to read Wix4SqlDatabase table");
hr = ScaSqlStrsRead(&psssList, saAction);
ExitOnFailure(hr, "failed to read Wix4SqlString table");
hr = ScaSqlStrsReadScripts(&psssList, saAction);
ExitOnFailure(hr, "failed to read Wix4SqlScript table");
if (SCA_ACTION_UNINSTALL == saAction)
{
// do uninstall actions (order is important!)
hr = ScaSqlStrsUninstall(psdList, psssList);
ExitOnFailure(hr, "failed to execute uninstall SQL strings");
hr = ScaDbsUninstall(psdList);
ExitOnFailure(hr, "failed to uninstall databases");
}
else
{
// do install actions (order is important!)
hr = ScaDbsInstall(psdList);
ExitOnFailure(hr, "failed to install databases");
hr = ScaSqlStrsInstall(psdList, psssList);
ExitOnFailure(hr, "failed to execute install SQL strings, length may be too long, try add GO to break up");
}
LExit:
if (psssList)
ScaSqlStrsFreeList(psssList);
if (psdList)
ScaDbsFreeList(psdList);
return hr;
}
|