11/*
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.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
@@ -48,7 +48,7 @@ void closeDatabaseView(MSIHANDLE hView) {
4848
4949
5050namespace {
51- UniqueMSIHANDLE openDatabase (const tstring& msiPath) {
51+ MSIHANDLE openDatabase (const tstring& msiPath) {
5252 MSIHANDLE h = 0 ;
5353 const UINT status = MsiOpenDatabase (msiPath.c_str (),
5454 MSIDBOPEN_READONLY, &h);
@@ -57,7 +57,7 @@ UniqueMSIHANDLE openDatabase(const tstring& msiPath) {
5757 << " MsiOpenDatabase(" << msiPath
5858 << " , MSIDBOPEN_READONLY) failed" , status));
5959 }
60- return UniqueMSIHANDLE (h) ;
60+ return h ;
6161}
6262
6363} // namespace
@@ -115,7 +115,7 @@ DatabaseRecord::DatabaseRecord(unsigned fieldCount) {
115115 JP_THROW (msi::Error (tstrings::any () << " MsiCreateRecord("
116116 << fieldCount << " ) failed" , ERROR_FUNCTION_FAILED));
117117 }
118- handle = UniqueMSIHANDLE (h) ;
118+ handle = h ;
119119}
120120
121121
@@ -139,7 +139,7 @@ DatabaseRecord& DatabaseRecord::tryFetch(DatabaseView& view) {
139139
140140
141141DatabaseRecord& 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 ());
143143 if (status != ERROR_SUCCESS) {
144144 JP_THROW (Error (tstrings::any () << " MsiRecordSetString(" << idx
145145 << " , " << v << " ) failed" , status));
@@ -149,7 +149,7 @@ DatabaseRecord& DatabaseRecord::setString(unsigned idx, const tstring& v) {
149149
150150
151151DatabaseRecord& DatabaseRecord::setInteger (unsigned idx, int v) {
152- const UINT status = MsiRecordSetInteger (handle. get () , idx, v);
152+ const UINT status = MsiRecordSetInteger (handle, idx, v);
153153 if (status != ERROR_SUCCESS) {
154154 JP_THROW (Error (tstrings::any () << " MsiRecordSetInteger(" << idx
155155 << " , " << v << " ) failed" , status));
@@ -160,7 +160,7 @@ DatabaseRecord& DatabaseRecord::setInteger(unsigned idx, int v) {
160160
161161DatabaseRecord& DatabaseRecord::setStreamFromFile (unsigned idx,
162162 const tstring& v) {
163- const UINT status = MsiRecordSetStream (handle. get () , idx, v.c_str ());
163+ const UINT status = MsiRecordSetStream (handle, idx, v.c_str ());
164164 if (status != ERROR_SUCCESS) {
165165 JP_THROW (Error (tstrings::any () << " MsiRecordSetStream(" << idx
166166 << " , " << v << " ) failed" , status));
@@ -170,7 +170,7 @@ DatabaseRecord& DatabaseRecord::setStreamFromFile(unsigned idx,
170170
171171
172172unsigned DatabaseRecord::getFieldCount () const {
173- const unsigned reply = MsiRecordGetFieldCount (handle. get () );
173+ const unsigned reply = MsiRecordGetFieldCount (handle);
174174 if (int (reply) <= 0 ) {
175175 JP_THROW (Error (std::string (" MsiRecordGetFieldCount() failed" ),
176176 ERROR_FUNCTION_FAILED));
@@ -180,7 +180,7 @@ unsigned DatabaseRecord::getFieldCount() const {
180180
181181
182182int DatabaseRecord::getInteger (unsigned idx) const {
183- int const reply = MsiRecordGetInteger (handle. get () , idx);
183+ int const reply = MsiRecordGetInteger (handle, idx);
184184 if (reply == MSI_NULL_INTEGER) {
185185 JP_THROW (Error (tstrings::any () << " MsiRecordGetInteger(" << idx
186186 << " ) failed" , ERROR_FUNCTION_FAILED));
@@ -199,7 +199,7 @@ void DatabaseRecord::saveStreamToFile(unsigned idx,
199199 DWORD bytes;
200200 do {
201201 bytes = ReadStreamBufferBytes;
202- const UINT status = MsiRecordReadStream (handle. get () , UINT (idx),
202+ const UINT status = MsiRecordReadStream (handle, UINT (idx),
203203 buffer.data (), &bytes);
204204 if (status != ERROR_SUCCESS) {
205205 JP_THROW (Error (std::string (" MsiRecordReadStream() failed" ),
@@ -216,25 +216,23 @@ DatabaseView::DatabaseView(const Database& db, const tstring& sqlQuery,
216216 MSIHANDLE h = 0 ;
217217
218218 // Create SQL query.
219- for (const UINT status = MsiDatabaseOpenView (db.dbHandle . get () ,
219+ for (const UINT status = MsiDatabaseOpenView (db.dbHandle ,
220220 sqlQuery.c_str (), &h); status != ERROR_SUCCESS; ) {
221221 JP_THROW (Error (tstrings::any () << " MsiDatabaseOpenView("
222222 << sqlQuery << " ) failed" , status));
223223 }
224224
225- UniqueMSIHANDLE tmp (h);
226-
227225 // Run SQL query.
228- for (const UINT status = MsiViewExecute (h, queryParam.handle . get () );
226+ for (const UINT status = MsiViewExecute (h, queryParam.handle );
229227 status != ERROR_SUCCESS; ) {
228+ closeMSIHANDLE (h);
230229 JP_THROW (Error (tstrings::any () << " MsiViewExecute("
231230 << sqlQuery << " ) failed" , status));
232231 }
233232
234233 // MsiViewClose should be called only after
235234 // successful MsiViewExecute() call.
236- handle = UniqueDbView (h);
237- tmp.release ();
235+ handle = h;
238236}
239237
240238
@@ -253,7 +251,7 @@ DatabaseRecord DatabaseView::tryFetch() {
253251
254252 // Fetch data from executed SQL query.
255253 // Data is stored in a record object.
256- for (const UINT status = MsiViewFetch (handle. get () , &h);
254+ for (const UINT status = MsiViewFetch (handle, &h);
257255 status != ERROR_SUCCESS; ) {
258256 if (status == ERROR_NO_MORE_ITEMS) {
259257 return DatabaseRecord ();
@@ -264,14 +262,14 @@ DatabaseRecord DatabaseView::tryFetch() {
264262 }
265263
266264 DatabaseRecord reply;
267- reply.handle = UniqueMSIHANDLE (h) ;
265+ reply.handle = h ;
268266 return reply;
269267}
270268
271269
272270DatabaseView& DatabaseView::modify (const DatabaseRecord& record,
273271 MSIMODIFY mode) {
274- const UINT status = MsiViewModify (handle. get () , mode, record.handle . get () );
272+ const UINT status = MsiViewModify (handle, mode, record.handle );
275273 if (status != ERROR_SUCCESS) {
276274 JP_THROW (Error (tstrings::any () << " MsiViewModify(mode=" << mode
277275 << " ) failed" , status));
0 commit comments