~ubuntu-branches/ubuntu/wily/tora/wily-proposed

« back to all changes in this revision

Viewing changes to src/tosql.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Meskes
  • Date: 2009-04-07 13:16:05 UTC
  • mfrom: (1.2.7 upstream) (3.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090407131605-u422yigfv7jgg0l0
Tags: 2.0.0-3
* Cleaned up packaging a little bit.
* Added homepage information to control file.
* Bumped Standards-Version to 3.8.1.
* Released to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****
2
 
*
3
 
* TOra - An Oracle Toolkit for DBA's and developers
4
 
* Copyright (C) 2003-2005 Quest Software, Inc
5
 
* Portions Copyright (C) 2005 Other Contributors
6
 
7
 
* This program is free software; you can redistribute it and/or
8
 
* modify it under the terms of the GNU General Public License
9
 
* as published by the Free Software Foundation;  only version 2 of
10
 
* the License is valid for this program.
11
 
12
 
* This program is distributed in the hope that it will be useful,
13
 
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
* GNU General Public License for more details.
16
 
17
 
* You should have received a copy of the GNU General Public License
18
 
* along with this program; if not, write to the Free Software
19
 
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
 
*
21
 
*      As a special exception, you have permission to link this program
22
 
*      with the Oracle Client libraries and distribute executables, as long
23
 
*      as you follow the requirements of the GNU GPL in regard to all of the
24
 
*      software in the executable aside from Oracle client libraries.
25
 
*
26
 
*      Specifically you are not permitted to link this program with the
27
 
*      Qt/UNIX, Qt/Windows or Qt Non Commercial products of TrollTech.
28
 
*      And you are not permitted to distribute binaries compiled against
29
 
*      these libraries without written consent from Quest Software, Inc.
30
 
*      Observe that this does not disallow linking to the Qt Free Edition.
31
 
*
32
 
*      You may link this product with any GPL'd Qt library such as Qt/Free
33
 
*
34
 
* All trademarks belong to their respective owners.
35
 
*
36
 
*****/
 
1
 
 
2
/* BEGIN_COMMON_COPYRIGHT_HEADER
 
3
 *
 
4
 * TOra - An Oracle Toolkit for DBA's and developers
 
5
 * 
 
6
 * Shared/mixed copyright is held throughout files in this product
 
7
 * 
 
8
 * Portions Copyright (C) 2000-2001 Underscore AB
 
9
 * Portions Copyright (C) 2003-2005 Quest Software, Inc.
 
10
 * Portions Copyright (C) 2004-2008 Numerous Other Contributors
 
11
 * 
 
12
 * This program is free software; you can redistribute it and/or
 
13
 * modify it under the terms of the GNU General Public License
 
14
 * as published by the Free Software Foundation;  only version 2 of
 
15
 * the License is valid for this program.
 
16
 * 
 
17
 * This program is distributed in the hope that it will be useful,
 
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
 * GNU General Public License for more details.
 
21
 * 
 
22
 * You should have received a copy of the GNU General Public License
 
23
 * along with this program; if not, write to the Free Software
 
24
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
25
 * 
 
26
 *      As a special exception, you have permission to link this program
 
27
 *      with the Oracle Client libraries and distribute executables, as long
 
28
 *      as you follow the requirements of the GNU GPL in regard to all of the
 
29
 *      software in the executable aside from Oracle client libraries.
 
30
 * 
 
31
 *      Specifically you are not permitted to link this program with the
 
32
 *      Qt/UNIX, Qt/Windows or Qt Non Commercial products of TrollTech.
 
33
 *      And you are not permitted to distribute binaries compiled against
 
34
 *      these libraries. 
 
35
 * 
 
36
 *      You may link this product with any GPL'd Qt library.
 
37
 * 
 
38
 * All trademarks belong to their respective owners.
 
39
 *
 
40
 * END_COMMON_COPYRIGHT_HEADER */
37
41
 
38
42
#include "utils.h"
39
43
 
43
47
#include <qapplication.h>
44
48
#include <qfile.h>
45
49
#include <qregexp.h>
 
50
#include <QString>
46
51
 
47
52
// A little magic to get lrefresh to work and get a check on qApp
48
53
 
53
58
const char * const toSQL::TOSQL_USERLIST = "Global:UserList";
54
59
const char * const toSQL::TOSQL_CREATEPLAN = "Global:CreatePlan";
55
60
 
56
 
toSQL::toSQL(const QCString &name,
 
61
toSQL::toSQL(const QString &name,
57
62
             const QString &sql,
58
63
             const QString &description,
59
 
             const QCString &ver,
60
 
             const QCString &provider)
 
64
             const QString &ver,
 
65
             const QString &provider)
61
66
        : Name(name)
62
67
{
63
68
    updateSQL(name, sql, description, ver, provider, false);
64
69
}
65
70
 
66
 
toSQL::toSQL(const QCString &name)
 
71
toSQL::toSQL(const QString &name)
67
72
        : Name(name)
68
73
{}
69
74
 
73
78
        Definitions = new sqlMap;
74
79
}
75
80
 
