~smartboyhw/ubuntu/raring/calligra/2.6.0-0ubuntu1

« back to all changes in this revision

Viewing changes to libs/db/parser/parser.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2012-10-23 21:09:16 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20121023210916-m82w6zxnxhaxz7va
Tags: 1:2.5.90-0ubuntu1
* New upstream alpha release (LP: #1070436)
  - Add libkactivities-dev and libopenimageio-dev to build-depends
  - Add kubuntu_build_calligraactive.diff to build calligraactive by default
  - Add package for calligraauthor and move files that are shared between
    calligrawords and calligraauthor to calligrawords-common
* Document the patches
* Remove numbers from patches so they follow the same naming scheme as
  the rest of our patches.
* calligra-data breaks replaces krita-data (<< 1:2.5.3) (LP: #1071686)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
   Copyright (C) 2003 Lucijan Busch <lucijan@kde.org>
 
3
   Copyright (C) 2004 Jarosław Staniek <staniek@kde.org>
 
4
 
 
5
   This library is free software; you can redistribute it and/or
 
6
   modify it under the terms of the GNU Library General Public
 
7
   License as published by the Free Software Foundation; either
 
8
   version 2 of the License, or (at your option) any later version.
 
9
 
 
10
   This library is distributed in the hope that it will be useful,
 
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
   Library General Public License for more details.
 
14
 
 
15
   You should have received a copy of the GNU Library General Public License
 
16
   along with this library; see the file COPYING.LIB.  If not, write to
 
17
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
18
 * Boston, MA 02110-1301, USA.
 
19
*/
 
20
 
 
21
#include <connection.h>
 
22
#include <tableschema.h>
 
23
#include "parser.h"
 
24
#include "parser_p.h"
 
25
#include "sqlparser.h"
 
26
 
 
27
/*moved to Driver
 
28
#include "tokens.cpp"
 
29
K_GLOBAL_STATIC_WITH_ARGS(StaticSetOfStrings, _reservedKeywords, (_tokens))
 
30
*/
 
31
 
 
32
//--------------------
 
33
 
 
34
using namespace KexiDB;
 
35
 
 
36
Parser::Parser(Connection *db)
 
37
        : d(new Private)
 
38
{
 
39
    d->db = db;
 
40
}
 
41
 
 
42
Parser::~Parser()
 
43
{
 
44
    delete d;
 
45
}
 
46
 
 
47
Parser::OPCode Parser::operation() const
 
48
{
 
49
    return (OPCode)d->operation;
 
50
}
 
51
 
 
52
QString
 
53
Parser::operationString() const
 
54
{
 
55
    switch ((OPCode)d->operation) {
 
56
    case OP_Error:
 
57
        return "Error";
 
58
    case OP_CreateTable:
 
59
        return "CreateTable";
 
60
    case OP_AlterTable:
 
61
        return "AlterTable";
 
62
    case OP_Select:
 
63
        return "Select";
 
64
    case OP_Insert:
 
65
        return "Insert";
 
66
    case OP_Update:
 
67
        return "Update";
 
68
    case OP_Delete:
 
69
        return "Delete";
 
70
    default: //OP_None
 
71
        return "None";
 
72
    }
 
73
}
 
74
 
 
75
TableSchema *Parser::table()
 
76
{
 
77
    TableSchema *t = d->table; d->table = 0; return t;
 
78
}
 
79
 
 
80
QuerySchema *Parser::query()
 
81
{
 
82
    QuerySchema *s = d->select; d->select = 0; return s;
 
83
}
 
84
 
 
85
Connection *Parser::db() const
 
86
{
 
87
    return d->db;
 
88
}
 
89
 
 
90
ParserError Parser::error() const
 
91
{
 
92
    return d->error;
 
93
}
 
94
 
 
95
QString Parser::statement() const
 
96
{
 
97
    return d->statement;
 
98
}
 
99
 
 
100
void Parser::setOperation(OPCode op)
 
101
{
 
102
    d->operation = op;
 
103
}
 
104
 
 
105
QuerySchema *Parser::select() const
 
106
{
 
107
    return d->select;
 
108
}
 
109
 
 
110
void Parser::setError(const ParserError &err)
 
111
{
 
112
    d->error = err;
 
113
}
 
114
 
 
115
void
 
116
Parser::createTable(const char *t)
 
117
{
 
118
    if (d->table)
 
119
        return;
 
120
 
 
121
    d->table = new KexiDB::TableSchema(t);
 
122
}
 
123
 
 
124
void
 
125
Parser::setQuerySchema(QuerySchema *query)
 
126
{
 
127
    if (d->select)
 
128
        delete d->select;
 
129
 
 
130
    d->select = query;
 
131
}
 
132
 
 
133
void Parser::init()
 
134
{
 
135
    if (d->initialized)
 
136
        return;
 
137
    // nothing to do
 
138
    d->initialized = true;
 
139
}
 
140
 
 
141
/*moved to Driver
 
142
bool Parser::isReservedKeyword(const QByteArray& str)
 
143
{
 
144
  return _reservedKeywords->contains(str.toUpper());
 
145
}*/
 
146
 
 
147
bool
 
148
Parser::parse(const QString &statement)
 
149
{
 
150
    init();
 
151
    clear();
 
152
    d->statement = statement;
 
153
 
 
154
    KexiDB::Parser *oldParser = parser;
 
155
    KexiDB::Field *oldField = field;
 
156
    bool res = parseData(this, statement.toUtf8());
 
157
    parser = oldParser;
 
158
    field = oldField;
 
159
    return res;
 
160
}
 
161
 
 
162
void
 
163
Parser::clear()
 
164
{
 
165
    d->clear();
 
166
}
 
167
 
 
168
//-------------------------------------
 
169
 
 
170
ParserError::ParserError()
 
171
        : m_at(-1)
 
172
{
 
173
// m_isNull = true;
 
174
}
 
175
 
 
176
ParserError::ParserError(const QString &type, const QString &error, const QString &hint, int at)
 
177
{
 
178
    m_type = type;
 
179
    m_error = error;
 
180
    m_hint = hint;
 
181
    m_at = at;
 
182
}
 
183
 
 
184
ParserError::~ParserError()
 
185
{
 
186
}
 
187