本文整理汇总了C++中database类的典型用法代码示例。如果您正苦于以下问题:C++ database类的具体用法?C++ database怎么用?C++ database使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了database类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: do_update_set
static int
do_update_set(const symboldb_options &opt, database &db, char **argv)
{
database::package_set_id set = db.lookup_package_set(opt.set_name.c_str());
if (set == database::package_set_id()) {
fprintf(stderr, "error: package set \"%s\" does not exist\n",
opt.set_name.c_str());
return 1;
}
typedef std::vector<database::package_id> pset;
pset ids;
{
package_set_consolidator<database::package_id> psc;
if (!load_rpms(opt, db, argv, psc)) {
return 1;
}
ids = psc.values();
}
db.txn_begin();
{
database::advisory_lock lock
(db.lock(database::PACKAGE_SET_LOCK_TAG, set.value()));
if (db.update_package_set(set, ids)) {
finalize_package_set(opt, db, set);
}
}
db.txn_commit();
return 0;
}
示例2: init_DB_level
void isomorph::init_DB_level(database &D, INT level, INT verbose_level)
{
INT f_v = (verbose_level >= 1);
btree B1, B2;
INT f_compress = TRUE;
INT f_duplicatekeys = TRUE;
INT i;
if (f_v) {
cout << "isomorph::init_DB_level level=" << level << endl;
}
sprintf(fname_db_level, "%sstarter_lvl_%ld.db", prefix, level);
sprintf(fname_db_level_idx1, "%sstarter_lvl_%ld_a.idx", prefix, level);
sprintf(fname_db_level_idx2, "%sstarter_lvl_%ld_b.idx", prefix, level);
sprintf(fname_db_level_ge, "%sstarter_lvl_%ld_ge.bin", prefix, level);
D.init(fname_db_level, VECTOR, f_compress);
B1.init(fname_db_level_idx1, f_duplicatekeys, 0 /* btree_idx */);
B1.add_key_INT4(0, 0);
D.btree_access().append(B1);
B2.init(fname_db_level_idx2, f_duplicatekeys, 1 /* btree_idx */);
// 2 up to 2+level-1 are the values of the starter (of size level)
for (i = 0; i < level; i++) {
B2.add_key_INT4(2 + i, 0);
}
D.btree_access().append(B2);
}
示例3: pay_worker
void refund_worker_type::pay_worker(share_type pay, database& db)
{
total_burned += pay;
db.modify(db.get(asset_id_type()).dynamic_data(db), [pay](asset_dynamic_data_object& d) {
d.current_supply -= pay;
});
}
示例4: do_create_set
static int
do_create_set(const symboldb_options &opt, database &db, char **argv)
{
if (db.lookup_package_set(opt.set_name.c_str())
!= database::package_set_id()) {
fprintf(stderr, "error: package set \"%s\" already exists\n",
opt.set_name.c_str());
return 1;
}
typedef std::vector<database::package_id> pset;
pset ids;
{
package_set_consolidator<database::package_id> psc;
if (!load_rpms(opt, db, argv, psc)) {
return 1;
}
ids = psc.values();
}
db.txn_begin();
database::package_set_id set =
db.create_package_set(opt.set_name.c_str());
if (db.update_package_set(set, ids)) {
finalize_package_set(opt, db, set);
}
db.txn_commit();
return 0;
}
示例5: load_zip
static void
load_zip(database &db,
database::contents_id cid, const rpm_file_entry &file)
{
zip_file zip(&file.contents);
std::vector<unsigned char> data;
while (true) {
try {
if (!zip.next()) {
break;
}
} catch (os_exception &e) {
// FIXME: Use proper, zip_file-specific exception.
// zip.name() is not necessarily valid at this point.
db.add_java_error(cid, e.what(), "");
// Exit the loop because the file is likely corrupted significantly.
break;
}
try {
zip.data(data);
} catch (os_exception &e) {
// FIXME: Use proper, zip_file-specific exception.
db.add_java_error(cid, e.what(), zip.name());
}
if (java_class::has_signature(data)) {
try {
java_class jc(&data);
db.add_java_class(cid, jc);
} catch (java_class::exception &e) {
db.add_java_error(cid, e.what(), zip.name());
}
}
}
}
示例6: apply
void apply(database &db, const operation &o, const options_type &opts) {
auto undo_session = db.start_undo_session(!(opts &
skip_undo_operation));
db.pre_apply_operation(o);
o.visit(apply_operation_visitor(db, opts));
db.post_apply_operation(o);
undo_session.squash();
}
示例7: add_solution
solution_id add_solution(database& db, assignment_id assignment, std::vector<student_id> solvers,
std::vector<task> editied_tasks) {
auto id = db.new_solution_id();
for(auto solver: solvers) {
db.get_student(solver).add_solution(id);
}
auto tmp = solution{assignment, id, std::move(solvers), std::move(editied_tasks)};
db.add_solution(std::move(tmp));
return id;
}
示例8: do_show_soname_conflicts
static int
do_show_soname_conflicts(const symboldb_options &opt, database &db)
{
database::package_set_id pset = db.lookup_package_set(opt.set_name.c_str());
if (pset > database::package_set_id()) {
db.print_elf_soname_conflicts(pset);
return 0;
} else {
fprintf(stderr, "error: invalid package set: %s\n", opt.set_name.c_str());
return 1;
}
}
示例9: add_files
static void
add_files(const symboldb_options &opt, database &db, python_analyzer &pya,
const rpm_package_info &pkginfo, database::package_id pkg,
const char *rpm_path, rpm_file_entry &file)
{
std::vector<unsigned char> digest;
std::vector<unsigned char> preview;
prepare_load(rpm_path, file, digest, preview);
file.infos.front().normalize_name();
database::file_id fid;
database::contents_id cid;
database::attribute_id aid;
bool added;
int contents_length;
db.add_file(pkg, file.infos.front(), digest, preview, fid, cid,
added, contents_length);
bool looks_like_python =
unpack_files(pkginfo) && is_python_path(file.infos.front());
if (file.infos.size() > 1) {
assert(!file.infos.front().ghost());
for (std::vector<rpm_file_info>::iterator
p = file.infos.begin() + 1, end = file.infos.end();
p != end; ++p) {
assert(!p->ghost());
p->normalize_name();
aid = db.intern_file_attribute(*p);
db.add_file(pkg, p->name, p->mtime, p->ino, cid, aid);
looks_like_python = looks_like_python
|| (unpack_files(pkginfo) && is_python_path(file.infos.front()));
}
}
if (added) {
if (unpack_files(pkginfo)) {
do_load_formats(opt, db, pya, cid, file);
}
} else {
// We might recognize additonal files as Python files if they are
// loaded later under a different name.
if (looks_like_python) {
load_python(opt, db, pya, cid, file);
}
}
// If the contents in the database was truncated, update it with the
// longer version.
if (static_cast<size_t>(contents_length) < preview.size()) {
db.update_contents_preview(cid, preview);
}
}
示例10: do_run_example
static int
do_run_example(const symboldb_options &opt, database &db, char **argv)
{
int errors = 0;
while (*argv) {
file_handle file(*argv, "r");
file_handle::line line_handle;
std::string current;
unsigned lineno = 0;
unsigned start_lineno;
try {
while (file.getline(line_handle)) {
++lineno;
std::string line(line_handle.str());
bool start = current.empty();
if (starts_with(line, " ")) {
current += " ";
current.append(line.begin() + 4, line.end());
} else if (starts_with(line, "\t")) {
current.append(line.begin() + 1, line.end());
} else if (!current.empty()) {
if (opt.output != symboldb_options::quiet) {
fprintf(stderr, "info: executing %s:%u\n", *argv, start_lineno);
}
db.exec_sql(current.c_str());
current.clear();
start = false;
} else {
start = false;
}
if (start && !current.empty()) {
start_lineno = lineno;
}
}
if (!current.empty()) {
if (opt.output != symboldb_options::quiet) {
fprintf(stderr, "info: executing %s:%u\n", *argv, start_lineno);
}
db.exec_sql(current.c_str());
}
} catch (pg_exception &e) {
dump("error: ", e, stderr);
++errors;
}
++argv;
}
if (errors > 0) {
return 1;
} else {
return 0;
}
}
示例11: get_all_tables_numbers
// Return a sorted vector of all table numbers.
std::vector<table::Number> get_all_tables_numbers(database const& table_file)
{
int const tables_count = table_file.tables_count();
std::vector<table::Number> numbers;
numbers.reserve(tables_count);
for(int i = 0; i != tables_count; ++i)
{
numbers.push_back(table_file.get_nth_table(i).number());
}
std::sort(numbers.begin(), numbers.end());
return numbers;
}
示例12: load_rpm_internal
static database::package_id
load_rpm_internal(const symboldb_options &opt, database &db,
const char *rpm_path, rpm_package_info &pkginfo)
{
rpm_parser rpmparser(rpm_path);
python_analyzer pya;
pkginfo = rpmparser.package();
// We can destroy the lock immediately because we are running in a
// transaction.
lock_rpm(db, pkginfo);
rpm_file_entry file;
database::package_id pkg;
if (!db.intern_package(rpmparser.package(), pkg)) {
if (opt.output != symboldb_options::quiet) {
fprintf(stderr, "info: skipping %s from %s\n",
rpmparser.nevra(), rpm_path);
}
return pkg;
}
if (opt.output != symboldb_options::quiet) {
fprintf(stderr, "info: loading %s from %s\n", rpmparser.nevra(), rpm_path);
}
dependencies(opt, db, pkg, rpmparser);
scripts(opt, db, pkg, rpmparser);
triggers(opt, db, pkg, rpmparser);
// FIXME: We should not read arbitrary files into memory, only ELF
// files.
while (rpmparser.read_file(file)) {
if (file.infos.size() > 1) {
// Hard links, so this is a real file.
add_files(opt, db, pya, pkginfo, pkg, rpm_path, file);
continue;
}
assert(!file.infos.empty());
rpm_file_info &info(file.infos.front());
if (info.is_directory()) {
db.add_directory(pkg, info);
} else if (info.is_symlink()) {
db.add_symlink(pkg, info);
} else {
add_files(opt, db, pya, pkginfo, pkg, rpm_path, file);
}
}
return pkg;
}
示例13: rpm_load
database::package_id
rpm_load(const symboldb_options &opt, database &db,
const char *path, rpm_package_info &info,
const checksum *expected, const char *url)
{
if (expected && (expected->type != hash_sink::sha256
&& expected->type != hash_sink::sha1)) {
raise<std::runtime_error>("unsupported hash type");
}
// Unreferenced RPMs should not be visible to analyzers, so we can
// load each RPM in a separate transaction. We make a synchronous
// commit when referencing the RPM data, so a non-synchronous commit
// is sufficient here.
db.txn_begin_no_sync();
database::package_id pkg = load_rpm_internal(opt, db, path, info);
hash_sink sha256(hash_sink::sha256);
hash_sink sha1(hash_sink::sha1);
{
fd_handle handle;
handle.open_read_only(path);
fd_source source(handle.get());
tee_sink tee(&sha256, &sha1);
copy_source_to_sink(source, tee);
}
assert(sha256.octets() == sha1.octets());
std::vector<unsigned char> digest;
sha256.digest(digest);
db.add_package_digest(pkg, digest, sha256.octets());
if (expected && expected->type == hash_sink::sha256
&& expected->value != digest) {
raise<std::runtime_error>("checksum mismatch");
}
sha1.digest(digest);
db.add_package_digest(pkg, digest, sha1.octets());
if (expected && expected->type == hash_sink::sha1
&& expected->value != digest) {
raise<std::runtime_error>("checksum mismatch");
}
if (url != NULL) {
db.add_package_url(pkg, url);
}
db.txn_commit();
return pkg;
}
示例14: _is_authorized_asset
bool _is_authorized_asset(
const database& d,
const account_object& acct,
const asset_object& asset_obj)
{
if( acct.allowed_assets.valid() )
{
if( acct.allowed_assets->find( asset_obj.id ) == acct.allowed_assets->end() )
return false;
// must still pass other checks even if it is in allowed_assets
}
for( const auto id : acct.blacklisting_accounts )
{
if( asset_obj.options.blacklist_authorities.find(id) != asset_obj.options.blacklist_authorities.end() )
return false;
}
if( d.head_block_time() > HARDFORK_415_TIME )
{
if( asset_obj.options.whitelist_authorities.size() == 0 )
return true;
}
for( const auto id : acct.whitelisting_accounts )
{
if( asset_obj.options.whitelist_authorities.find(id) != asset_obj.options.whitelist_authorities.end() )
return true;
}
return false;
}
示例15: expire
void
expire(const symboldb_options &opt, database &db)
{
if (opt.output != symboldb_options::quiet) {
fprintf(stderr, "info: expiring URL cache\n");
}
db.expire_url_cache();
if (opt.output != symboldb_options::quiet) {
fprintf(stderr, "info: expiring unreferenced packages\n");
}
db.expire_packages();
if (opt.output != symboldb_options::quiet) {
fprintf(stderr, "info: expiring file contents\n");
}
db.expire_file_contents();
if (opt.output != symboldb_options::quiet) {
fprintf(stderr, "info: expiring java classes\n");
}
db.expire_java_classes();
if (opt.output != symboldb_options::quiet) {
fprintf(stderr, "info: expiring unused RPMs\n");
}
{
typedef std::vector<std::vector<unsigned char> > digvec;
std::tr1::shared_ptr<file_cache> fcache(opt.rpm_cache());
digvec fcdigests;
fcache->digests(fcdigests);
std::sort(fcdigests.begin(), fcdigests.end());
digvec dbdigests;
db.referenced_package_digests(dbdigests);
digvec result;
std::set_difference(fcdigests.begin(), fcdigests.end(),
dbdigests.begin(), dbdigests.end(),
std::back_inserter(result));
fd_handle dir;
dir.open_directory(opt.rpm_cache_path().c_str());
for (digvec::iterator p = result.begin(), end = result.end();
p != end; ++p) {
dir.unlinkat(base16_encode(p->begin(), p->end()).c_str(), 0);
}
}
}