KDbParser
#include <KDbParser.h>
Public Types | |
enum | StatementType { NoType , Select , CreateTable , AlterTable , Insert , Update , Delete } |
Public Member Functions | |
KDbParser (KDbConnection *connection) | |
KDbConnection * | connection () |
const KDbConnection * | connection () const |
KDbParserError | error () const |
bool | parse (const KDbEscapedString &sql, KDbQuerySchema *query=nullptr) |
KDbQuerySchema * | query () |
void | reset () |
KDbEscapedString | statement () const |
StatementType | statementType () const |
QString | statementTypeString () const |
KDbTableSchema * | table () |
Detailed Description
A parser tool for SQL statements.
The KDbParser class offers functionality of a SQL parser for database-backend-independent KDbSQL dialect. Schema objects such as KDbQuerySchema that are created after successful parsing can be then used for running the queries on actual data or used for further modification.
- Todo
Add examples
Support more types than the SELECT
Definition at line 103 of file KDbParser.h.
Member Enumeration Documentation
◆ StatementType
The type of the statement.
Definition at line 111 of file KDbParser.h.
Constructor & Destructor Documentation
◆ KDbParser()
|
explicit |
Constructs an new parser object.
connection is used to obtain context, for example wildcards "T.*" resolution is possible only if information about table T is available.
Definition at line 54 of file KDbParser.cpp.
◆ ~KDbParser()
KDbParser::~KDbParser | ( | ) |
Definition at line 60 of file KDbParser.cpp.
Member Function Documentation
◆ connection() [1/2]
KDbConnection * KDbParser::connection | ( | ) |
- Returns
- a pointer to the used database connection or
nullptr
if it was not set.
Definition at line 90 of file KDbParser.cpp.
◆ connection() [2/2]
const KDbConnection * KDbParser::connection | ( | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Since
- 3.1
Definition at line 95 of file KDbParser.cpp.
◆ error()
KDbParserError KDbParser::error | ( | ) | const |
- Returns
- detailed information about last error. If no error occurred KDbParserError::type() is empty.
Definition at line 100 of file KDbParser.cpp.
◆ parse()
bool KDbParser::parse | ( | const KDbEscapedString & | sql, |
KDbQuerySchema * | query = nullptr ) |
Clears the parser's status and runs the parsing for a raw SQL statement.
If parsing of sql results in a proper query and query is present, it will be set to representation of the parsed query.
- Since
- 3.1
Definition at line 118 of file KDbParser.cpp.
◆ query()
KDbQuerySchema * KDbParser::query | ( | ) |
- Returns
- a pointer to a new query schema created by parsing 'SELECT ...' statement or
nullptr
for any other statements or on error. If existing query was supplied to parse()nullptr
is returned.
- Note
- A proper query schema is returned only once for each successful parse() call, and the object is owned by the caller. In all other cases nullptr is returned.
Definition at line 83 of file KDbParser.cpp.
◆ reset()
void KDbParser::reset | ( | ) |
Reset the parser's status (table, query, error, statement, statement type).
Definition at line 138 of file KDbParser.cpp.
◆ statement()
KDbEscapedString KDbParser::statement | ( | ) | const |
- Returns
- the statement passed on the most recent call of parse().
Definition at line 105 of file KDbParser.cpp.
◆ statementType()
KDbParser::StatementType KDbParser::statementType | ( | ) | const |
- Returns
- the resulting statement type NoType is returned if parsing failed or it has not been yet performed or reset() was called.
Definition at line 65 of file KDbParser.cpp.
◆ statementTypeString()
QString KDbParser::statementTypeString | ( | ) | const |
- Returns
- the resulting statement type as string. It is not translated.
Definition at line 70 of file KDbParser.cpp.
◆ table()
KDbTableSchema * KDbParser::table | ( | ) |
- Returns
- a pointer to a query schema if 'CREATE TABLE ...' statement was parsed or
nullptr
for any other statements or on error.
- Note
- A proper table schema is returned only once for each successful parse() call, and the object is owned by the caller. In all other cases
nullptr
is returned.
- Todo
- Implement this
Definition at line 76 of file KDbParser.cpp.
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:19:08 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.