68 lines
1.8 KiB
C++
68 lines
1.8 KiB
C++
#include "dbobjectptr.hh"
|
|
#include "dbobjectmap.hh"
|
|
#include "category.hh"
|
|
#include "dbobject.hh"
|
|
#include "item.hh"
|
|
#include "dbsession.hh"
|
|
#include <stdexcept>
|
|
|
|
#include <zdb.h>
|
|
// refer to libzdb docs
|
|
#include <Exception.h>
|
|
|
|
namespace inventory {
|
|
namespace datamodel {
|
|
|
|
const char *Category::sc_table = "categories";
|
|
const char *Category::sc_view = "category_view";
|
|
const char *Category::sc_membership_table = "category_membership";
|
|
const char *Category::sc_dbclass = "category";
|
|
|
|
const struct DBRecordElementDesc Category::desc_desc = {
|
|
"description",
|
|
"",
|
|
""
|
|
};
|
|
|
|
const struct DBRecordElementDesc Category::symbol_desc = {
|
|
"symbol",
|
|
"",
|
|
""
|
|
};
|
|
|
|
void Category::create_tables(db::DBSession &session) {
|
|
const char *create_table =
|
|
"CREATE TABLE \"categories\" ( \n\
|
|
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, \n\
|
|
`sup` INTEGER NOT NULL DEFAULT -1, \n\
|
|
`name` TEXT, \n\
|
|
`description` TEXT, \n\
|
|
`symbol` BLOB, \n\
|
|
FOREIGN KEY(`sup`) REFERENCES categories ( id ) );";
|
|
|
|
db::DBOperations::execute<void *>(session, NULL, create_table,
|
|
[](void *, PreparedStatement_T s) {});
|
|
|
|
DBHierarchicalObject<Category>::create_sub_view(session);
|
|
DBHierarchicalObject<Category>::create_sup_view(session);
|
|
DBAssocHierarchicalObject<Item, Category>::create_membership_table(session);
|
|
|
|
const char *category_view =
|
|
"CREATE VIEW category_view AS SELECT * FROM category_sub \n\
|
|
JOIN categories ON categories.id = category_sub.id;";
|
|
|
|
db::DBOperations::execute<void *>(session, NULL, category_view,
|
|
[](void *, PreparedStatement_T s) {});
|
|
}
|
|
|
|
void Category::validate_tables(db::DBSession &session) {
|
|
|
|
}
|
|
|
|
void Category::remove_tables(db::DBSession &session) {
|
|
|
|
}
|
|
|
|
}
|
|
}
|