/usr/include/dballe/db/v6/datav6.h is in libdballe-dev 7.21-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | #ifndef DBALLE_DB_V6_DATAV6_H
#define DBALLE_DB_V6_DATAV6_H
/** @file
* @ingroup db
*
* Attribute table management used by the db module.
*/
#include <dballe/core/defs.h>
#include <dballe/sql/fwd.h>
#include <wreport/var.h>
#include <memory>
#include <vector>
#include <cstdio>
namespace dballe {
struct Record;
namespace db {
namespace v6 {
struct QueryBuilder;
namespace bulk {
struct InsertV6;
}
/**
* Precompiled query to manipulate the data table
*/
struct DataV6
{
public:
enum UpdateMode {
UPDATE,
IGNORE,
ERROR,
};
virtual ~DataV6();
/// Bulk variable insert
virtual void insert(dballe::sql::Transaction& t, bulk::InsertV6& vars, UpdateMode update_mode=UPDATE) = 0;
/// Run the query to delete all records selected by the given QueryBuilder
virtual void remove(const v6::QueryBuilder& qb) = 0;
/// Dump the entire contents of the table to an output stream
virtual void dump(FILE* out) = 0;
};
namespace bulk {
struct Item
{
static const unsigned FLAG_NEEDS_UPDATE = 1 << 0;
static const unsigned FLAG_UPDATED = 1 << 1;
static const unsigned FLAG_NEEDS_INSERT = 1 << 2;
static const unsigned FLAG_INSERTED = 1 << 3;
unsigned flags = 0;
bool needs_update() const { return flags & FLAG_NEEDS_UPDATE; }
bool updated() const { return flags & FLAG_UPDATED; }
bool needs_insert() const { return flags & FLAG_NEEDS_INSERT; }
bool inserted() const { return flags & FLAG_INSERTED; }
void set_needs_update() { flags |= FLAG_NEEDS_UPDATE; }
void set_updated() { flags = (flags & ~FLAG_NEEDS_UPDATE) | FLAG_UPDATED; }
void set_needs_insert() { flags |= FLAG_NEEDS_INSERT; }
void set_inserted() { flags = (flags & ~FLAG_NEEDS_INSERT) | FLAG_INSERTED; }
/**
* Format flags in the first 4 characters of dest.
*
* It adds a trailing 0, so dest should be at least 5 bytes long.
*/
void format_flags(char* dest) const;
};
/**
* Workflow information about a variable listed for bulk insert/update
*/
struct VarV6 : public Item
{
int id_levtr;
int id_data;
const wreport::Var* var;
VarV6(const wreport::Var* var, int id_levtr=-1, int id_data=-1)
: id_levtr(id_levtr), id_data(id_data), var(var)
{
}
bool operator<(const VarV6& v) const
{
if (int d = id_levtr - v.id_levtr) return d < 0;
return var->code() < v.var->code();
}
void dump(FILE* out) const;
};
/**
* Input for a bulk insert of a lot of variables sharing the same context
* information.
*/
struct InsertV6 : public std::vector<VarV6>
{
int id_station;
int id_report;
Datetime datetime;
void add(const wreport::Var* var, int id_levtr)
{
emplace_back(var, id_levtr);
}
void dump(FILE* out) const;
};
/**
* Helper class for annotating InsertV6 variables with the current status of
* the database.
*/
struct AnnotateVarsV6
{
InsertV6& vars;
InsertV6::iterator iter;
bool do_insert = false;
bool do_update = false;
AnnotateVarsV6(InsertV6& vars);
bool annotate(int id_data, int id_levtr, wreport::Varcode code, const char* value);
void annotate_end();
void dump(FILE* out) const;
};
}
}
}
}
#endif
|