1
1
/*
2
- * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -48,7 +48,7 @@ void closeDatabaseView(MSIHANDLE hView) {
48
48
49
49
50
50
namespace {
51
- UniqueMSIHANDLE openDatabase (const tstring& msiPath) {
51
+ MSIHANDLE openDatabase (const tstring& msiPath) {
52
52
MSIHANDLE h = 0 ;
53
53
const UINT status = MsiOpenDatabase (msiPath.c_str (),
54
54
MSIDBOPEN_READONLY, &h);
@@ -57,7 +57,7 @@ UniqueMSIHANDLE openDatabase(const tstring& msiPath) {
57
57
<< " MsiOpenDatabase(" << msiPath
58
58
<< " , MSIDBOPEN_READONLY) failed" , status));
59
59
}
60
- return UniqueMSIHANDLE (h) ;
60
+ return h ;
61
61
}
62
62
63
63
} // namespace
@@ -115,7 +115,7 @@ DatabaseRecord::DatabaseRecord(unsigned fieldCount) {
115
115
JP_THROW (msi::Error (tstrings::any () << " MsiCreateRecord("
116
116
<< fieldCount << " ) failed" , ERROR_FUNCTION_FAILED));
117
117
}
118
- handle = UniqueMSIHANDLE (h) ;
118
+ handle = h ;
119
119
}
120
120
121
121
@@ -139,7 +139,7 @@ DatabaseRecord& DatabaseRecord::tryFetch(DatabaseView& view) {
139
139
140
140
141
141
DatabaseRecord& DatabaseRecord::setString (unsigned idx, const tstring& v) {
142
- const UINT status = MsiRecordSetString (handle. get () , idx, v.c_str ());
142
+ const UINT status = MsiRecordSetString (handle, idx, v.c_str ());
143
143
if (status != ERROR_SUCCESS) {
144
144
JP_THROW (Error (tstrings::any () << " MsiRecordSetString(" << idx
145
145
<< " , " << v << " ) failed" , status));
@@ -149,7 +149,7 @@ DatabaseRecord& DatabaseRecord::setString(unsigned idx, const tstring& v) {
149
149
150
150
151
151
DatabaseRecord& DatabaseRecord::setInteger (unsigned idx, int v) {
152
- const UINT status = MsiRecordSetInteger (handle. get () , idx, v);
152
+ const UINT status = MsiRecordSetInteger (handle, idx, v);
153
153
if (status != ERROR_SUCCESS) {
154
154
JP_THROW (Error (tstrings::any () << " MsiRecordSetInteger(" << idx
155
155
<< " , " << v << " ) failed" , status));
@@ -160,7 +160,7 @@ DatabaseRecord& DatabaseRecord::setInteger(unsigned idx, int v) {
160
160
161
161
DatabaseRecord& DatabaseRecord::setStreamFromFile (unsigned idx,
162
162
const tstring& v) {
163
- const UINT status = MsiRecordSetStream (handle. get () , idx, v.c_str ());
163
+ const UINT status = MsiRecordSetStream (handle, idx, v.c_str ());
164
164
if (status != ERROR_SUCCESS) {
165
165
JP_THROW (Error (tstrings::any () << " MsiRecordSetStream(" << idx
166
166
<< " , " << v << " ) failed" , status));
@@ -170,7 +170,7 @@ DatabaseRecord& DatabaseRecord::setStreamFromFile(unsigned idx,
170
170
171
171
172
172
unsigned DatabaseRecord::getFieldCount () const {
173
- const unsigned reply = MsiRecordGetFieldCount (handle. get () );
173
+ const unsigned reply = MsiRecordGetFieldCount (handle);
174
174
if (int (reply) <= 0 ) {
175
175
JP_THROW (Error (std::string (" MsiRecordGetFieldCount() failed" ),
176
176
ERROR_FUNCTION_FAILED));
@@ -180,7 +180,7 @@ unsigned DatabaseRecord::getFieldCount() const {
180
180
181
181
182
182
int DatabaseRecord::getInteger (unsigned idx) const {
183
- int const reply = MsiRecordGetInteger (handle. get () , idx);
183
+ int const reply = MsiRecordGetInteger (handle, idx);
184
184
if (reply == MSI_NULL_INTEGER) {
185
185
JP_THROW (Error (tstrings::any () << " MsiRecordGetInteger(" << idx
186
186
<< " ) failed" , ERROR_FUNCTION_FAILED));
@@ -199,7 +199,7 @@ void DatabaseRecord::saveStreamToFile(unsigned idx,
199
199
DWORD bytes;
200
200
do {
201
201
bytes = ReadStreamBufferBytes;
202
- const UINT status = MsiRecordReadStream (handle. get () , UINT (idx),
202
+ const UINT status = MsiRecordReadStream (handle, UINT (idx),
203
203
buffer.data (), &bytes);
204
204
if (status != ERROR_SUCCESS) {
205
205
JP_THROW (Error (std::string (" MsiRecordReadStream() failed" ),
@@ -216,25 +216,23 @@ DatabaseView::DatabaseView(const Database& db, const tstring& sqlQuery,
216
216
MSIHANDLE h = 0 ;
217
217
218
218
// Create SQL query.
219
- for (const UINT status = MsiDatabaseOpenView (db.dbHandle . get () ,
219
+ for (const UINT status = MsiDatabaseOpenView (db.dbHandle ,
220
220
sqlQuery.c_str (), &h); status != ERROR_SUCCESS; ) {
221
221
JP_THROW (Error (tstrings::any () << " MsiDatabaseOpenView("
222
222
<< sqlQuery << " ) failed" , status));
223
223
}
224
224
225
- UniqueMSIHANDLE tmp (h);
226
-
227
225
// Run SQL query.
228
- for (const UINT status = MsiViewExecute (h, queryParam.handle . get () );
226
+ for (const UINT status = MsiViewExecute (h, queryParam.handle );
229
227
status != ERROR_SUCCESS; ) {
228
+ closeMSIHANDLE (h);
230
229
JP_THROW (Error (tstrings::any () << " MsiViewExecute("
231
230
<< sqlQuery << " ) failed" , status));
232
231
}
233
232
234
233
// MsiViewClose should be called only after
235
234
// successful MsiViewExecute() call.
236
- handle = UniqueDbView (h);
237
- tmp.release ();
235
+ handle = h;
238
236
}
239
237
240
238
@@ -253,7 +251,7 @@ DatabaseRecord DatabaseView::tryFetch() {
253
251
254
252
// Fetch data from executed SQL query.
255
253
// Data is stored in a record object.
256
- for (const UINT status = MsiViewFetch (handle. get () , &h);
254
+ for (const UINT status = MsiViewFetch (handle, &h);
257
255
status != ERROR_SUCCESS; ) {
258
256
if (status == ERROR_NO_MORE_ITEMS) {
259
257
return DatabaseRecord ();
@@ -264,14 +262,14 @@ DatabaseRecord DatabaseView::tryFetch() {
264
262
}
265
263
266
264
DatabaseRecord reply;
267
- reply.handle = UniqueMSIHANDLE (h) ;
265
+ reply.handle = h ;
268
266
return reply;
269
267
}
270
268
271
269
272
270
DatabaseView& DatabaseView::modify (const DatabaseRecord& record,
273
271
MSIMODIFY mode) {
274
- const UINT status = MsiViewModify (handle. get () , mode, record.handle . get () );
272
+ const UINT status = MsiViewModify (handle, mode, record.handle );
275
273
if (status != ERROR_SUCCESS) {
276
274
JP_THROW (Error (tstrings::any () << " MsiViewModify(mode=" << mode
277
275
<< " ) failed" , status));
0 commit comments