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

« back to all changes in this revision

Viewing changes to toconnection.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Albin Tonnerre
  • Date: 2007-05-29 13:13:36 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070529131336-85ygaddivvmkd3xc
Tags: 1.3.21pre22-1ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes:
  - debian/rules: call dh_iconcache
  - Remove g++ build dependency
* Modify Maintainer value to match Debian-Maintainer-Field Spec

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
 
*****/
37
 
 
38
 
#include "utils.h"
39
 
 
40
 
#include "toconf.h"
41
 
#include "toconnection.h"
42
 
#include "tohighlightedtext.h"
43
 
#include "tomain.h"
44
 
#include "tosql.h"
45
 
#include "totool.h"
46
 
 
47
 
#include <string>
48
 
#include <time.h>
49
 
 
50
 
#include <qapplication.h>
51
 
#include <qdir.h>
52
 
#include <qprogressdialog.h>
53
 
#include <qtextstream.h>
54
 
#include <qwidget.h>
55
 
 
56
 
// A little magic to get lrefresh to work and get a check on qApp
57
 
 
58
 
#undef QT_TRANSLATE_NOOP
59
 
#define QT_TRANSLATE_NOOP(x,y) QTRANS(x,y)
60
 
 
61
 
#define TO_DEBUGOUT(x) fprintf(stderr,(const char *)x);
62
 
 
63
 
// Connection provider implementation
64
 
 
65
 
std::map<QCString, toConnectionProvider *> *toConnectionProvider::Providers;
66
 
std::map<QCString, toConnectionProvider *> *toConnectionProvider::Types;
67
 
 
68
 
static int NumberFormat;
69
 
static int NumberDecimals;
70
 
 
71
 
void toConnectionProvider::checkAlloc(void)
72
 
{
73
 
    if (!Providers)
74
 
        Providers = new std::map<QCString, toConnectionProvider *>;
75
 
}
76
 
 
77
 
void toConnectionProvider::addProvider(const QCString &provider)
78
 
{
79
 
    checkAlloc();
80
 
    Provider = provider;
81
 
    (*Providers)[Provider] = this;
82
 
}
83
 
 
84
 
toConnectionProvider::toConnectionProvider(const QCString &provider, bool add
85
 
                                              )
86
 
{
87
 
    Provider = provider;
88
 
    if (add
89
 
       )
90
 
        addProvider(provider);
91
 
    if (!Types)
92
 
        Types = new std::map<QCString, toConnectionProvider *>;
93
 
    (*Types)[provider] = this;
94
 
}
95
 
 
96
 
std::list<QString> toConnectionProvider::providedOptions(const QCString &)
97
 
{
98
 
    std::list<QString> ret;
99
 
    return ret;
100
 
}
101
 
 
102
 
void toConnectionProvider::removeProvider(const QCString &provider)
103
 
{
104
 
    std::map<QCString, toConnectionProvider *>::iterator i = Providers->find(provider);
105
 
    if (i != Providers->end())
106
 
        Providers->erase(i);
107
 
}
108
 
 
109
 
toConnectionProvider::~toConnectionProvider()
110
 
{
111
 
    try
112
 
    {
113
 
        if (!Provider.isEmpty())
114
 
            removeProvider(Provider);
115
 
        std::map<QCString, toConnectionProvider *>::iterator i = Types->find(Provider);
116
 
        if (i != Types->end())
117
 
            Types->erase(i);
118
 
    }
119
 
    catch (...)
120
 
    {}
121
 
}
122
 
 
123
 
std::list<QString> toConnectionProvider::providedHosts(const QCString &)
124
 
{
125
 
    std::list<QString> ret;
126
 
    return ret;
127
 
}
128
 
 
129
 
std::list<QCString> toConnectionProvider::providers()
130
 
{
131
 
    std::list<QCString> ret;
132
 
    if (!Providers)
133
 
        return ret;
134
 
    for (std::map<QCString, toConnectionProvider *>::iterator i = Providers->begin();i != Providers->end();i++)
135
 
        ret.insert(ret.end(), (*i).first);
136
 
    return ret;
137
 
}
138
 
 
139
 
void toConnectionProvider::initializeAll(void)
140
 
{
141
 
    if (Types)
142
 
        for (std::map<QCString, toConnectionProvider *>::iterator i = Types->begin();
143
 
                i != Types->end();i++)
144
 
            (*i).second->initialize();
145
 
}
146
 
 
147
 
toConnectionProvider &toConnectionProvider::fetchProvider(const QCString &provider)
148
 
{
149
 
    checkAlloc();
150
 
    std::map<QCString, toConnectionProvider *>::iterator i = Providers->find(provider);
151
 
    if (i == Providers->end())
152
 
        throw QT_TRANSLATE_NOOP("toConnectionProvider", "Tried to fetch unknown provider %1").arg(provider);
153
 
    return *((*i).second);
154
 
}
155
 
 
156
 
std::list<QString> toConnectionProvider::options(const QCString &provider)
157
 
{
158
 
    return fetchProvider(provider).providedOptions(provider);
159
 
}
160
 
 
161
 
QWidget *toConnectionProvider::configurationTab(const QCString &provider, QWidget *parent)
162
 
{
163
 
    return fetchProvider(provider).providerConfigurationTab(provider, parent);
164
 
}
165
 
 
166
 
toConnection::connectionImpl *toConnectionProvider::connection(const QCString &provider,
167
 
        toConnection *conn)
168
 
{
169
 
    return fetchProvider(provider).provideConnection(provider, conn);
170
 
}
171
 
 
172
 
std::list<QString> toConnectionProvider::hosts(const QCString &provider)
173
 
{
174
 
    return fetchProvider(provider).providedHosts(provider);
175
 
}
176
 
 
177
 
std::list<QString> toConnectionProvider::databases(const QCString &provider, const QString &host,
178
 
        const QString &user, const QString &pwd)
179
 
{
180
 
    return fetchProvider(provider).providedDatabases(provider, host, user, pwd);
181
 
}
182
 
 
183
 
const QString &toConnectionProvider::config(const QCString &tag, const QCString &def)
184
 
{
185
 
    QCString str = Provider;
186
 
    str.append(":");
187
 
    str.append(tag);
188
 
    return toTool::globalConfig(str, def);
189
 
}
190
 
 
191
 
void toConnectionProvider::setConfig(const QCString &tag, const QCString &def)
192
 
{
193
 
    QCString str = Provider;
194
 
    str.append(":");
195
 
    str.append(tag);
196
 
    toTool::globalSetConfig(str, def);
197
 
}
198
 
 
199
 
QWidget *toConnectionProvider::providerConfigurationTab(const QCString &, QWidget *)
200
 
{
201
 
    return NULL;
202
 
}
203
 
 
204
 
// Query value implementation
205
 
 
206
 
toQValue::toQValue(int i)
207
 
{
208
 
    Type = intType;
209
 
    Value.Int = i;
210
 
}
211
 
 
212
 
toQValue::toQValue(double i)
213
 
{
214
 
    Type = doubleType;
215
 
    Value.Double = i;
216
 
}
217
 
 
218
 
toQValue::toQValue(const toQValue &copy)
219
 
{
220
 
    Type = copy.Type;
221
 
    switch (Type)
222
 
    {
223
 
    case intType:
224
 
        Value.Int = copy.Value.Int;
225
 
        break;
226
 
    case doubleType:
227
 
        Value.Double = copy.Value.Double;
228
 
        break;
229
 
    case stringType:
230
 
        Value.String = new QString(*copy.Value.String);
231
 
        break;
232
 
    case binaryType:
233
 
        Value.Array = new QByteArray(*copy.Value.Array);
234
 
        break;
235
 
    case nullType:
236
 
        break;
237
 
    }
238
 
}
239
 
 
240
 
const toQValue &toQValue::operator = (const toQValue &copy)
241
 
{
242
 
    if (Type == stringType)
243
 
        delete Value.String;
244
 
    else if (Type == binaryType)
245
 
        delete Value.Array;
246
 
 
247
 
    Type = copy.Type;
248
 
    switch (Type)
249
 
    {
250
 
    case intType:
251
 
        Value.Int = copy.Value.Int;
252
 
        break;
253
 
    case doubleType:
254
 
        Value.Double = copy.Value.Double;
255
 
        break;
256
 
    case stringType:
257
 
        Value.String = new QString(*copy.Value.String);
258
 
        break;
259
 
    case binaryType:
260
 
        Value.Array = new QByteArray(*copy.Value.Array);
261
 
        break;
262
 
    case nullType:
263
 
        break;
264
 
    }
265
 
    return *this;
266
 
}
267
 
 
268
 
bool toQValue::operator == (const toQValue &val) const
269
 
{
270
 
    if (isNull() && val.isNull())
271
 
        return true;
272
 
    if (val.Type != Type)
273
 
        return false;
274
 
    switch (Type)
275
 
    {
276
 
    case intType:
277
 
        return (val.Value.Int == Value.Int);
278
 
    case doubleType:
279
 
        return (val.Value.Double == Value.Double);
280
 
    case stringType:
281
 
        return (*val.Value.String) == (*Value.String);
282
 
    case binaryType:
283
 
        return (*val.Value.Array) == (*Value.Array);
284
 
    case nullType:
285
 
        break;
286
 
    }
287
 
    return false;  // Should never get here
288
 
}
289
 
 
290
 
toQValue::toQValue(const QString &str)
291
 
{
292
 
    Type = stringType;
293
 
    Value.String = new QString(str);
294
 
}
295
 
 
296
 
toQValue::toQValue(void)
297
 
{
298
 
    Type = nullType;
299
 
}
300
 
 
301
 
toQValue::~toQValue()
302
 
{
303
 
    if (Type == stringType)
304
 
        delete Value.String;
305
 
    else if (Type == binaryType)
306
 
        delete Value.Array;
307
 
}
308
 
 
309
 
bool toQValue::isInt(void) const
310
 
{
311
 
    return Type == intType;
312
 
}
313
 
 
314
 
bool toQValue::isDouble(void) const
315
 
{
316
 
    return Type == doubleType;
317
 
}
318
 
 
319
 
bool toQValue::isString(void) const
320
 
{
321
 
    return Type == stringType;
322
 
}
323
 
 
324
 
bool toQValue::isBinary(void) const
325
 
{
326
 
    return Type == binaryType;
327
 
}
328
 
 
329
 
bool toQValue::isNull(void) const
330
 
{
331
 
    if (Type == nullType)
332
 
        return true;
333
 
    if (Type == stringType && Value.String->isNull())
334
 
        return true;
335
 
    return false;
336
 
}
337
 
 
338
 
const QByteArray &toQValue::toByteArray() const
339
 
{
340
 
    if (Type != binaryType)
341
 
        throw qApp->translate("toQValue", "Tried to convert non binary value to binary");
342
 
    return *Value.Array;
343
 
}
344
 
 
345
 
static char HexString[] = "0123456789ABCDEF";
346
 
 
347
 
QCString toQValue::utf8(void) const
348
 
{
349
 
    switch (Type)
350
 
    {
351
 
    case nullType:
352
 
        {
353
 
            QCString ret;
354
 
            return ret;
355
 
        }
356
 
    case intType:
357
 
        {
358
 
            QCString ret;
359
 
            ret.setNum(Value.Int);
360
 
            return ret;
361
 
        }
362
 
    case doubleType:
363
 
        {
364
 
            QCString ret;
365
 
            if (Value.Double != int(Value.Double))
366
 
            {
367
 
                ret.setNum(Value.Double);
368
 
                return ret;
369
 
            }
370
 
            char buf[100];
371
 
            switch (NumberFormat)
372
 
            {
373
 
            default:
374
 
                ret.setNum(Value.Double);
375
 
                break;
376
 
            case 1:
377
 
                sprintf(buf, "%E", Value.Double);
378
 
                ret = buf;
379
 
                break;
380
 
            case 2:
381
 
                sprintf(buf, "%0.*f", NumberDecimals, Value.Double);
382
 
                ret = buf;
383
 
                break;
384
 
            }
385
 
            return ret;
386
 
        }
387
 
    case stringType:
388
 
        return Value.String->utf8();
389
 
    case binaryType:
390
 
        {
391
 
            QCString ret(Value.Array->size()*2 + 1);
392
 
            for (unsigned int i = 0;i < Value.Array->size();i++)
393
 
            {
394
 
                unsigned char c = (unsigned char)Value.Array->at(i);
395
 
                ret.at(i*2) = HexString[(c / 16) % 16];
396
 
                ret.at(i*2 + 1) = HexString[c % 16];
397
 
            }
398
 
            ret.at(Value.Array->size()*2) = 0;
399
 
            return ret;
400
 
        }
401
 
    }
402
 
    throw qApp->translate("toQValue", "Unknown type of query value");
403
 
}
404
 
 
405
 
int toQValue::toInt(void) const
406
 
{
407
 
    switch (Type)
408
 
    {
409
 
    case nullType:
410
 
        return 0;
411
 
    case intType:
412
 
        return Value.Int;
413
 
    case doubleType:
414
 
        return int(Value.Double);
415
 
    case stringType:
416
 
        return Value.String->toInt();
417
 
    case binaryType:
418
 
        throw qApp->translate("toQValue", "Can't transform binary value to int");
419
 
    }
420
 
    throw qApp->translate("toQValue", "Unknown type of query value");
421
 
}
422
 
 
423
 
double toQValue::toDouble(void) const
424
 
{
425
 
    switch (Type)
426
 
    {
427
 
    case nullType:
428
 
        return 0;
429
 
    case intType:
430
 
        return double(Value.Int);
431
 
    case doubleType:
432
 
        return Value.Double;
433
 
    case stringType:
434
 
        return Value.String->toDouble();
435
 
    case binaryType:
436
 
        throw qApp->translate("toQValue", "Can't transform binary value to double");
437
 
    }
438
 
    throw qApp->translate("toQValue", "Unknown type of query value");
439
 
}
440
 
 
441
 
void toQValue::setNumberFormat(int format, int decimals)
442
 
{
443
 
    NumberFormat = format;
444
 
    NumberDecimals = decimals;
445
 
}
446
 
 
447
 
QString toQValue::formatNumber(double number)
448
 
{
449
 
    if (number == int(number))
450
 
        return QString::number(number);
451
 
    switch (NumberFormat)
452
 
    {
453
 
    case 1:
454
 
        {
455
 
            char buf[100];
456
 
            sprintf(buf, "%E", number);
457
 
            return buf;
458
 
        }
459
 
    case 2:
460
 
        {
461
 
            char buf[100];
462
 
            sprintf(buf, "%0.*f", NumberDecimals, number);
463
 
            return buf;
464
 
        }
465
 
    default:
466
 
        return QString::number(number);
467
 
    }
468
 
}
469
 
 
470
 
int toQValue::numberFormat(void)
471
 
{
472
 
    return NumberFormat;
473
 
}
474
 
 
475
 
int toQValue::numberDecimals(void)
476
 
{
477
 
    return NumberDecimals;
478
 
}
479
 
 
480
 
toQValue toQValue::createBinary(const QByteArray &arr)
481
 
{
482
 
    toQValue ret;
483
 
    ret.Type = binaryType;
484
 
    ret.Value.Array = new QByteArray(arr);
485
 
    return ret;
486
 
}
487
 
 
488
 
toQValue toQValue::createFromHex(const QCString &hex)
489
 
{
490
 
    QByteArray arr((hex.length() + 1) / 2);
491
 
    for (unsigned int i = 0;i < hex.length();i += 2)
492
 
    {
493
 
        int num;
494
 
        char c = hex.at(i);
495
 
        if (c >= 'a')
496
 
            num = c - 'a';
497
 
        else if (c >= 'A')
498
 
            num = c - 'A';
499
 
        else
500
 
            num = c - '0';
501
 
        num <<= 4;
502
 
        c = hex.at(i + 1);
503
 
        if (c >= 'a')
504
 
            num += c - 'a';
505
 
        else if (c >= 'A')
506
 
            num += c - 'A';
507
 
        else
508
 
            num += c - '0';
509
 
        arr.at(i / 2) = num;
510
 
    }
511
 
    return createBinary(arr);
512
 
}
513
 
 
514
 
toQValue toQValue::createFromHex(const QString &hex)
515
 
{
516
 
    QByteArray arr((hex.length() + 1) / 2);
517
 
    for (unsigned int i = 0;i < hex.length();i += 2)
518
 
    {
519
 
        int num;
520
 
        char c = hex.at(i);
521
 
        if (c >= 'a')
522
 
            num = c - 'a';
523
 
        else if (c >= 'A')
524
 
            num = c - 'A';
525
 
        else
526
 
            num = c - '0';
527
 
        num <<= 4;
528
 
        c = hex.at(i + 1);
529
 
        if (c >= 'a')
530
 
            num += c - 'a';
531
 
        else if (c >= 'A')
532
 
            num += c - 'A';
533
 
        else
534
 
            num += c - '0';
535
 
        arr.at(i / 2) = num;
536
 
    }
537
 
    return createBinary(arr);
538
 
}
539
 
 
540
 
toQValue::operator QString() const
541
 
{
542
 
    switch (Type)
543
 
    {
544
 
    case nullType:
545
 
        return QString::null;
546
 
    case doubleType:
547
 
        return formatNumber(Value.Double);
548
 
    case intType:
549
 
        return QString::number(Value.Int);
550
 
    case stringType:
551
 
        return *Value.String;
552
 
    case binaryType:
553
 
        {
554
 
            QString ret;
555
 
            for (unsigned int i = 0;i < Value.Array->size();i++)
556
 
            {
557
 
                unsigned char c = (unsigned char)Value.Array->at(i);
558
 
                ret += HexString[(c / 16) % 16];
559
 
                ret += HexString[c % 16];
560
 
            }
561
 
            return ret;
562
 
        }
563
 
    }
564
 
    throw qApp->translate("toQValue", "Unknown type of query value");
565
 
}
566
 
 
567
 
// toQuery implementation
568
 
 
569
 
toQuery::toQuery(toConnection &conn, const toSQL &sql,
570
 
                 const QString &arg1, const QString &arg2,
571
 
                 const QString &arg3, const QString &arg4,
572
 
                 const QString &arg5, const QString &arg6,
573
 
                 const QString &arg7, const QString &arg8,
574
 
                 const QString &arg9)
575
 
        : Connection(conn), ConnectionSub(conn.mainConnection()), SQL(sql(Connection))
576
 
{
577
 
    Mode = Normal;
578
 
    int numArgs;
579
 
    if (!arg9.isNull())
580
 
        numArgs = 9;
581
 
    else if (!arg8.isNull())
582
 
        numArgs = 8;
583
 
    else if (!arg7.isNull())
584
 
        numArgs = 7;
585
 
    else if (!arg6.isNull())
586
 
        numArgs = 6;
587
 
    else if (!arg5.isNull())
588
 
        numArgs = 5;
589
 
    else if (!arg4.isNull())
590
 
        numArgs = 4;
591
 
    else if (!arg3.isNull())
592
 
        numArgs = 3;
593
 
    else if (!arg2.isNull())
594
 
        numArgs = 2;
595
 
    else if (!arg1.isNull())
596
 
        numArgs = 1;
597
 
    else
598
 
        numArgs = 0;
599
 
 
600
 
    if (numArgs > 0)
601
 
        Params.insert(Params.end(), arg1);
602
 
    if (numArgs > 1)
603
 
        Params.insert(Params.end(), arg2);
604
 
    if (numArgs > 2)
605
 
        Params.insert(Params.end(), arg3);
606
 
    if (numArgs > 3)
607
 
        Params.insert(Params.end(), arg4);
608
 
    if (numArgs > 4)
609
 
        Params.insert(Params.end(), arg5);
610
 
    if (numArgs > 5)
611
 
        Params.insert(Params.end(), arg6);
612
 
    if (numArgs > 6)
613
 
        Params.insert(Params.end(), arg7);
614
 
    if (numArgs > 7)
615
 
        Params.insert(Params.end(), arg8);
616
 
    if (numArgs > 8)
617
 
        Params.insert(Params.end(), arg9);
618
 
 
619
 
    toBusy busy;
620
 
    try
621
 
    {
622
 
        Query = NULL;
623
 
        Query = conn.Connection->createQuery(this, ConnectionSub);
624
 
        Query->execute();
625
 
    }
626
 
    catch (...)
627
 
    {
628
 
        delete Query;
629
 
        Query = NULL;
630
 
        Connection.freeConnection(ConnectionSub);
631
 
        throw;
632
 
    }
633
 
    ConnectionSub->setQuery(this);
634
 
}
635
 
 
636
 
toQuery::toQuery(toConnection &conn, const QString &sql,
637
 
                 const QString &arg1, const QString &arg2,
638
 
                 const QString &arg3, const QString &arg4,
639
 
                 const QString &arg5, const QString &arg6,
640
 
                 const QString &arg7, const QString &arg8,
641
 
                 const QString &arg9)
642
 
        : Connection(conn), ConnectionSub(conn.mainConnection()), SQL(sql.utf8())
643
 
{
644
 
    Mode = Normal;
645
 
    int numArgs;
646
 
    if (!arg9.isNull())
647
 
        numArgs = 9;
648
 
    else if (!arg8.isNull())
649
 
        numArgs = 8;
650
 
    else if (!arg7.isNull())
651
 
        numArgs = 7;
652
 
    else if (!arg6.isNull())
653
 
        numArgs = 6;
654
 
    else if (!arg5.isNull())
655
 
        numArgs = 5;
656
 
    else if (!arg4.isNull())
657
 
        numArgs = 4;
658
 
    else if (!arg3.isNull())
659
 
        numArgs = 3;
660
 
    else if (!arg2.isNull())
661
 
        numArgs = 2;
662
 
    else if (!arg1.isNull())
663
 
        numArgs = 1;
664
 
    else
665
 
        numArgs = 0;
666
 
 
667
 
    if (numArgs > 0)
668
 
        Params.insert(Params.end(), arg1);
669
 
    if (numArgs > 1)
670
 
        Params.insert(Params.end(), arg2);
671
 
    if (numArgs > 2)
672
 
        Params.insert(Params.end(), arg3);
673
 
    if (numArgs > 3)
674
 
        Params.insert(Params.end(), arg4);
675
 
    if (numArgs > 4)
676
 
        Params.insert(Params.end(), arg5);
677
 
    if (numArgs > 5)
678
 
        Params.insert(Params.end(), arg6);
679
 
    if (numArgs > 6)
680
 
        Params.insert(Params.end(), arg7);
681
 
    if (numArgs > 7)
682
 
        Params.insert(Params.end(), arg8);
683
 
    if (numArgs > 8)
684
 
        Params.insert(Params.end(), arg9);
685
 
 
686
 
    toBusy busy;
687
 
    try
688
 
    {
689
 
        Query = NULL;
690
 
        Query = conn.Connection->createQuery(this, ConnectionSub);
691
 
        Query->execute();
692
 
    }
693
 
    catch (...)
694
 
    {
695
 
        delete Query;
696
 
        Query = NULL;
697
 
        Connection.freeConnection(ConnectionSub);
698
 
        throw;
699
 
    }
700
 
    ConnectionSub->setQuery(this);
701
 
}
702
 
 
703
 
toQuery::toQuery(toConnection &conn, const toSQL &sql, const toQList &params)
704
 
        : Connection(conn), ConnectionSub(conn.mainConnection()), Params(params), SQL(sql(conn))
705
 
{
706
 
    Mode = Normal;
707
 
    toBusy busy;
708
 
    try
709
 
    {
710
 
        Query = NULL;
711
 
        Query = conn.Connection->createQuery(this, ConnectionSub);
712
 
        Query->execute();
713
 
    }
714
 
    catch (...)
715
 
    {
716
 
        delete Query;
717
 
        Query = NULL;
718
 
        Connection.freeConnection(ConnectionSub);
719
 
        throw;
720
 
    }
721
 
    ConnectionSub->setQuery(this);
722
 
}
723
 
 
724
 
toQuery::toQuery(toConnection &conn, const QString &sql, const toQList &params)
725
 
        : Connection(conn), ConnectionSub(conn.mainConnection()), Params(params), SQL(sql.utf8())
726
 
{
727
 
    Mode = Normal;
728
 
    toBusy busy;
729
 
    try
730
 
    {
731
 
        Query = NULL;
732
 
        Query = conn.Connection->createQuery(this, ConnectionSub);
733
 
        Query->execute();
734
 
    }
735
 
    catch (...)
736
 
    {
737
 
        delete Query;
738
 
        Query = NULL;
739
 
        Connection.freeConnection(ConnectionSub);
740
 
        throw;
741
 
    }
742
 
    ConnectionSub->setQuery(this);
743
 
}
744
 
 
745
 
toQuery::toQuery(toConnection &conn, queryMode mode, const toSQL &sql, const toQList &params)
746
 
        : Connection(conn),
747
 
        Params(params),
748
 
        SQL(sql(conn))
749
 
{
750
 
    Mode = mode;
751
 
 
752
 
    switch (Mode)
753
 
    {
754
 
    case Normal:
755
 
    case All:
756
 
        ConnectionSub = conn.mainConnection();
757
 
        break;
758
 
    case Background:
759
 
        ConnectionSub = conn.backgroundConnection();
760
 
        break;
761
 
    case Long:
762
 
        ConnectionSub = conn.longConnection();
763
 
        break;
764
 
    }
765
 
 
766
 
    toBusy busy;
767
 
    try
768
 
    {
769
 
        Query = NULL;
770
 
        Query = conn.Connection->createQuery(this, ConnectionSub);
771
 
        Query->execute();
772
 
    }
773
 
    catch (...)
774
 
    {
775
 
        delete Query;
776
 
        Query = NULL;
777
 
        Connection.freeConnection(ConnectionSub);
778
 
        throw;
779
 
    }
780
 
    ConnectionSub->setQuery(this);
781
 
}
782
 
 
783
 
toQuery::toQuery(toConnection &conn, queryMode mode, const QString &sql, const toQList &params)
784
 
        : Connection(conn),
785
 
        Params(params),
786
 
        SQL(sql.utf8())
787
 
{
788
 
    Mode = mode;
789
 
 
790
 
    switch (Mode)
791
 
    {
792
 
    case Normal:
793
 
    case All:
794
 
        ConnectionSub = conn.mainConnection();
795
 
        break;
796
 
    case Background:
797
 
        ConnectionSub = conn.backgroundConnection();
798
 
        break;
799
 
    case Long:
800
 
        ConnectionSub = conn.longConnection();
801
 
        break;
802
 
    }
803
 
 
804
 
    toBusy busy;
805
 
    try
806
 
    {
807
 
        Query = NULL;
808
 
        Query = conn.Connection->createQuery(this, ConnectionSub);
809
 
        Query->execute();
810
 
    }
811
 
    catch (...)
812
 
    {
813
 
        delete Query;
814
 
        Query = NULL;
815
 
        Connection.freeConnection(ConnectionSub);
816
 
        throw;
817
 
    }
818
 
    ConnectionSub->setQuery(this);
819
 
}
820
 
 
821
 
toQuery::toQuery(toConnection &conn, queryMode mode)
822
 
        : Connection(conn)
823
 
{
824
 
    Mode = mode;
825
 
 
826
 
    switch (Mode)
827
 
    {
828
 
    case Normal:
829
 
    case All:
830
 
        ConnectionSub = conn.mainConnection();
831
 
        break;
832
 
    case Background:
833
 
        ConnectionSub = conn.backgroundConnection();
834
 
        break;
835
 
    case Long:
836
 
        ConnectionSub = conn.longConnection();
837
 
        break;
838
 
    }
839
 
 
840
 
    toBusy busy;
841
 
    try
842
 
    {
843
 
        Query = NULL;
844
 
        Query = conn.Connection->createQuery(this, ConnectionSub);
845
 
    }
846
 
    catch (...)
847
 
    {
848
 
        delete Query;
849
 
        Query = NULL;
850
 
        throw;
851
 
    }
852
 
    ConnectionSub->setQuery(this);
853
 
}
854
 
 
855
 
void toQuery::execute(const toSQL &sql, const toQList &params)
856
 
{
857
 
    toBusy busy;
858
 
    SQL = sql(Connection);
859
 
    Params = params;
860
 
    Query->execute();
861
 
}
862
 
 
863
 
void toQuery::execute(const QString &sql, const toQList &params)
864
 
{
865
 
    toBusy busy;
866
 
    SQL = sql.utf8();
867
 
    Params = params;
868
 
    Query->execute();
869
 
}
870
 
 
871
 
toQuery::~toQuery()
872
 
{
873
 
    toBusy busy;
874
 
    delete Query;
875
 
    try
876
 
    {
877
 
        if (ConnectionSub->query() == this)
878
 
            ConnectionSub->setQuery(NULL);
879
 
        Connection.freeConnection(ConnectionSub);
880
 
    }
881
 
    catch (...)
882
 
    {}
883
 
}
884
 
 
885
 
bool toQuery::eof(void)
886
 
{
887
 
    if (Mode == All)
888
 
    {
889
 
        if (Query->eof())
890
 
        {
891
 
            Connection.Lock.lock();
892
 
            bool found = false;
893
 
            try
894
 
            {
895
 
                std::list<toConnectionSub *> &cons = Connection.connections();
896
 
                for (std::list<toConnectionSub *>::iterator i = cons.begin();i != cons.end();i++)
897
 
                {
898
 
                    if (*i == ConnectionSub)
899
 
                    {
900
 
                        i++;
901
 
                        if (i != cons.end())
902
 
                        {
903
 
                            ConnectionSub = *i;
904
 
                            Connection.Lock.unlock();
905
 
                            found = true;
906
 
                            delete Query;
907
 
                            Query = NULL;
908
 
                            Query = connection().Connection->createQuery(this, ConnectionSub);
909
 
                            Query->execute();
910
 
                            Connection.Lock.lock();
911
 
                        }
912
 
                        break;
913
 
                    }
914
 
                }
915
 
                Connection.Lock.unlock();
916
 
            }
917
 
            catch (...)
918
 
            {}
919
 
        }
920
 
    }
921
 
    return Query->eof();
922
 
}
923
 
 
924
 
toQList toQuery::readQuery(toConnection &conn, const toSQL &sql, toQList &params)
925
 
{
926
 
    toBusy busy;
927
 
    toQuery query(conn, sql, params);
928
 
    toQList ret;
929
 
    while (!query.eof())
930
 
        ret.insert(ret.end(), query.readValue());
931
 
    return ret;
932
 
}
933
 
 
934
 
toQList toQuery::readQuery(toConnection &conn, const QString &sql, toQList &params)
935
 
{
936
 
    toBusy busy;
937
 
    toQuery query(conn, sql, params);
938
 
    toQList ret;
939
 
    while (!query.eof())
940
 
        ret.insert(ret.end(), query.readValue());
941
 
    return ret;
942
 
}
943
 
 
944
 
toQList toQuery::readQuery(toConnection &conn, const toSQL &sql,
945
 
                           const QString &arg1, const QString &arg2,
946
 
                           const QString &arg3, const QString &arg4,
947
 
                           const QString &arg5, const QString &arg6,
948
 
                           const QString &arg7, const QString &arg8,
949
 
                           const QString &arg9)
950
 