76
 
bool toSQL::updateSQL(const QCString &name,
 
81
bool toSQL::updateSQL(const QString &name,
77
82
                      const QString &sql,
78
83
                      const QString &description,
79
 
                      const QCString &ver,
80
 
                      const QCString &provider,
 
84
                      const QString &ver,
 
85
                      const QString &provider,
81
86
                      bool modified)
82
87
{
83
 
#ifdef TO_NO_ORACLE
84
 
    if (provider == "Oracle")
85
 
        return false;
86
 
#endif
87
 
 
88
88
    version def(provider, ver, sql, modified);
89
89
 
90
90
    allocCheck();
93
93
    {
94
94
        if (description.isEmpty())
95
95
        {
96
 
            fprintf(stderr, "ERROR:Tried add new version to unknown SQL (%s)\n", (const char *)name);
 
96
            fprintf(stderr, "ERROR:Tried add new version to unknown SQL (%s)\n", name.toAscii().constData());
97
97
            return false;
98
98
        }
99
99
        definition newDef;
117
117
                (*i).second.Modified = modified;
118
118
            }
119
119
            if (!modified)
120
 
                fprintf(stderr, "ERROR:Overwrite description of nonmodified (%s)\n", (const char *)name);
 
120
                fprintf(stderr, "ERROR:Overwrite description of nonmodified (%s)\n", name.toAscii().constData());
121
121
        }
122
122
        std::list<version> &cl = (*i).second.Versions;
123
123
        for (std::list<version>::iterator j = cl.begin();j != cl.end();j++)
132
132
                }
133
133
                return false;
134
134
            }
135
 
            else if ((*j).Provider > provider.data() ||
136
 
                     ((*j).Provider == provider && (*j).Version > ver.data()))
 
135
            else if ((*j).Provider > provider ||
 
136
                     ((*j).Provider == provider && (*j).Version > ver))
137
137
            {
138
138
                if (!sql.isNull())
139
139
                    cl.insert(j, def);
145
145
    }
146
146
}
147
147
 
148
 
bool toSQL::deleteSQL(const QCString &name,
149
 
                      const QCString &ver,
150
 
                      const QCString &provider)
 
148
bool toSQL::deleteSQL(const QString &name,
 
149
                      const QString &ver,
 
150
                      const QString &provider)
151
151
{
152
152
    allocCheck();
153
153
    sqlMap::iterator i = Definitions->find(name);
167
167
                    Definitions->erase(i);
168
168
                return true;
169
169
            }
170
 
            else if ((*j).Provider > provider.data() ||
171
 
                     ((*j).Provider == provider && (*j).Version > ver.data()))
 
170
            else if ((*j).Provider > provider ||
 
171
                     ((*j).Provider == provider && !(*j).Version.isNull()))
172
172
            {
173
173
                return false;
174
174
            }
177
177
    }
178
178
}
179
179
 
180
 
toSQL toSQL::sql(const QCString &name)
 
180
toSQL toSQL::sql(const QString &name)
181
181
{
182
182
    allocCheck();
183
183
    sqlMap::iterator i = Definitions->find(name);
184
184
    if (i != Definitions->end())
185
185
        return name;
186
 
    throw qApp->translate("toSQL", "Tried to get unknown SQL (%1)").arg(name);
 
186
    throw qApp->translate("toSQL", "Tried to get unknown SQL (%1)").arg(QString(name));
187
187
}
188
188
 
189
 
QString toSQL::string(const QCString &name,
 
189
QString toSQL::string(const QString &name,
190
190
                      const toConnection &conn)
191
191
{
192
192
    allocCheck();
193
 
    QCString ver = conn.version();
194
 
    QCString prov = conn.provider();
 
193
    QString ver = conn.version();
 
194
    QString prov = conn.provider();
195
195
 
196
196
    bool quit = false;
197
197
 
208
208
            {
209
209
                if ((*j).Provider == prov)
210
210
                {
211
 
                    if ((*j).Version <= ver.data() || !sql)
 
211
                    if ((*j).Version <= ver || !sql)
212
212
                    {
213
213
                        sql = &(*j).SQL;
214
214
                    }
215
 
                    if ((*j).Version >= ver.data())
 
215
                    if ((*j).Version >= ver)
216
216
                        return *sql;
217
217
                }
218
218
            }
224
224
        while (!quit);
225
225
    }
226
226
 
227
 
    throw qApp->translate("toSQL", "Tried to get unknown SQL (%1)").arg(name);
 
227
    throw qApp->translate("toSQL", "Tried to get unknown SQL (%1)").arg(QString(name));
228
228
}
229
229
 
230
230
bool toSQL::saveSQL(const QString &filename, bool all)
231
231
{
232
232
    allocCheck();
233
 
    QCString data;
 
233
    QString data;
234
234
 
235
235
    QRegExp backslash(QString::fromLatin1("\\"));
236
236
    QRegExp newline(QString::fromLatin1("\n"));
237
237
    for (sqlMap::iterator i = Definitions->begin();i != Definitions->end();i++)
238
238
    {
239
 
        QCString str;
 
239
        QString str;
240
240
        definition &def = (*i).second;
241
 
        QCString name = (*i).first;
 
241
        QString name = (*i).first;
242
242
        if (def.Modified || all)
243
243
        {
244
 
            QCString line = name;
 
244
            QString line = name;
245
245
            line += "=";
246
246
            QString t = def.Description;
247
247
            t.replace(backslash, QString::fromLatin1("\\\\"));
255
255
            version &ver = (*j);
256
256
            if (ver.Modified || all)
257
257
            {
258
 
                QCString line = name;
 
258
                QString line = name;
259
259
                line += "[";
260
260
                line += ver.Version;
261
261
                line += "][";
277
277
void toSQL::loadSQL(const QString &filename)
278
278
{
279
279
    allocCheck();
280
 
    QCString data = toReadFile(filename);
 
280
    QByteArray data = toReadFile(filename).toUtf8();
281
281
 
282
282
    int size = data.length();
283
283
    int pos = 0;
295
295
                throw QT_TRANSLATE_NOOP("toSQL", "Malformed tag in config file. Missing = on row.");
296
296
            data[wpos] = 0;
297
297
            {
298
 
                QCString nam = ((const char *)data) + bol;
 
298
                QString nam = ((const char *)data) + bol;
299
299
                QString val(QString::fromUtf8(((const char *)data) + endtag + 1));
300
 
                QCString ver;
301
 
                QCString prov;
 
300
                QString ver;
 
301
                QString prov;
302
302
                if (vertag >= 0)
303
303
                {
304
304
                    ver = ((const char *)data) + vertag + 1;
374
374
    }
375
375
}
376
376
 
377
 
std::list<QCString> toSQL::range(const QCString &startWith)
 
377
std::list<QString> toSQL::range(const QString &startWith)
378
378
{
379
 
    std::list<QCString> ret;
 
379
    std::list<QString> ret;
380
380
    for (sqlMap::iterator i = Definitions->begin();i != Definitions->end();i++)
381
381
    {
382
 
        if ((*i).first > startWith.data() || startWith.isNull())
 
382
        if ((*i).first > startWith || startWith.isNull())
383
383
        {
384
384
            if ((*i).first.mid(0, startWith.length()) == startWith || startWith.isNull())
385
385
                ret.insert(ret.end(), (*i).first);
390
390
    return ret;
391
391
}
392
392
 
393
 
QString toSQL::description(const QCString &name)
 
393
QString toSQL::description(const QString &name)
394
394
{
395
395
    allocCheck();
396
396
    sqlMap::iterator i = Definitions->find(name);
397
397
    if (i != Definitions->end())
398
398
        return (*i).second.Description;
399
 
    throw qApp->translate("toSQL", "Tried to get unknown SQL (%1)").arg(name);
 
399
    throw qApp->translate("toSQL", "Tried to get unknown SQL (%1)").arg(QString(name));
400
400
}