fix(Data): Make SQLParser internal

This commit is contained in:
Matej Kenda 2024-02-13 17:18:00 +01:00 committed by Alex Fabijanic
parent 55fc2d0111
commit 0088334536
2 changed files with 122 additions and 114 deletions

View File

@ -24,7 +24,6 @@
#include "Poco/Data/Range.h" #include "Poco/Data/Range.h"
#include "Poco/Data/Bulk.h" #include "Poco/Data/Bulk.h"
#include "Poco/Data/Row.h" #include "Poco/Data/Row.h"
#include "SQLParser.h"
#include "Poco/Data/SimpleRowFormatter.h" #include "Poco/Data/SimpleRowFormatter.h"
#include "Poco/SharedPtr.h" #include "Poco/SharedPtr.h"
#include "Poco/Mutex.h" #include "Poco/Mutex.h"
@ -35,9 +34,14 @@
#include <algorithm> #include <algorithm>
namespace hsql {
class SQLParserResult;
}
namespace Poco { namespace Poco {
namespace Data { namespace Data {
namespace Parser = hsql; // namespace Poco::Data::Parser
class AbstractBinding; class AbstractBinding;
class AbstractExtraction; class AbstractExtraction;
@ -537,10 +541,10 @@ private:
#ifndef POCO_DATA_NO_SQL_PARSER #ifndef POCO_DATA_NO_SQL_PARSER
bool isType(Parser::StatementType type) const; bool isType(unsigned int type) const;
/// Returns true if the statement is of the argument type. /// Returns true if the statement is of the argument type.
bool hasType(Parser::StatementType type) const; bool hasType(unsigned int type) const;
/// Returns true if the statement is of the argument type. /// Returns true if the statement is of the argument type.
Poco::SharedPtr<Parser::SQLParserResult> _pParseResult; Poco::SharedPtr<Parser::SQLParserResult> _pParseResult;
@ -568,113 +572,6 @@ inline std::size_t Statement::subTotalRowCount(int dataSet) const
} }
inline const std::string& Statement::parseError()
{
#ifdef POCO_DATA_NO_SQL_PARSER
static std::string empty;
return empty;
#else
return _parseError;
#endif
}
inline Optional<bool> Statement::isSelect() const
{
#ifndef POCO_DATA_NO_SQL_PARSER
if (_pImpl->session().shouldParse())
return isType(Parser::StatementType::kStmtSelect);
else return Optional<bool>();
#else
return Optional<bool>();
#endif
}
inline Optional<bool> Statement::isInsert() const
{
#ifndef POCO_DATA_NO_SQL_PARSER
if (_pImpl->session().shouldParse())
return isType(Parser::StatementType::kStmtInsert);
else return Optional<bool>();
#else
return Optional<bool>();
#endif
}
inline Optional<bool> Statement::isUpdate() const
{
#ifndef POCO_DATA_NO_SQL_PARSER
if (_pImpl->session().shouldParse())
return isType(Parser::StatementType::kStmtUpdate);
else return Optional<bool>();
#else
return Optional<bool>();
#endif
}
inline Optional<bool> Statement::isDelete() const
{
#ifndef POCO_DATA_NO_SQL_PARSER
if (_pImpl->session().shouldParse())
return isType(Parser::StatementType::kStmtDelete);
else return Optional<bool>();
#else
return Optional<bool>();
#endif
}
inline Optional<bool> Statement::hasSelect() const
{
#ifndef POCO_DATA_NO_SQL_PARSER
if (_pImpl->session().shouldParse())
return hasType(Parser::StatementType::kStmtSelect);
else return Optional<bool>();
#else
return Optional<bool>();
#endif
}
inline Optional<bool> Statement::hasInsert() const
{
#ifndef POCO_DATA_NO_SQL_PARSER
if (_pImpl->session().shouldParse())
return hasType(Parser::StatementType::kStmtInsert);
else return Optional<bool>();
#else
return Optional<bool>();
#endif
}
inline Optional<bool> Statement::hasUpdate() const
{
#ifndef POCO_DATA_NO_SQL_PARSER
if (_pImpl->session().shouldParse())
return hasType(Parser::StatementType::kStmtUpdate);
else return Optional<bool>();
#else
return Optional<bool>();
#endif
}
inline Optional<bool> Statement::hasDelete() const
{
#ifndef POCO_DATA_NO_SQL_PARSER
if (_pImpl->session().shouldParse())
return hasType(Parser::StatementType::kStmtDelete);
else return Optional<bool>();
#else
return Optional<bool>();
#endif
}
namespace Keywords { namespace Keywords {

View File

@ -12,6 +12,7 @@
// //
#include "SQLParser.h"
#include "Poco/Data/Statement.h" #include "Poco/Data/Statement.h"
#include "Poco/Data/DataException.h" #include "Poco/Data/DataException.h"
#include "Poco/Data/Extraction.h" #include "Poco/Data/Extraction.h"
@ -193,14 +194,15 @@ Optional<bool> Statement::parse()
#ifndef POCO_DATA_NO_SQL_PARSER #ifndef POCO_DATA_NO_SQL_PARSER
bool Statement::isType(Parser::StatementType type) const bool Statement::isType(unsigned int type) const
{ {
const auto st = static_cast<Parser::StatementType>(type);
std::size_t sz = _pParseResult->size(); std::size_t sz = _pParseResult->size();
if (sz) if (sz)
{ {
for (int i = 0; i < sz; ++i) for (int i = 0; i < sz; ++i)
{ {
if (_pParseResult->getStatement(i)->type() != type) if (_pParseResult->getStatement(i)->type() != st)
return false; return false;
} }
return true; return true;
@ -209,19 +211,128 @@ bool Statement::isType(Parser::StatementType type) const
} }
bool Statement::hasType(Parser::StatementType type) const bool Statement::hasType(unsigned int type) const
{ {
const auto st = static_cast<Parser::StatementType>(type);
for (int i = 0; i < _pParseResult->size(); ++i) for (int i = 0; i < _pParseResult->size(); ++i)
{ {
if (_pParseResult->getStatement(i)->type() == type) if (_pParseResult->getStatement(i)->type() == st)
return true; return true;
} }
return false; return false;
} }
#endif // POCO_DATA_NO_SQL_PARSER #endif // POCO_DATA_NO_SQL_PARSER
const std::string& Statement::parseError()
{
#ifdef POCO_DATA_NO_SQL_PARSER
static std::string empty;
return empty;
#else
return _parseError;
#endif
}
Optional<bool> Statement::isSelect() const
{
#ifndef POCO_DATA_NO_SQL_PARSER
if (_pImpl->session().shouldParse())
return isType(Parser::StatementType::kStmtSelect);
else return Optional<bool>();
#else
return Optional<bool>();
#endif
}
Optional<bool> Statement::isInsert() const
{
#ifndef POCO_DATA_NO_SQL_PARSER
if (_pImpl->session().shouldParse())
return isType(Parser::StatementType::kStmtInsert);
else return Optional<bool>();
#else
return Optional<bool>();
#endif
}
Optional<bool> Statement::isUpdate() const
{
#ifndef POCO_DATA_NO_SQL_PARSER
if (_pImpl->session().shouldParse())
return isType(Parser::StatementType::kStmtUpdate);
else return Optional<bool>();
#else
return Optional<bool>();
#endif
}
Optional<bool> Statement::isDelete() const
{
#ifndef POCO_DATA_NO_SQL_PARSER
if (_pImpl->session().shouldParse())
return isType(Parser::StatementType::kStmtDelete);
else return Optional<bool>();
#else
return Optional<bool>();
#endif
}
Optional<bool> Statement::hasSelect() const
{
#ifndef POCO_DATA_NO_SQL_PARSER
if (_pImpl->session().shouldParse())
return hasType(Parser::StatementType::kStmtSelect);
else return Optional<bool>();
#else
return Optional<bool>();
#endif
}
Optional<bool> Statement::hasInsert() const
{
#ifndef POCO_DATA_NO_SQL_PARSER
if (_pImpl->session().shouldParse())
return hasType(Parser::StatementType::kStmtInsert);
else return Optional<bool>();
#else
return Optional<bool>();
#endif
}
Optional<bool> Statement::hasUpdate() const
{
#ifndef POCO_DATA_NO_SQL_PARSER
if (_pImpl->session().shouldParse())
return hasType(Parser::StatementType::kStmtUpdate);
else return Optional<bool>();
#else
return Optional<bool>();
#endif
}
Optional<bool> Statement::hasDelete() const
{
#ifndef POCO_DATA_NO_SQL_PARSER
if (_pImpl->session().shouldParse())
return hasType(Parser::StatementType::kStmtDelete);
else return Optional<bool>();
#else
return Optional<bool>();
#endif
}
void Statement::formatQuery() void Statement::formatQuery()
{ {
if (_arguments.size()) if (_arguments.size())