diff options
Diffstat (limited to 'src/ca/scasql.cpp')
| -rw-r--r-- | src/ca/scasql.cpp | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/src/ca/scasql.cpp b/src/ca/scasql.cpp new file mode 100644 index 00000000..5e3edd1c --- /dev/null +++ b/src/ca/scasql.cpp | |||
| @@ -0,0 +1,113 @@ | |||
| 1 | // 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. | ||
| 2 | |||
| 3 | #include "precomp.h" | ||
| 4 | |||
| 5 | // prototypes | ||
| 6 | static HRESULT ConfigureSqlData( | ||
| 7 | __in SCA_ACTION saAction | ||
| 8 | ); | ||
| 9 | |||
| 10 | |||
| 11 | /******************************************************************** | ||
| 12 | InstallSqlData - CUSTOM ACTION ENTRY POINT for installing | ||
| 13 | SQL data | ||
| 14 | |||
| 15 | ********************************************************************/ | ||
| 16 | extern "C" UINT __stdcall InstallSqlData( | ||
| 17 | __in MSIHANDLE hInstall | ||
| 18 | ) | ||
| 19 | { | ||
| 20 | HRESULT hr = S_OK; | ||
| 21 | UINT er = ERROR_SUCCESS; | ||
| 22 | |||
| 23 | // initialize | ||
| 24 | hr = WcaInitialize(hInstall, "InstallSqlData"); | ||
| 25 | ExitOnFailure(hr, "Failed to initialize"); | ||
| 26 | |||
| 27 | hr = ConfigureSqlData(SCA_ACTION_INSTALL); | ||
| 28 | |||
| 29 | LExit: | ||
| 30 | er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE; | ||
| 31 | return WcaFinalize(er); | ||
| 32 | } | ||
| 33 | |||
| 34 | |||
| 35 | /******************************************************************** | ||
| 36 | UninstallSqlData - CUSTOM ACTION ENTRY POINT for uninstalling | ||
| 37 | SQL data | ||
| 38 | |||
| 39 | ********************************************************************/ | ||
| 40 | extern "C" UINT __stdcall UninstallSqlData( | ||
| 41 | __in MSIHANDLE hInstall | ||
| 42 | ) | ||
| 43 | { | ||
| 44 | HRESULT hr = S_OK; | ||
| 45 | UINT er = ERROR_SUCCESS; | ||
| 46 | |||
| 47 | // initialize | ||
| 48 | hr = WcaInitialize(hInstall, "UninstallCertificates"); | ||
| 49 | ExitOnFailure(hr, "Failed to initialize"); | ||
| 50 | |||
| 51 | hr = ConfigureSqlData(SCA_ACTION_UNINSTALL); | ||
| 52 | |||
| 53 | LExit: | ||
| 54 | er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE; | ||
| 55 | return WcaFinalize(er); | ||
| 56 | } | ||
| 57 | |||
| 58 | |||
| 59 | static HRESULT ConfigureSqlData( | ||
| 60 | __in SCA_ACTION saAction | ||
| 61 | ) | ||
| 62 | { | ||
| 63 | //AssertSz(FALSE, "debug ConfigureSqlData()"); | ||
| 64 | HRESULT hr = S_OK; | ||
| 65 | |||
| 66 | SCA_DB* psdList = NULL; | ||
| 67 | SCA_SQLSTR* psssList = NULL; | ||
| 68 | |||
| 69 | // check for the prerequsite tables | ||
| 70 | if (S_OK != WcaTableExists(L"SqlDatabase")) | ||
| 71 | { | ||
| 72 | WcaLog(LOGMSG_VERBOSE, "skipping SQL CustomAction, no SqlDatabase table"); | ||
| 73 | ExitFunction1(hr = S_FALSE); | ||
| 74 | } | ||
| 75 | |||
| 76 | // read tables | ||
| 77 | hr = ScaDbsRead(&psdList, saAction); | ||
| 78 | ExitOnFailure(hr, "failed to read SqlDatabase table"); | ||
| 79 | |||
| 80 | hr = ScaSqlStrsRead(&psssList, saAction); | ||
| 81 | ExitOnFailure(hr, "failed to read SqlStrings table"); | ||
| 82 | |||
| 83 | hr = ScaSqlStrsReadScripts(&psssList, saAction); | ||
| 84 | ExitOnFailure(hr, "failed to read SqlScripts table"); | ||
| 85 | |||
| 86 | if (SCA_ACTION_UNINSTALL == saAction) | ||
| 87 | { | ||
| 88 | // do uninstall actions (order is important!) | ||
| 89 | hr = ScaSqlStrsUninstall(psdList, psssList); | ||
| 90 | ExitOnFailure(hr, "failed to execute uninstall SQL strings"); | ||
| 91 | |||
| 92 | hr = ScaDbsUninstall(psdList); | ||
| 93 | ExitOnFailure(hr, "failed to uninstall databases"); | ||
| 94 | } | ||
| 95 | else | ||
| 96 | { | ||
| 97 | // do install actions (order is important!) | ||
| 98 | hr = ScaDbsInstall(psdList); | ||
| 99 | ExitOnFailure(hr, "failed to install databases"); | ||
| 100 | |||
| 101 | hr = ScaSqlStrsInstall(psdList, psssList); | ||
| 102 | ExitOnFailure(hr, "failed to execute install SQL strings, length may be too long, try add GO to break up"); | ||
| 103 | } | ||
| 104 | |||
| 105 | LExit: | ||
| 106 | if (psssList) | ||
| 107 | ScaSqlStrsFreeList(psssList); | ||
| 108 | |||
| 109 | if (psdList) | ||
| 110 | ScaDbsFreeList(psdList); | ||
| 111 | |||
| 112 | return hr; | ||
| 113 | } | ||
