fix fact db structure
This commit is contained in:
parent
6761117e24
commit
ab83a1626b
@ -29,7 +29,7 @@ void obelisk::Fact::selectFact(sqlite3* dbConnection)
|
|||||||
sqlite3_stmt* ppStmt = nullptr;
|
sqlite3_stmt* ppStmt = nullptr;
|
||||||
|
|
||||||
auto result = sqlite3_prepare_v2(dbConnection,
|
auto result = sqlite3_prepare_v2(dbConnection,
|
||||||
"SELECT id, left_entity, right_entity, verb FROM fact WHERE (left_entity=? AND right_entity=? AND verb=?)",
|
"SELECT id, left_entity, right_entity, verb, is_true FROM fact WHERE (left_entity=? AND right_entity=? AND verb=?)",
|
||||||
-1,
|
-1,
|
||||||
&ppStmt,
|
&ppStmt,
|
||||||
nullptr);
|
nullptr);
|
||||||
@ -106,6 +106,7 @@ void obelisk::Fact::selectFact(sqlite3* dbConnection)
|
|||||||
getLeftEntity().setId(sqlite3_column_int(ppStmt, 1));
|
getLeftEntity().setId(sqlite3_column_int(ppStmt, 1));
|
||||||
getRightEntity().setId(sqlite3_column_int(ppStmt, 2));
|
getRightEntity().setId(sqlite3_column_int(ppStmt, 2));
|
||||||
getVerb().setId(sqlite3_column_int(ppStmt, 3));
|
getVerb().setId(sqlite3_column_int(ppStmt, 3));
|
||||||
|
setIsTrue(sqlite3_column_int(ppStmt, 4));
|
||||||
break;
|
break;
|
||||||
case SQLITE_BUSY :
|
case SQLITE_BUSY :
|
||||||
throw obelisk::DatabaseBusyException();
|
throw obelisk::DatabaseBusyException();
|
||||||
@ -135,7 +136,7 @@ void obelisk::Fact::insertFact(sqlite3* dbConnection)
|
|||||||
sqlite3_stmt* ppStmt = nullptr;
|
sqlite3_stmt* ppStmt = nullptr;
|
||||||
|
|
||||||
auto result = sqlite3_prepare_v2(dbConnection,
|
auto result = sqlite3_prepare_v2(dbConnection,
|
||||||
"INSERT INTO fact (left_entity, right_entity, verb) VALUES (?, ?, ?)",
|
"INSERT INTO fact (left_entity, right_entity, verb, is_true) VALUES (?, ?, ?, ?)",
|
||||||
-1,
|
-1,
|
||||||
&ppStmt,
|
&ppStmt,
|
||||||
nullptr);
|
nullptr);
|
||||||
@ -201,6 +202,25 @@ void obelisk::Fact::insertFact(sqlite3* dbConnection)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result = sqlite3_bind_int(ppStmt, 4, getIsTrue());
|
||||||
|
switch (result)
|
||||||
|
{
|
||||||
|
case SQLITE_OK :
|
||||||
|
break;
|
||||||
|
case SQLITE_TOOBIG :
|
||||||
|
throw obelisk::DatabaseSizeException();
|
||||||
|
break;
|
||||||
|
case SQLITE_RANGE :
|
||||||
|
throw obelisk::DatabaseRangeException();
|
||||||
|
break;
|
||||||
|
case SQLITE_NOMEM :
|
||||||
|
throw obelisk::DatabaseMemoryException();
|
||||||
|
break;
|
||||||
|
default :
|
||||||
|
throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
result = sqlite3_step(ppStmt);
|
result = sqlite3_step(ppStmt);
|
||||||
switch (result)
|
switch (result)
|
||||||
{
|
{
|
||||||
@ -267,3 +287,13 @@ void obelisk::Fact::setVerb(obelisk::Verb verb)
|
|||||||
{
|
{
|
||||||
verb_ = verb;
|
verb_ = verb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool& obelisk::Fact::getIsTrue()
|
||||||
|
{
|
||||||
|
return isTrue_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void obelisk::Fact::setIsTrue(bool isTrue)
|
||||||
|
{
|
||||||
|
isTrue_ = isTrue;
|
||||||
|
}
|
||||||
|
@ -16,13 +16,15 @@ namespace obelisk
|
|||||||
obelisk::Entity leftEntity_;
|
obelisk::Entity leftEntity_;
|
||||||
obelisk::Entity rightEntity_;
|
obelisk::Entity rightEntity_;
|
||||||
obelisk::Verb verb_;
|
obelisk::Verb verb_;
|
||||||
|
bool isTrue_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Fact() :
|
Fact() :
|
||||||
id_(0),
|
id_(0),
|
||||||
leftEntity_(),
|
leftEntity_(),
|
||||||
rightEntity_(),
|
rightEntity_(),
|
||||||
verb_()
|
verb_(),
|
||||||
|
isTrue_(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,23 +32,26 @@ namespace obelisk
|
|||||||
id_(id),
|
id_(id),
|
||||||
leftEntity_(),
|
leftEntity_(),
|
||||||
rightEntity_(),
|
rightEntity_(),
|
||||||
verb_()
|
verb_(),
|
||||||
|
isTrue_(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Fact(obelisk::Entity leftEntity, obelisk::Entity rightEntity, obelisk::Verb verb) :
|
Fact(obelisk::Entity leftEntity, obelisk::Entity rightEntity, obelisk::Verb verb, bool isTrue) :
|
||||||
id_(0),
|
id_(0),
|
||||||
leftEntity_(leftEntity),
|
leftEntity_(leftEntity),
|
||||||
rightEntity_(rightEntity),
|
rightEntity_(rightEntity),
|
||||||
verb_(verb)
|
verb_(verb),
|
||||||
|
isTrue_(isTrue)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Fact(int id, obelisk::Entity leftEntity, obelisk::Entity rightEntity, obelisk::Verb verb) :
|
Fact(int id, obelisk::Entity leftEntity, obelisk::Entity rightEntity, obelisk::Verb verb, bool isTrue) :
|
||||||
id_(id),
|
id_(id),
|
||||||
leftEntity_(leftEntity),
|
leftEntity_(leftEntity),
|
||||||
rightEntity_(rightEntity),
|
rightEntity_(rightEntity),
|
||||||
verb_(verb)
|
verb_(verb),
|
||||||
|
isTrue_(isTrue)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,6 +69,9 @@ namespace obelisk
|
|||||||
Verb& getVerb();
|
Verb& getVerb();
|
||||||
void setVerb(obelisk::Verb verb);
|
void setVerb(obelisk::Verb verb);
|
||||||
|
|
||||||
|
bool& getIsTrue();
|
||||||
|
void setIsTrue(bool isTrue);
|
||||||
|
|
||||||
void selectFact(sqlite3* dbConnection);
|
void selectFact(sqlite3* dbConnection);
|
||||||
void insertFact(sqlite3* dbConnection);
|
void insertFact(sqlite3* dbConnection);
|
||||||
};
|
};
|
||||||
|
@ -336,7 +336,7 @@ void obelisk::Parser::parseFact(std::vector<obelisk::Fact>& facts)
|
|||||||
for (auto& rightEntity : rightEntities)
|
for (auto& rightEntity : rightEntities)
|
||||||
{
|
{
|
||||||
facts.push_back(
|
facts.push_back(
|
||||||
obelisk::Fact(obelisk::Entity(leftEntity), obelisk::Entity(rightEntity), obelisk::Verb(verb)));
|
obelisk::Fact(obelisk::Entity(leftEntity), obelisk::Entity(rightEntity), obelisk::Verb(verb), true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user