Search for usage in LXR

#include <KDbParser.h>

Public Types

enum  StatementType {
  NoType, Select, CreateTable, AlterTable,
  Insert, Update, Delete

Public Member Functions

 KDbParser (KDbConnection *connection)
KDbConnectionconnection ()
const KDbConnectionconnection () const
KDbParserError error () const
bool parse (const KDbEscapedString &sql, KDbQuerySchema *query=nullptr)
KDbQuerySchemaquery ()
void reset ()
KDbEscapedString statement () const
StatementType statementType () const
QString statementTypeString () const
KDbTableSchematable ()

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.


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.


No statement type specified or detected.




Create a new table.


Alter schema of an existing table.


Insert new records.


Update existing records.


Delete existing records.

Definition at line 111 of file KDbParser.h.

Constructor & Destructor Documentation

◆ KDbParser()

KDbParser::KDbParser ( KDbConnection connection)

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.

Member Function Documentation

◆ connection() [1/2]

const KDbConnection * KDbParser::connection ( )
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.


◆ error()

KDbParserError KDbParser::error ( ) const
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.


Definition at line 118 of file KDbParser.cpp.

◆ query()

KDbQuerySchema * KDbParser::query ( )
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.
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
the statement passed on the most recent call of parse().

Definition at line 105 of file KDbParser.cpp.

◆ statementType()

KDbParser::StatementType KDbParser::statementType ( ) const
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
the resulting statement type as string. It is not translated.

Definition at line 70 of file KDbParser.cpp.

◆ table()

KDbTableSchema * KDbParser::table ( )
a pointer to a query schema if 'CREATE TABLE ...' statement was parsed or nullptr for any other statements or on error.
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.
Implement this

Definition at line 76 of file KDbParser.cpp.

The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Oct 3 2023 04:09:18 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.