/* * Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
tstring Database::getProperty(const tstring& name) const { // Query value of a property with the given name from 'Property' MSI table. const tstring sqlQuery = (tstrings::any()
<< "SELECT Value FROM Property WHERE Property = '"
<< name << "'").tstr();
// Data is stored in a record object. SQL query is constructed in a way // this record object contains a single field. // Verify record contains exactly one field. if (record.getFieldCount() != 1) {
JP_THROW(Error(
tstrings::any() << "record.getFieldCount(" << msiPath
<< ", " << sqlQuery
<< ") returned unexpected value",
ERROR_SUCCESS));
}
// Field identifier. They start with 1, not from 0. constunsigned field = 1; return record.getString(field);
}
// Create SQL query. for (const UINT status = MsiDatabaseOpenView(db.dbHandle,
sqlQuery.c_str(), &h); status != ERROR_SUCCESS; ) {
JP_THROW(Error(tstrings::any() << "MsiDatabaseOpenView("
<< sqlQuery << ") failed", status));
}
// Run SQL query. for (const UINT status = MsiViewExecute(h, queryParam.handle);
status != ERROR_SUCCESS; ) {
closeMSIHANDLE(h);
JP_THROW(Error(tstrings::any() << "MsiViewExecute("
<< sqlQuery << ") failed", status));
}
// MsiViewClose should be called only after // successful MsiViewExecute() call.
handle = h;
}
DatabaseRecord DatabaseView::fetch() {
DatabaseRecord reply = tryFetch(); if (reply.empty()) {
JP_THROW(NoMoreItemsError(tstrings::any() << "No more items in ["
<< sqlQuery << "] query"));
} return reply;
}
DatabaseRecord DatabaseView::tryFetch() {
MSIHANDLE h = 0;
// Fetch data from executed SQL query. // Data is stored in a record object. for (const UINT status = MsiViewFetch(handle, &h);
status != ERROR_SUCCESS; ) { if (status == ERROR_NO_MORE_ITEMS) { return DatabaseRecord();
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.1Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.