kexi

parser.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2003 Lucijan Busch <lucijan@kde.org>
00003    Copyright (C) 2004 Jaroslaw Staniek <js@iidea.pl>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #ifndef KEXIDBPARSER_H
00022 #define KEXIDBPARSER_H
00023 
00024 #include <qobject.h>
00025 #include <qptrlist.h>
00026 
00027 #include <kexidb/field.h>
00028 #include <kexidb/expression.h>
00029 
00030 namespace KexiDB
00031 {
00032 
00033 class Connection;
00034 class QuerySchema;
00035 class TableSchema;
00036 class Field;
00037 
00041 class KEXI_DB_EXPORT ParserError
00042 {
00043     public:
00044 
00048         ParserError();
00049 
00058         ParserError(const QString &type, const QString &error, const QString &hint, int at);
00059 
00063         ~ParserError();
00064 
00068         QString type() { return m_type; }
00069 
00073         QString error() { return m_error; }
00074 
00078         int at() { return m_at; }
00079 
00080     private:
00081         QString m_type;
00082         QString m_error;
00083         QString m_hint;
00084         int m_at;
00085 //      bool    m_isNull;
00086 };
00087 
00088 class ParserPrivate;
00089 
00093 class KEXI_DB_EXPORT Parser
00094 {
00095     public:
00096 
00100         enum OPCode
00101         {
00102             OP_None = 0,    
00103             OP_Error,   
00104             OP_CreateTable, 
00105             OP_AlterTable,  
00106             OP_Select,      
00107             OP_Insert,      
00108             OP_Update,      
00109             OP_Delete       
00110         };
00111 
00116         Parser(Connection *connection);
00117         ~Parser();
00118 
00122         bool parse(const QString &statement);
00123 
00127         void clear();
00128 
00132         OPCode operation() const;
00133 
00137                 QString operationString() const;
00138 
00145         TableSchema *table();
00146 
00153         QuerySchema *query();
00154 
00160         Connection  *db() const;
00161 
00166         ParserError error() const;
00167 
00171         QString statement() const;
00172 
00177         void setOperation(OPCode op);
00178 
00183         void createTable(const char *t);
00184 
00189 //todo: other query types
00190         void setQuerySchema(QuerySchema *query);
00191 
00196         QuerySchema *select() const;
00197 
00202         void setError(const ParserError &err);
00203 
00209         bool isReservedKeyword(const char *str);
00210 
00211     protected:
00212         void init();
00213 
00214         ParserError m_error;
00215         ParserPrivate *d;
00216 };
00217 
00218 }
00219 
00220 #endif
00221 
KDE Home | KDE Accessibility Home | Description of Access Keys