#include <parser.h>

Public Types

enum  OPCode {
  OP_None = 0 , OP_Error , OP_CreateTable , OP_AlterTable ,
  OP_Select , OP_Insert , OP_Update , OP_Delete
}
 

Public Member Functions

 Parser (Connection *connection)
 
bool parse (const TQString &statement)
 
void clear ()
 
OPCode operation () const
 
TQString operationString () const
 
TableSchema * table ()
 
QuerySchema * query ()
 
Connection * db () const
 
ParserError error () const
 
TQString statement () const
 
void setOperation (OPCode op)
 
void createTable (const char *t)
 
void setQuerySchema (QuerySchema *query)
 
QuerySchema * select () const
 
void setError (const ParserError &err)
 
bool isReservedKeyword (const char *str)
 

Protected Member Functions

void init ()
 

Protected Attributes

ParserError m_error
 
ParserPrivate * d
 

Detailed Description

Parser for SQL statements.

The best and prefeerred way to run queries is using the KexiDB::Parser functionality and use the resulting QuerySchema object since this offers a database-backend-independent way to deal with SQL statements on the one hand and offers high level functionality on the other. Also BLOBs like images are handled that way.

For example if we like to use the SELECT statement "SELECT dir.path, media.filename FROM dir, media WHERE dir.id=media.dirId AND media.id=%s" we are able to use the Connection::prepareStatement method which takes the type of the statement (in our case PreparedStatement::SelectStatement ), a list of fields (in our case dir.path and media.filename) and returns a PreparedStatement::Ptr instance. By using the QuerySchema::addRelationship and QuerySchema::addToWhereExpression methods the SQL statement could be extended with relationships and WHERE expressions.

For more, see KexiDB::PreparedStatement and Connection::selectStatement() . A more complex example that looks at what the user has defined and carefully builds KexiDB::QuerySchema object, including the WHERE expression can be found in the Query Designer's source code in the method KexiQueryDesignerGuiEditor::buildSchema().

Definition at line 112 of file parser.h.

Member Enumeration Documentation

◆ OPCode

The operation-code of the statement.

Enumerator
OP_Error 

No statement parsed or reseted.

OP_CreateTable 

Error while parsing.

OP_AlterTable 

Create a table.

OP_Select 

Alter an existing table.

OP_Insert 

Query-statement.

OP_Update 

Insert new content.

OP_Delete 

Update existing content.

Delete existing content.

Definition at line 119 of file parser.h.

Constructor & Destructor Documentation

◆ Parser()

Parser::Parser ( Connection *  connection)

constructs an empty object of the parser

Parameters
connectionis used for things like wildcard resolution. If 0 parser works in "pure mode"

Definition at line 31 of file parser.cpp.

◆ ~Parser()

Parser::~Parser ( )

Definition at line 37 of file parser.cpp.

Member Function Documentation

◆ clear()

void Parser::clear ( )

rests results

Definition at line 131 of file parser.cpp.

◆ createTable()

void Parser::createTable ( const char *  t)

Definition at line 84 of file parser.cpp.

◆ db()

Connection * Parser::db ( ) const
Returns
a pointer to the used database connection or 0 if not set You can call this method only once every time after doing parse(). Next time, the call will return 0.

Definition at line 71 of file parser.cpp.

◆ error()

ParserError Parser::error ( ) const
Returns
detailed information about last error. If no error occurred ParserError isNull()

Definition at line 73 of file parser.cpp.

◆ init()

void Parser::init ( )
protected

Definition at line 101 of file parser.cpp.

◆ isReservedKeyword()

bool Parser::isReservedKeyword ( const char *  str)
Returns
true if the
Parameters
stris an reserved keyword (see tokens.cpp for a list of reserved keywords).

Definition at line 110 of file parser.cpp.

◆ operation()

Parser::OPCode Parser::operation ( ) const
Returns
the resulting operation or OP_Error if failed

Definition at line 42 of file parser.cpp.

◆ operationString()

TQString Parser::operationString ( ) const
Returns
the resulting operation as string.

Definition at line 45 of file parser.cpp.

◆ parse()

bool Parser::parse ( const TQString &  statement)

clears previous results and runs the parser

Definition at line 116 of file parser.cpp.

◆ query()

QuerySchema * Parser::query ( )
Returns
a pointer to KexiDBSelect if 'SELECT ...' was called or 0 on any other operation or error. Returned object is owned by you. You can call this method only once every time after doing parse(). Next time, the call will return 0.

Definition at line 69 of file parser.cpp.

◆ select()

QuerySchema * Parser::select ( ) const

Definition at line 79 of file parser.cpp.

◆ setError()

void Parser::setError ( const ParserError &  err)

Definition at line 81 of file parser.cpp.

◆ setOperation()

void Parser::setOperation ( OPCode  op)

Definition at line 77 of file parser.cpp.

◆ setQuerySchema()

void Parser::setQuerySchema ( QuerySchema *  query)

Definition at line 93 of file parser.cpp.

◆ statement()

TQString Parser::statement ( ) const
Returns
the statement passed on the last parse method-call.

Definition at line 75 of file parser.cpp.

◆ table()

TableSchema * Parser::table ( )
Returns
a pointer to a KexiDBTable on CREATE TABLE or 0 on any other operation or error. Returned object is owned by you. You can call this method only once every time after doing parse(). Next time, the call will return 0.

Definition at line 67 of file parser.cpp.

Member Data Documentation

◆ d

ParserPrivate* KexiDB::Parser::d
protected

Definition at line 234 of file parser.h.

◆ m_error

ParserError KexiDB::Parser::m_error
protected

detailed information about last error.

Definition at line 233 of file parser.h.


The documentation for this class was generated from the following files: