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 #include <qvariant.h>
00027 
00028 #include <kexidb/field.h>
00029 #include <kexidb/expression.h>
00030 
00031 namespace KexiDB
00032 {
00033 
00034 class Connection;
00035 class QuerySchema;
00036 class TableSchema;
00037 class Field;
00038 
00042 class KEXI_DB_EXPORT ParserError
00043 {
00044     public:
00045 
00049         ParserError();
00050 
00059         ParserError(const QString &type, const QString &error, const QString &hint, int at);
00060 
00064         ~ParserError();
00065 
00069         QString type() { return m_type; }
00070 
00074         QString error() { return m_error; }
00075 
00079         int at() { return m_at; }
00080 
00081     private:
00082         QString m_type;
00083         QString m_error;
00084         QString m_hint;
00085         int m_at;
00086 //      bool    m_isNull;
00087 };
00088 
00089 class ParserPrivate;
00090 
00112 class KEXI_DB_EXPORT Parser
00113 {
00114     public:
00115 
00119         enum OPCode
00120         {
00121             OP_None = 0, 
00122             OP_Error, 
00123             OP_CreateTable, 
00124             OP_AlterTable, 
00125             OP_Select, 
00126             OP_Insert, 
00127             OP_Update, 
00128             OP_Delete  
00129         };
00130 
00135         Parser(Connection *connection);
00136         ~Parser();
00137 
00141         bool parse(const QString &statement);
00142 
00146         void clear();
00147 
00151         OPCode operation() const;
00152 
00156         QString operationString() const;
00157 
00164         TableSchema *table();
00165 
00172         QuerySchema *query();
00173 
00179         Connection  *db() const;
00180 
00185         ParserError error() const;
00186 
00190         QString statement() const;
00191 
00196         void setOperation(OPCode op);
00197 
00202         void createTable(const char *t);
00203 
00208 //todo: other query types
00209         void setQuerySchema(QuerySchema *query);
00210 
00215         QuerySchema *select() const;
00216 
00221         void setError(const ParserError &err);
00222 
00228         bool isReservedKeyword(const char *str);
00229 
00230     protected:
00231         void init();
00232 
00233         ParserError m_error; 
00234         ParserPrivate *d; 
00235 };
00236 
00237 }
00238 
00239 #endif
00240 
KDE Home | KDE Accessibility Home | Description of Access Keys