{
951
 
    toBusy busy;
952
 
    toQuery query(conn, sql, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
953
 
    toQList ret;
954
 
    while (!query.eof())
955
 
        ret.insert(ret.end(), query.readValue());
956
 
    return ret;
957
 
}
958
 
 
959
 
toQList toQuery::readQuery(toConnection &conn, const QString &sql,
960
 
                           const QString &arg1, const QString &arg2,
961
 
                           const QString &arg3, const QString &arg4,
962
 
                           const QString &arg5, const QString &arg6,
963
 
                           const QString &arg7, const QString &arg8,
964
 
                           const QString &arg9)
965
 
{
966
 
    toBusy busy;
967
 
    toQuery query(conn, sql, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
968
 
    toQList ret;
969
 
    while (!query.eof())
970
 
        ret.insert(ret.end(), query.readValue());
971
 
    return ret;
972
 
}
973
 
 
974
 
toQList toQuery::readQueryNull(toConnection &conn, const toSQL &sql, toQList &params)
975
 
{
976
 
    toBusy busy;
977
 
    toQuery query(conn, sql, params);
978
 
    toQList ret;
979
 
    while (!query.eof())
980
 
        ret.insert(ret.end(), query.readValueNull());
981
 
    return ret;
982
 
}
983
 
 
984
 
toQList toQuery::readQueryNull(toConnection &conn, const QString &sql, toQList &params)
985
 
{
986
 
    toBusy busy;
987
 
    toQuery query(conn, sql, params);
988
 
    toQList ret;
989
 
    while (!query.eof())
990
 
        ret.insert(ret.end(), query.readValueNull());
991
 
    return ret;
992
 
}
993
 
 
994
 
toQList toQuery::readQueryNull(toConnection &conn, const toSQL &sql,
995
 
                               const QString &arg1, const QString &arg2,
996
 
                               const QString &arg3, const QString &arg4,
997
 
                               const QString &arg5, const QString &arg6,
998
 
                               const QString &arg7, const QString &arg8,
999
 
                               const QString &arg9)
1000
 
{
1001
 
    toBusy busy;
1002
 
    toQuery query(conn, sql, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
1003
 
    toQList ret;
1004
 
    while (!query.eof())
1005
 
        ret.insert(ret.end(), query.readValueNull());
1006
 
    return ret;
1007
 
}
1008
 
 
1009
 
toQList toQuery::readQueryNull(toConnection &conn, const QString &sql,
1010
 
                               const QString &arg1, const QString &arg2,
1011
 
                               const QString &arg3, const QString &arg4,
1012
 
                               const QString &arg5, const QString &arg6,
1013
 
                               const QString &arg7, const QString &arg8,
1014
 
                               const QString &arg9)
1015
 
{
1016
 
    toBusy busy;
1017
 
    toQuery query(conn, sql, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
1018
 
    toQList ret;
1019
 
    while (!query.eof())
1020
 
        ret.insert(ret.end(), query.readValueNull());
1021
 
    return ret;
1022
 
}
1023
 
 
1024
 
toQValue toQuery::readValue(void)
1025
 
{
1026
 
    toBusy busy;
1027
 
    if (Connection.Abort)
1028
 
        throw qApp->translate("toQuery", "Query aborted");
1029
 
    if (Mode == All)
1030
 
        eof();
1031
 
    return toNull(Query->readValue());
1032
 
}
1033
 
 
1034
 
toQValue toQuery::readValueNull(void)
1035
 
{
1036
 
    toBusy busy;
1037
 
    if (Connection.Abort)
1038
 
        throw qApp->translate("toQuery", "Query aborted");
1039
 
    if (Mode == All)
1040
 
        eof();
1041
 
    return Query->readValue();
1042
 
}
1043
 
 
1044
 
void toQuery::cancel(void)
1045
 
{
1046
 
    Query->cancel();
1047
 
}
1048
 
 
1049
 
// toConnection implementation
1050
 
 
1051
 
void toConnection::addConnection(void)
1052
 
{
1053
 
    toBusy busy;
1054
 
    toConnectionSub *sub = Connection->createConnection();
1055
 
    toLocker lock (Lock)
1056
 
        ;
1057
 
    Connections.insert(Connections.end(), sub);
1058
 
    toQList params;
1059
 
    for (std::list<QString>::iterator i = InitStrings.begin();i != InitStrings.end();i++)
1060
 
    {
1061
 
        try
1062
 
        {
1063
 
            Connection->execute(sub, (*i).utf8(), params);
1064
 
        }
1065
 
        TOCATCH
1066
 
    }
1067
 
}
1068
 
 
1069
 
toConnection::toConnection(const QCString &provider,
1070
 
                           const QString &user, const QString &password,
1071
 
                           const QString &host, const QString &database,
1072
 
                           const std::set
1073
 
                               <QString> &options, bool cache)
1074
 
            : Provider(provider), User(user), Password(password), Host(host), Database(database), Options(options)
1075
 
{
1076
 
    BackgroundConnection = NULL;
1077
 
    BackgroundCount = 0;
1078
 
    Connection = toConnectionProvider::connection(Provider, this);
1079
 
    addConnection();
1080
 
    Version = Connection->version(mainConnection());
1081
 
    NeedCommit = Abort = false;
1082
 
    ReadingCache = false;
1083
 
    if (cache)
1084
 
    {
1085
 
        if (toTool::globalConfig(CONF_OBJECT_CACHE, DEFAULT_OBJECT_CACHE).toInt() == 1)
1086
 
            readObjects();
1087
 
    }
1088
 
    else
1089
 
    {
1090
 
        ReadingValues.up();
1091
 
        ReadingValues.up();
1092
 
    }
1093
 
}
1094
 
 
1095
 
toConnection::toConnection(const toConnection &conn)
1096
 
        : Provider(conn.Provider),
1097
 
        User(conn.User),
1098
 
        Password(conn.Password),
1099
 
        Host(conn.Host),
1100
 
        Database(conn.Database),
1101
 
        Options(conn.Options)
1102
 
{
1103
 
    BackgroundConnection = NULL;
1104
 
    BackgroundCount = 0;
1105
 
    Connection = toConnectionProvider::connection(Provider, this);
1106
 
    addConnection();
1107
 
    Version = Connection->version(mainConnection());
1108
 
    ReadingValues.up();
1109
 
    ReadingValues.up();
1110
 
    ReadingCache = false;
1111
 
    NeedCommit = Abort = false;
1112
 
}
1113
 
 
1114
 
std::list<QString> toConnection::running(void)
1115
 
{
1116
 
    toBusy busy;
1117
 
    toLocker lock (Lock)
1118
 
        ;
1119
 
    std::list<QString> ret;
1120
 
    toConnectionSub *sub = (*(Connections.begin()));
1121
 
    if (sub && sub->query())
1122
 
        ret.insert(ret.end(), sub->query()->sql());
1123
 
    if (BackgroundConnection && BackgroundConnection->query())
1124
 
        ret.insert(ret.end(), BackgroundConnection->query()->sql());
1125
 
    for (std::list<toConnectionSub *>::const_iterator i = Running.begin();i != Running.end();i++)
1126
 
    {
1127
 
        sub = *i;
1128
 
        if (sub && sub->query())
1129
 
            ret.insert(ret.end(), sub->query()->sql());
1130
 
    }
1131
 
    return ret;
1132
 
}
1133
 
 
1134
 
void toConnection::cancelAll(void)
1135
 
{
1136
 
    toBusy busy;
1137
 
    toLocker lock (Lock)
1138
 
        ;
1139
 
    for (std::list<toConnectionSub *>::iterator i = Running.begin();i != Running.end();i++)
1140
 
        (*i)->cancel();
1141
 
}
1142
 
 
1143
 
toConnection::~toConnection()
1144
 
{
1145
 
    toBusy busy;
1146
 
 
1147
 
    {
1148
 
        toLocker lock (Lock)
1149
 
            ;
1150
 
        for_each(Widgets.begin(), Widgets.end(), DeleteObject());
1151
 
        {
1152
 
            for (std::list<toConnectionSub *>::iterator i = Running.begin();i != Running.end();i++)
1153
 
                try
1154
 
                {
1155
 
                    (*i)->cancel();
1156
 
                }
1157
 
                catch (...)
1158
 
                {}
1159
 
        }
1160
 
    }
1161
 
    Abort = true;
1162
 
    if (ReadingCache)
1163
 
    {
1164
 
        ReadingValues.down();
1165
 
        ReadingValues.down();
1166
 
    }
1167
 
    for (std::list<toConnectionSub *>::iterator i = Connections.begin();i != Connections.end();i++)
1168
 
    {
1169
 
        try
1170
 
        {
1171
 
            Connection->closeConnection(*i);
1172
 
        }
1173
 
        catch (...)
1174
 
        {}
1175
 
    }
1176
 
    delete Connection;
1177
 
}
1178
 
 
1179
 
toConnectionSub *toConnection::mainConnection()
1180
 
{
1181
 
    if (Connection->handleMultipleQueries())
1182
 
    {
1183
 
        toLocker lock (Lock)
1184
 
            ;
1185
 
        return (*(Connections.begin()));
1186
 
    }
1187
 
    else
1188
 
    {
1189
 
        return longConnection();
1190
 
    }
1191
 
}
1192
 
 
1193
 
toConnectionSub *toConnection::backgroundConnection()
1194
 
{
1195
 
    if (!Connection->handleMultipleQueries())
1196
 
        return longConnection();
1197
 
    if (toTool::globalConfig(CONF_BKGND_CONNECT, "").isEmpty())
1198
 
        return mainConnection();
1199
 
    Lock.lock();
1200
 
    if (!BackgroundConnection)
1201
 
    {
1202
 
        Lock.unlock();
1203
 
        toConnectionSub *tmp = longConnection();
1204
 
        Lock.lock();
1205
 
 
1206
 
        BackgroundConnection = tmp;
1207
 
        BackgroundCount = 0;
1208
 
    }
1209
 
    BackgroundCount++;
1210
 
    Lock.unlock();
1211
 
    return BackgroundConnection;
1212
 
}
1213
 
 
1214
 
toConnectionSub *toConnection::longConnection()
1215
 
{
1216
 
    Lock.lock();
1217
 
    bool multiple = Connection->handleMultipleQueries();
1218
 
    if ((multiple && Connections.size() == 1) ||
1219
 
            (!multiple && Connections.empty()))
1220
 
    {
1221
 
        Lock.unlock();
1222
 
        addConnection();
1223
 
    }
1224
 
    else
1225
 
        Lock.unlock();
1226
 
    toLocker lock (Lock)
1227
 
        ;
1228
 
    std::list<toConnectionSub *>::iterator i = Connections.begin();
1229
 
    if (multiple)
1230
 
        i++;
1231
 
    toConnectionSub *ret = (*i);
1232
 
    Connections.erase(i);
1233
 
    Running.insert(Running.end(), ret);
1234
 
    return ret;
1235
 
}
1236
 
 
1237
 
void toConnection::freeConnection(toConnectionSub *sub)
1238
 
{
1239
 
    toLocker lock (Lock)
1240
 
        ;
1241
 
    if (sub == BackgroundConnection)
1242
 
    {
1243
 
        BackgroundCount--;
1244
 
        if (BackgroundCount > 0)
1245
 
            return ;
1246
 
        BackgroundConnection = NULL;
1247
 
    }
1248
 
    {
1249
 
        for (std::list<toConnectionSub *>::iterator i = Running.begin();i != Running.end();i++)
1250
 
        {
1251
 
            if (*i == sub)
1252
 
            {
1253
 
                Running.erase(i);
1254
 
                break;
1255
 
            }
1256
 
        }
1257
 
    }
1258
 
    {
1259
 
        for (std::list<toConnectionSub *>::iterator i = Connections.begin();i != Connections.end();i++)
1260
 
        {
1261
 
            if (*i == sub)
1262
 
                return ;
1263
 
        }
1264
 
    }
1265
 
    Connections.insert(Connections.end(), sub);
1266
 
}
1267
 
 
1268
 
void toConnection::commit(void)
1269
 
{
1270
 
    toBusy busy;
1271
 
    toLocker lock (Lock)
1272
 
        ;
1273
 
    for (std::list<toConnectionSub *>::iterator i = Connections.begin();i != Connections.end();i++)
1274
 
        Connection->commit(*i);
1275
 
    while (Connections.size() > 2)
1276
 
    {
1277
 
        std::list<toConnectionSub *>::iterator i = Connections.begin();
1278
 
        i++;
1279
 
        delete (*i);
1280
 
        Connections.erase(i);
1281
 
    }
1282
 
    setNeedCommit(false);
1283
 
}
1284
 
 
1285
 
void toConnection::rollback(void)
1286
 
{
1287
 
    toBusy busy;
1288
 
    toLocker lock (Lock)
1289
 
        ;
1290
 
    for (std::list<toConnectionSub *>::iterator i = Connections.begin();i != Connections.end();i++)
1291
 
    {
1292
 
        Connection->rollback(*i);
1293
 
    }
1294
 
    while (Connections.size() > 2)
1295
 
    {
1296
 
        std::list<toConnectionSub *>::iterator i = Connections.begin();
1297
 
        i++;
1298
 
        delete (*i);
1299
 
        Connections.erase(i);
1300
 
    }
1301
 
    setNeedCommit(false);
1302
 
}
1303
 
 
1304
 
void toConnection::delWidget(QObject *widget)
1305
 
{
1306
 
    for (std::list<QObject *>::iterator i = Widgets.begin();i != Widgets.end();i++)
1307
 
    {
1308
 
        if ((*i) == widget)
1309
 
        {
1310
 
            Widgets.erase(i);
1311
 
            break;
1312
 
        }
1313
 
    }
1314
 
}
1315
 
 
1316
 
bool toConnection::closeWidgets(void)
1317
 
{
1318
 
    for (std::list<QObject *>::iterator i = Widgets.begin();i != Widgets.end();i = Widgets.begin())
1319
 
    {
1320
 
        if ((*i)->inherits("QWidget"))
1321
 
        {
1322
 
            QWidget * widget = static_cast<QWidget *>(*i);
1323
 
            if (!widget->close(true))
1324
 
                return false;
1325
 
        }
1326
 
        else
1327
 
            delete *i;
1328
 
        std::list<QObject *>::iterator nextI = Widgets.begin();
1329
 
        if (i == nextI)
1330
 
            throw qApp->translate("toConnection", "All tool widgets need to have autodelete flag set");
1331
 
    }
1332
 
    return true;
1333
 
}
1334
 
 
1335
 
QString toConnection::description(bool version) const
1336
 
{
1337
 
    QString ret(User);
1338
 
    ret += QString::fromLatin1("@");
1339
 
    ret += Database;
1340
 
    if (!Host.isEmpty() && Host != "SQL*Net")
1341
 
    {
1342
 
        ret += QString::fromLatin1(".");
1343
 
        ret += Host;
1344
 
    }
1345
 
 
1346
 
    if (version)
1347
 
    {
1348
 
        if (!Version.isEmpty())
1349
 
        {
1350
 
            ret += QString::fromLatin1(" [");
1351
 
            ret += QString::fromLatin1(Version);
1352
 
            ret += QString::fromLatin1("]");
1353
 
        }
1354
 
    }
1355
 
    return ret;
1356
 
}
1357
 
 
1358
 
void toConnection::addInit(const QString &sql)
1359
 
{
1360
 
    delInit(sql);
1361
 
    InitStrings.insert(InitStrings.end(), sql);
1362
 
}
1363
 
 
1364
 
void toConnection::delInit(const QString &sql)
1365
 
{
1366
 
    std::list<QString>::iterator i = InitStrings.begin();
1367
 
    while (i != InitStrings.end())
1368
 
    {
1369
 
        if ((*i) == sql)
1370
 
            i = InitStrings.erase(i);
1371
 
        else
1372
 
            i++;
1373
 
    }
1374
 
}
1375
 
 
1376
 
const std::list<QString> toConnection::initStrings() const
1377
 
{
1378
 
    return InitStrings;
1379
 
}
1380
 
 
1381
 
void toConnection::parse(const QString &sql)
1382
 
{
1383
 
    toBusy busy;
1384
 
    Connection->parse(mainConnection(), sql.utf8());
1385
 
}
1386
 
 
1387
 
void toConnection::parse(const toSQL &sql)
1388
 
{
1389
 
    toBusy busy;
1390
 
    Connection->parse(mainConnection(), toSQL::sql(sql, *this));
1391
 
}
1392
 
 
1393
 
void toConnection::execute(const toSQL &sql, toQList &params)
1394
 
{
1395
 
    toBusy busy;
1396
 
    Connection->execute(mainConnection(), toSQL::sql(sql, *this), params);
1397
 
}
1398
 
 
1399
 
void toConnection::execute(const QString &sql, toQList &params)
1400
 
{
1401
 
    toBusy busy;
1402
 
    Connection->execute(mainConnection(), sql.utf8(), params);
1403
 
}
1404
 
 
1405
 
void toConnection::execute(const toSQL &sql,
1406
 
                           const QString &arg1, const QString &arg2,
1407
 
                           const QString &arg3, const QString &arg4,
1408
 
                           const QString &arg5, const QString &arg6,
1409
 
                           const QString &arg7, const QString &arg8,
1410
 
                           const QString &arg9)
1411
 
{
1412
 
    int numArgs;
1413
 
    if (!arg9.isNull())
1414
 
        numArgs = 9;
1415
 
    else if (!arg8.isNull())
1416
 
        numArgs = 8;
1417
 
    else if (!arg7.isNull())
1418
 
        numArgs = 7;
1419
 
    else if (!arg6.isNull())
1420
 
        numArgs = 6;
1421
 
    else if (!arg5.isNull())
1422
 
        numArgs = 5;
1423
 
    else if (!arg4.isNull())
1424
 
        numArgs = 4;
1425
 
    else if (!arg3.isNull())
1426
 
        numArgs = 3;
1427
 
    else if (!arg2.isNull())
1428
 
        numArgs = 2;
1429
 
    else if (!arg1.isNull())
1430
 
        numArgs = 1;
1431
 
    else
1432
 
        numArgs = 0;
1433
 
 
1434
 
    toQList args;
1435
 
    if (numArgs > 0)
1436
 
        args.insert(args.end(), arg1);
1437
 
    if (numArgs > 1)
1438
 
        args.insert(args.end(), arg2);
1439
 
    if (numArgs > 2)
1440
 
        args.insert(args.end(), arg3);
1441
 
    if (numArgs > 3)
1442
 
        args.insert(args.end(), arg4);
1443
 
    if (numArgs > 4)
1444
 
        args.insert(args.end(), arg5);
1445
 
    if (numArgs > 5)
1446
 
        args.insert(args.end(), arg6);
1447
 
    if (numArgs > 6)
1448
 
        args.insert(args.end(), arg7);
1449
 
    if (numArgs > 7)
1450
 
        args.insert(args.end(), arg8);
1451
 
    if (numArgs > 8)
1452
 
        args.insert(args.end(), arg9);
1453
 
 
1454
 
    toBusy busy;
1455
 
    Connection->execute(mainConnection(), toSQL::sql(sql, *this), args);
1456
 
}
1457
 
 
1458
 
void toConnection::execute(const QString &sql,
1459
 
                           const QString &arg1, const QString &arg2,
1460
 
                           const QString &arg3, const QString &arg4,
1461
 
                           const QString &arg5, const QString &arg6,
1462
 
                           const QString &arg7, const QString &arg8,
1463
 
                           const QString &arg9)
1464
 
{
1465
 
    int numArgs;
1466
 
    if (!arg9.isNull())
1467
 
        numArgs = 9;
1468
 
    else if (!arg8.isNull())
1469
 
        numArgs = 8;
1470
 
    else if (!arg7.isNull())
1471
 
        numArgs = 7;
1472
 
    else if (!arg6.isNull())
1473
 
        numArgs = 6;
1474
 
    else if (!arg5.isNull())
1475
 
        numArgs = 5;
1476
 
    else if (!arg4.isNull())
1477
 
        numArgs = 4;
1478
 
    else if (!arg3.isNull())
1479
 
        numArgs = 3;
1480
 
    else if (!arg2.isNull())
1481
 
        numArgs = 2;
1482
 
    else if (!arg1.isNull())
1483
 
        numArgs = 1;
1484
 
    else
1485
 
        numArgs = 0;
1486
 
 
1487
 
    toQList args;
1488
 
    if (numArgs > 0)
1489
 
        args.insert(args.end(), arg1);
1490
 
    if (numArgs > 1)
1491
 
        args.insert(args.end(), arg2);
1492
 
    if (numArgs > 2)
1493
 
        args.insert(args.end(), arg3);
1494
 
    if (numArgs > 3)
1495
 
        args.insert(args.end(), arg4);
1496
 
    if (numArgs > 4)
1497
 
        args.insert(args.end(), arg5);
1498
 
    if (numArgs > 5)
1499
 
        args.insert(args.end(), arg6);
1500
 
    if (numArgs > 6)
1501
 
        args.insert(args.end(), arg7);
1502
 
    if (numArgs > 7)
1503
 
        args.insert(args.end(), arg8);
1504
 
    if (numArgs > 8)
1505
 
        args.insert(args.end(), arg9);
1506
 
 
1507
 
    toBusy busy;
1508
 
    Connection->execute(mainConnection(), sql.utf8(), args);
1509
 
}
1510
 
 
1511
 
void toConnection::allExecute(const toSQL &sql, toQList &params)
1512
 
{
1513
 
    toBusy busy;
1514
 
    toLocker lock (Lock)
1515
 
        ;
1516
 
    for (std::list<toConnectionSub *>::iterator i = Connections.begin();i != Connections.end();i++)
1517
 
    {
1518
 
        try
1519
 
        {
1520
 
            Connection->execute(*i, toSQL::sql(sql, *this), params);
1521
 
        }
1522
 
        TOCATCH
1523
 
    }
1524
 
}
1525
 
 
1526
 
void toConnection::allExecute(const QString &sql, toQList &params)
1527
 
{
1528
 
    toBusy busy;
1529
 
    toLocker lock (Lock)
1530
 
        ;
1531
 
    for (std::list<toConnectionSub *>::iterator i = Connections.begin();i != Connections.end();i++)
1532
 
    {
1533
 
        try
1534
 
        {
1535
 
            Connection->execute(*i, sql.utf8(), params);
1536
 
        }
1537
 
        TOCATCH
1538
 
    }
1539
 
}
1540
 
 
1541
 
void toConnection::allExecute(const toSQL &sql,
1542
 
                              const QString &arg1, const QString &arg2,
1543
 
                              const QString &arg3, const QString &arg4,
1544
 
                              const QString &arg5, const QString &arg6,
1545
 
                              const QString &arg7, const QString &arg8,
1546
 
                              const QString &arg9)
1547
 
{
1548
 
    int numArgs;
1549
 
    if (!arg9.isNull())
1550
 
        numArgs = 9;
1551
 
    else if (!arg8.isNull())
1552
 
        numArgs = 8;
1553
 
    else if (!arg7.isNull())
1554
 
        numArgs = 7;
1555
 
    else if (!arg6.isNull())
1556
 
        numArgs = 6;
1557
 
    else if (!arg5.isNull())
1558
 
        numArgs = 5;
1559
 
    else if (!arg4.isNull())
1560
 
        numArgs = 4;
1561
 
    else if (!arg3.isNull())
1562
 
        numArgs = 3;
1563
 
    else if (!arg2.isNull())
1564
 
        numArgs = 2;
1565
 
    else if (!arg1.isNull())
1566
 
        numArgs = 1;
1567
 
    else
1568
 
        numArgs = 0;
1569
 
 
1570
 
    toQList args;
1571
 
    if (numArgs > 0)
1572
 
        args.insert(args.end(), arg1);
1573
 
    if (numArgs > 1)
1574
 
        args.insert(args.end(), arg2);
1575
 
    if (numArgs > 2)
1576
 
        args.insert(args.end(), arg3);
1577
 
    if (numArgs > 3)
1578
 
        args.insert(args.end(), arg4);
1579
 
    if (numArgs > 4)
1580
 
        args.insert(args.end(), arg5);
1581
 
    if (numArgs > 5)
1582
 
        args.insert(args.end(), arg6);
1583
 
    if (numArgs > 6)
1584
 
        args.insert(args.end(), arg7);
1585
 
    if (numArgs > 7)
1586
 
        args.insert(args.end(), arg8);
1587
 
    if (numArgs > 8)
1588
 
        args.insert(args.end(), arg9);
1589
 
 
1590
 
    toBusy busy;
1591
 
    toLocker lock (Lock)
1592
 
        ;
1593
 
    for (std::list<toConnectionSub *>::iterator i = Connections.begin();i != Connections.end();i++)
1594
 
    {
1595
 
        try
1596
 
        {
1597
 
            Connection->execute(*i, toSQL::sql(sql, *this), args);
1598
 
        }
1599
 
        TOCATCH
1600
 
    }
1601
 
}
1602
 
 
1603
 
void toConnection::allExecute(const QString &sql,
1604
 
                              const QString &arg1, const QString &arg2,
1605
 
                              const QString &arg3, const QString &arg4,
1606
 
                              const QString &arg5, const QString &arg6,
1607
 
                              const QString &arg7, const QString &arg8,
1608
 
                              const QString &arg9)
1609
 
{
1610
 
    int numArgs;
1611
 
    if (!arg9.isNull())
1612
 
        numArgs = 9;
1613
 
    else if (!arg8.isNull())
1614
 
        numArgs = 8;
1615
 
    else if (!arg7.isNull())
1616
 
        numArgs = 7;
1617
 
    else if (!arg6.isNull())
1618
 
        numArgs = 6;
1619
 
    else if (!arg5.isNull())
1620
 
        numArgs = 5;
1621
 
    else if (!arg4.isNull())
1622
 
        numArgs = 4;
1623
 
    else if (!arg3.isNull())
1624
 
        numArgs = 3;
1625
 
    else if (!arg2.isNull())
1626
 
        numArgs = 2;
1627
 
    else if (!arg1.isNull())
1628
 
        numArgs = 1;
1629
 
    else
1630
 
        numArgs = 0;
1631
 
 
1632
 
    toQList args;
1633
 
    if (numArgs > 0)
1634
 
        args.insert(args.end(), arg1);
1635
 
    if (numArgs > 1)
1636
 
        args.insert(args.end(), arg2);
1637
 
    if (numArgs > 2)
1638
 
        args.insert(args.end(), arg3);
1639
 
    if (numArgs > 3)
1640
 
        args.insert(args.end(), arg4);
1641
 
    if (numArgs > 4)
1642
 
        args.insert(args.end(), arg5);
1643
 
    if (numArgs > 5)
1644
 
        args.insert(args.end(), arg6);
1645
 
    if (numArgs > 6)
1646
 
        args.insert(args.end(), arg7);
1647
 
    if (numArgs > 7)
1648
 
        args.insert(args.end(), arg8);
1649
 
    if (numArgs > 8)
1650
 
        args.insert(args.end(), arg9);
1651
 
 
1652
 
    toBusy busy;
1653
 
    toLocker lock (Lock)
1654
 
        ;
1655
 
    for (std::list<toConnectionSub *>::iterator i = Connections.begin();i != Connections.end();i++)
1656
 
    {
1657
 
        try
1658
 
        {
1659
 
            Connection->execute(*i, sql.utf8(), args);
1660
 
        }
1661
 
        TOCATCH
1662
 
    }
1663
 
}
1664
 
 
1665
 
const QCString &toConnection::provider(void) const
1666
 
{
1667
 
    return Provider;
1668
 
}
1669
 
 
1670
 
QString toConnection::cacheDir()
1671
 
{
1672
 
    QString home = QDir::homeDirPath();
1673
 
    QString dirname = toTool::globalConfig(CONF_CACHE_DIR, "");
1674
 
 
1675
 
    if (dirname.isEmpty())
1676
 
    {
1677
 
#ifdef WIN32
1678
 
        if (getenv("TEMP"))
1679
 
            dirname = QString(getenv("TEMP"));
1680
 
        else
1681
 
#endif
1682
 
 
1683
 
            dirname = QString(home);
1684
 
#ifdef TOAD
1685
 
 
1686
 
        dirname += "/.toad_cache";
1687
 
#else
1688
 
 
1689
 
        dirname += "/.tora_cache";
1690
 
#endif
1691
 
 
1692
 
    }
1693
 
    return dirname;
1694
 
}
1695
 
 
1696
 
QString toConnection::cacheFile()
1697
 
{
1698
 
    QString dbname (description(false).stripWhiteSpace());
1699
 
 
1700
 
    return (cacheDir() + "/" + dbname).simplifyWhiteSpace();
1701
 
}
1702
 
 
1703
 
bool toConnection::loadDiskCache()
1704
 
{
1705
 
    if (toTool::globalConfig(CONF_CACHE_DISK, DEFAULT_CACHE_DISK).isEmpty())
1706
 
        return false;
1707
 
 
1708
 
    toConnection::objectName *cur = 0;
1709
 
    int objCounter = 0;
1710
 
    int synCounter = 0;
1711
 
 
1712
 
    QString filename = cacheFile();
1713
 
 
1714
 
    QFile file(filename);
1715
 
 
1716
 
    if (!QFile::exists(filename))
1717
 
        return false;
1718
 
 
1719
 
    QFileInfo fi(file);
1720
 
    QDateTime today;
1721
 
    if (fi.lastModified().addDays(toTool::globalConfig(CONF_CACHE_TIMEOUT, DEFAULT_CACHE_TIMEOUT).toInt()) < today)
1722
 
        return false;
1723
 
 
1724
 
    /** read in all data
1725
 
     */
1726
 
 
1727
 
    if (!file.open(IO_ReadOnly))
1728
 
        return false;
1729
 
 
1730
 
    QString data = file.readAll();
1731
 
 
1732
 
    /** build cache lists
1733
 
     */
1734
 
 
1735
 
    QStringList records = QStringList::split("\x1D", data, true);
1736
 
    for ( QStringList::Iterator i = records.begin(); i != records.end(); i++)
1737
 
    {
1738
 
        objCounter++;
1739
 
        QStringList record = QStringList::split("\x1E", (*i), true);
1740
 
        QStringList::Iterator rec = record.begin();
1741
 
        cur = new objectName;
1742
 
        (*cur).Owner = (*rec);
1743
 
        rec++;
1744
 
        (*cur).Name = (*rec);
1745
 
        rec++;
1746
 
        (*cur).Type = (*rec);
1747
 
        rec++;
1748
 
        (*cur).Comment = (*rec);
1749
 
        rec++;
1750
 
        QStringList slist = QStringList::split("\x1F", (*rec), false);
1751
 
        for (QStringList::Iterator s = slist.begin(); s != slist.end(); s++)
1752
 
        {
1753
 
            SynonymMap[(*s)] = (*cur);
1754
 
            (*cur).Synonyms.insert((*cur).Synonyms.end(), (*s));
1755
 
            synCounter++;
1756
 
        }
1757
 
        ObjectNames.insert(ObjectNames.end(), (*cur));
1758
 
        delete cur;
1759
 
        cur = 0;
1760
 
    }
1761
 
    return true;
1762
 
}
1763
 
 
1764
 
void toConnection::writeDiskCache()
1765
 
{
1766
 
    QString text;
1767
 
    long objCounter = 0;
1768
 
    long synCounter = 0;
1769
 
 
1770
 
    if (toTool::globalConfig(CONF_CACHE_DISK, DEFAULT_CACHE_DISK).isEmpty())
1771
 
        return ;
1772
 
 
1773
 
 
1774
 
    QString filename(cacheFile());
1775
 
 
1776
 
    /** check pathnames and create
1777
 
     */
1778
 
 
1779
 
    QString dirname(cacheDir());
1780
 
    QDir dir;
1781
 
    dir.setPath(dirname);
1782
 
 
1783
 
    if (!dir.exists(dirname))
1784
 
        dir.mkdir(dirname);
1785
 
 
1786
 
 
1787
 
    /** build record to write out
1788
 
     */
1789
 
 
1790
 
    QStringList record;
1791
 
    QStringList records;
1792
 
    QStringList recordSynonym;
1793
 
    for (std::list<objectName>::iterator i = ObjectNames.begin();i != ObjectNames.end();i++)
1794
 
    {
1795
 
        record.clear();
1796
 
        record.append((*i).Owner);
1797
 
        record.append((*i).Name);
1798
 
        record.append((*i).Type);
1799
 
        record.append((*i).Comment);
1800
 
        for (std::list<QString>::iterator s = (*i).Synonyms.begin();s != (*i).Synonyms.end();s++)
1801
 
        {
1802
 
            recordSynonym.append((*s));
1803
 
            synCounter++;
1804
 
        }
1805
 
        record.append(recordSynonym.join("\x1F"));
1806
 
        recordSynonym.clear();
1807
 
        objCounter++;
1808
 
        records.append(record.join("\x1E"));
1809
 
    }
1810
 
    /** open file
1811
 
     */
1812
 
    QFile file(filename);
1813
 
    file.open( IO_ReadWrite | IO_Truncate );
1814
 
    QTextStream t (&file);
1815
 
    t << records.join("\x1D");
1816
 
    file.flush();
1817
 
    file.close();
1818
 
}
1819
 
 
1820
 
void toConnection::cacheObjects::run()
1821
 
{
1822
 
    bool diskloaded = false;
1823
 
    try
1824
 
    {
1825
 
        diskloaded = Connection.loadDiskCache();
1826
 
        if (!diskloaded)
1827
 
        {
1828
 
            Connection.ObjectNames = Connection.Connection->objectNames();
1829
 
        }
1830
 
        Connection.ObjectNames.sort();
1831
 
        Connection.ReadingValues.up();
1832
 
        if (!diskloaded)
1833
 
        {
1834
 
            Connection.SynonymMap = Connection.Connection->synonymMap(Connection.ObjectNames);
1835
 
            Connection.writeDiskCache();
1836
 
        }
1837
 
    }
1838
 
    catch (...)
1839
 
    {
1840
 
        if (Connection.ReadingValues.getValue() == 0)
1841
 
            Connection.ReadingValues.up();
1842
 
    }
1843
 
    Connection.ReadingValues.up();
1844
 
}
1845
 
 
1846
 
 
1847
 
void toConnection::readObjects(void)
1848
 
{
1849
 
    if (toTool::globalConfig(CONF_OBJECT_CACHE, DEFAULT_OBJECT_CACHE).toInt() == 3)
1850
 
    {
1851
 
        ReadingCache = false;
1852
 
        return ;
1853
 
    }
1854
 
 
1855
 
    if (!ReadingCache)
1856
 
    {
1857
 
        ReadingCache = true;
1858
 
        try
1859
 
        {
1860
 
            (new toThread(new cacheObjects(*this)))->start();
1861
 
        }
1862
 
        catch (...)
1863
 
        {
1864
 
            ReadingCache = false;
1865
 
        }
1866
 
    }
1867
 
}
1868
 
 
1869
 
void toConnection::rereadCache(void)
1870
 
{
1871
 
 
1872
 
    if (toTool::globalConfig(CONF_OBJECT_CACHE, DEFAULT_OBJECT_CACHE).toInt() == 3)
1873
 
    {
1874
 
        ColumnCache.clear();
1875
 
        return ;
1876
 
    }
1877
 
 
1878
 
    if (ReadingValues.getValue() < 2 && ReadingCache)
1879
 
    {
1880
 
        toStatusMessage(qApp->translate("toConnection",
1881
 
                                        "Not done caching objects, can not clear unread cache"));
1882
 
        return ;
1883
 
    }
1884
 
 
1885
 
 
1886
 
    ReadingCache = false;
1887
 
    while (ReadingValues.getValue() > 0)
1888
 
        ReadingValues.down();
1889
 
 
1890
 
    ObjectNames.clear();
1891
 
    ColumnCache.clear();
1892
 
    SynonymMap.clear();
1893
 
 
1894
 
    /** delete cache file to force reload
1895
 
     */
1896
 
 
1897
 
    QString filename(cacheFile());
1898
 
 
1899
 
    if (QFile::exists(filename))
1900
 
        QFile::remove
1901
 
            (filename);
1902
 
 
1903
 
    readObjects();
1904
 
}
1905
 
 
1906
 
QString toConnection::quote(const QString &name)
1907
 
{
1908
 
    return Connection->quote(name);
1909
 
}
1910
 
 
1911
 
QString toConnection::unQuote(const QString &name)
1912
 
{
1913
 
    return Connection->unQuote(name);
1914
 
}
1915
 
 
1916
 
bool toConnection::cacheAvailable(bool synonyms, bool block, bool need)
1917
 
{
1918
 
    if (toTool::globalConfig(CONF_OBJECT_CACHE, DEFAULT_OBJECT_CACHE).toInt() == 3)
1919
 
        return true;
1920
 
 
1921
 
    if (!ReadingCache)
1922
 
    {
1923
 
        if (!need)
1924
 
            return true;
1925
 
        if (toTool::globalConfig(CONF_OBJECT_CACHE, DEFAULT_OBJECT_CACHE).toInt() == 2 && !block)
1926
 
            return true;
1927
 
        readObjects();
1928
 
        toMainWidget()->checkCaching();
1929
 
    }
1930
 
    if (ReadingValues.getValue() == 0 || (ReadingValues.getValue() == 1 && synonyms == true))
1931
 
    {
1932
 
        if (block)
1933
 
        {
1934
 
            toBusy busy;
1935
 
            if (toThread::mainThread())
1936
 
            {
1937
 
                QProgressDialog waiting(qApp->translate("toConnection",
1938
 
                                                        "Waiting for object caching to be completed.\n"
1939
 
                                                        "Canceling this dialog will probably leave some list of\n"
1940
 
                                                        "database objects empty."),
1941
 
                                        qApp->translate("toConnection", "Cancel"),
1942
 
                                        10,
1943
 
                                        toMainWidget(),
1944
 
                                        "progress",
1945
 
                                        true);
1946
 
                waiting.setCaption(qApp->translate("toConnection", "Waiting for object cache"));
1947
 
                int num = 1;
1948
 
 
1949
 
                int waitVal = (synonyms ? 2 : 1);
1950
 
                do
1951
 
                {
1952
 
                    qApp->processEvents();
1953
 
                    toThread::msleep(100);
1954
 
                    waiting.setProgress((++num) % 10);
1955
 
                    if (waiting.wasCancelled())
1956
 
                        return false;
1957
 
                }
1958
 
                while (ReadingValues.getValue() < waitVal);
1959
 
            }
1960
 
 
1961
 
            ReadingValues.down();
1962
 
            if (synonyms)
1963
 
            {
1964
 
                ReadingValues.down();
1965
 
                ReadingValues.up();
1966
 
            }
1967
 
            ReadingValues.up();
1968
 
        }
1969
 
        else
1970
 
            return false;
1971
 
    }
1972
 
    return true;
1973
 
}
1974
 
 
1975
 
std::list<toConnection::objectName> &toConnection::objects(bool block)
1976
 
{
1977
 
    if (!cacheAvailable(false, block))
1978
 
    {
1979
 
        toStatusMessage(qApp->translate("toConnection", "Not done caching objects"), false, false);
1980
 
        static std::list<objectName> ret;
1981
 
        return ret;
1982
 
    }
1983
 
 
1984
 
    return ObjectNames;
1985
 
}
1986
 
 
1987
 
void toConnection::addIfNotExists(toConnection::objectName &obj)
1988
 
{
1989
 
    if (!cacheAvailable(true, false))
1990
 
    {
1991
 
        toStatusMessage(qApp->translate("toConnection", "Not done caching objects"), false, false);
1992
 
        return ;
1993
 
    }
1994
 
    std::list<toConnection::objectName>::iterator i = ObjectNames.begin();
1995
 
    while (i != ObjectNames.end() && (*i) < obj)
1996
 
        i++;
1997
 
    if (i != ObjectNames.end() && *i == obj) // Already exists, don't add
1998
 
        return ;
1999
 
    ObjectNames.insert(i, obj);
2000
 
}
2001
 
 
2002
 
std::map<QString, toConnection::objectName> &toConnection::synonyms(bool block)
2003
 
{
2004
 
    if (!cacheAvailable(true, block))
2005
 
    {
2006
 
        toStatusMessage(qApp->translate("toConnection", "Not done caching objects"), false, false);
2007
 
        static std::map<QString, objectName> ret;
2008
 
        return ret;
2009
 
    }
2010
 
 
2011
 
    return SynonymMap;
2012
 
}
2013
 
 
2014
 
const toConnection::objectName &toConnection::realName(const QString &object,
2015
 
        QString &synonym,
2016
 
        bool block)
2017
 
{
2018
 
    if (!cacheAvailable(true, block))
2019
 
        throw qApp->translate("toConnection", "Not done caching objects");
2020
 
 
2021
 
    QString name;
2022
 
    QString owner;
2023
 
 
2024
 
    QString q = QString::fromLatin1("\"");
2025
 
    QString c = QString::fromLatin1(".");
2026
 
 
2027
 
    bool quote = false;
2028
 
    for (unsigned int pos = 0;pos < object.length();pos++)
2029
 
    {
2030
 
        if (object.at(pos) == q)
2031
 
        {
2032
 
            quote = !quote;
2033
 
        }
2034
 
        else
2035
 
        {
2036
 
            if (!quote && object.at(pos) == c)
2037
 
            {
2038
 
                owner = name;
2039
 
                name = QString::null;
2040
 
            }
2041
 
            else
2042
 
                name += object.at(pos);
2043
 
        }
2044
 
    }
2045
 
 
2046
 
    QString uo = owner.upper();
2047
 
    QString un = name.upper();
2048
 
 
2049
 
    synonym = QString::null;
2050
 
    for (std::list<objectName>::iterator i = ObjectNames.begin();i != ObjectNames.end();i++)
2051
 
    {
2052
 
        if (owner.isEmpty())
2053
 
        {
2054
 
            if (((*i).Name == un || (*i).Name == name) &&
2055
 
                    ((*i).Owner == user().upper() || (*i).Owner == database()))
2056
 
                return *i;
2057
 
        }
2058
 
        else if (((*i).Name == un || (*i).Name == name) &&
2059
 
                 ((*i).Owner == uo || (*i).Owner == owner))
2060
 
            return *i;
2061
 
    }
2062
 
    if (owner.isEmpty())
2063
 
    {
2064
 
        std::map<QString, objectName>::iterator i = SynonymMap.find(name);
2065
 
        if (i == SynonymMap.end() && un != name)
2066
 
        {
2067
 
            i = SynonymMap.find(un);
2068
 
            synonym = un;
2069
 
        }
2070
 
        else
2071
 
            synonym = name;
2072
 
        if (i != SynonymMap.end())
2073
 
        {
2074
 
            return (*i).second;
2075
 
        }
2076
 
    }
2077
 
    throw qApp->translate("toConnection", "Object %1 not available for %2").arg(object).arg(user());
2078
 
}
2079
 
 
2080
 
const toConnection::objectName &toConnection::realName(const QString &object, bool block)
2081
 
{
2082
 
    QString dummy;
2083
 
    return realName(object, dummy, block);
2084
 
}
2085
 
 
2086
 
toQDescList &toConnection::columns(const objectName &object, bool nocache)
2087
 
{
2088
 
    std::map<objectName, toQDescList>::iterator i = ColumnCache.find(object);
2089
 
    if (i == ColumnCache.end() || nocache)
2090
 
    {
2091
 
        ColumnCache[object] = Connection->columnDesc(object);
2092
 
    }
2093
 
 
2094
 
    return ColumnCache[object];
2095
 
}
2096
 
 
2097
 
bool toConnection::objectName::operator < (const objectName &nam) const
2098
 
{
2099
 
    if (Owner < nam.Owner || (Owner.isNull() && !nam.Owner.isNull()))
2100
 
        return true;
2101
 
    if (Owner > nam.Owner || (!Owner.isNull() && nam.Owner.isNull()))
2102
 
        return false;
2103
 
    if (Name < nam.Name || (Name.isNull() && !nam.Name.isNull()))
2104
 
        return true;
2105
 
    if (Name > nam.Name || (!Name.isNull() && nam.Name.isNull()))
2106
 
        return false;
2107
 
    if (Type < nam.Type)
2108
 
        return true;
2109
 
    return false;
2110
 
}
2111
 
 
2112
 
bool toConnection::objectName::operator == (const objectName &nam) const
2113
 
{
2114
 
    return Owner == nam.Owner && Name == nam.Name && Type == nam.Type;
2115
 
}
2116
 
 
2117
 
toSyntaxAnalyzer &toConnection::connectionImpl::analyzer()
2118
 
{
2119
 
    return toSyntaxAnalyzer::defaultAnalyzer();
2120
 
}
2121
 
 
2122
 
toSyntaxAnalyzer &toConnection::analyzer()
2123
 
{
2124
 
    return Connection->analyzer();
2125
 
}
2126
 
 
2127
 
std::list<toConnection::objectName> toConnection::connectionImpl::objectNames(void)
2128
 
{
2129
 
    std::list<toConnection::objectName> ret;
2130
 
    return ret;
2131
 
}
2132
 
 
2133
 
std::map<QString, toConnection::objectName> toConnection::connectionImpl::synonymMap(std::list<toConnection::objectName> &)
2134
 
{
2135
 
    std::map<QString, toConnection::objectName> ret;
2136
 
    return ret;
2137
 
}
2138
 
 
2139
 
toQDescList toConnection::connectionImpl::columnDesc(const objectName &)
2140
 
{
2141
 
    toQDescList ret;
2142
 
    return ret;
2143
 
}
2144
 
 
2145
 
void toConnection::connectionImpl::parse(toConnectionSub *, const QCString &)
2146
 
{
2147
 
    throw qApp->translate("toConnection", "Parse only not implemented for this type of connection");
2148
 
}