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

« back to all changes in this revision

Viewing changes to help/api/toconnection_h.html

  • 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
 
<HTML>
2
 
<HEAD>
3
 
<TITLE>Source: toconnection.h</TITLE>
4
 
 
5
 
<META NAME="Generator" CONTENT="KDOC ">
6
 
</HEAD>
7
 
<BODY bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#000099" alink= "#ffffff">
8
 
<TABLE WIDTH="100%" BORDER="0">
9
 
<TR>
10
 
<TD>
11
 
        <TABLE BORDER="0">
12
 
                <TR><TD valign="top" align="left" cellspacing="10">
13
 
                <h1>Source: toconnection.h</h1>
14
 
                </TD>
15
 
                <TD valign="top" align="right" colspan="1"></TD></TR>
16
 
        </TABLE>
17
 
        <HR>
18
 
        <TABLE BORDER="0">
19
 
                
20
 
        </TABLE>
21
 
        </TD>
22
 
<TD align="right"><TABLE BORDER="0"><TR><TD><small><A HREF="index-long.html">Annotated List</A></small></TD></TR>
23
 
<TR><TD><small><A HREF="header-list.html">Files</A></small></TD></TR>
24
 
<TR><TD><small><A HREF="all-globals.html">Globals</A></small></TD></TR>
25
 
<TR><TD><small><A HREF="hier.html">Hierarchy</A></small></TD></TR>
26
 
<TR><TD><small><A HREF="index.html">Index</A></small></TD></TR>
27
 
</TABLE></TD></TR></TABLE>
28
 
<pre>
29
 
/*****
30
 
 *
31
 
 * TOra - An Oracle Toolkit for DBA's and developers
32
 
 * Copyright (C) 2003-2005 Quest Software, Inc
33
 
 * Portions Copyright (C) 2005 Other Contributors
34
 
 * 
35
 
 * This program is free software; you can redistribute it and/or
36
 
 * modify it under the terms of the GNU General Public License
37
 
 * as published by the Free Software Foundation;  only version 2 of
38
 
 * the License is valid for this program.
39
 
 * 
40
 
 * This program is distributed in the hope that it will be useful,
41
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
42
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
43
 
 * GNU General Public License for more details.
44
 
 * 
45
 
 * You should have received a copy of the GNU General Public License
46
 
 * along with this program; if not, write to the Free Software
47
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
48
 
 *
49
 
 *      As a special exception, you have permission to link this program
50
 
 *      with the Oracle Client libraries and distribute executables, as long
51
 
 *      as you follow the requirements of the GNU GPL in regard to all of the
52
 
 *      software in the executable aside from Oracle client libraries.
53
 
 *
54
 
 *      Specifically you are not permitted to link this program with the
55
 
 *      Qt/UNIX, Qt/Windows or Qt Non Commercial products of TrollTech.
56
 
 *      And you are not permitted to distribute binaries compiled against
57
 
 *      these libraries without written consent from Quest Software, Inc.
58
 
 *      Observe that this does not disallow linking to the Qt Free Edition.
59
 
 *
60
 
 *      You may link this product with any GPL'd Qt library such as Qt/Free
61
 
 *
62
 
 * All trademarks belong to their respective owners.
63
 
 *
64
 
 *****/
65
 
 
66
 
#ifndef TOCONNECTION_H
67
 
#define TOCONNECTION_H
68
 
 
69
 
#include "toqvalue.h"
70
 
#include "tothread.h"
71
 
 
72
 
#include <list>
73
 
#include <map>
74
 
#include <set>
75
 
 
76
 
#include <qstring.h>
77
 
 
78
 
class QWidget;
79
 
class toConnection;
80
 
class toConnectionProvider;
81
 
class toSQL;
82
 
class toQuery;
83
 
class toSyntaxAnalyzer;
84
 
 
85
 
/** This class is an abstract definition of an actual connection to a database.
86
 
 * Each @ref toConnection object can have one or more actual connections to the
87
 
 * database depending on long running queries. Normally you will never need to
88
 
 * bother with this class if you aren't creating a new database provider
89
 
 * (@ref toConnectionProvider).
90
 
 */
91
 
 
92
 
class toConnectionSub {
93
 
  toQuery *Query;
94
 
public:
95
 
  /** Create connection to database.
96
 
   */
97
 
  toConnectionSub()
98
 
  { Query=NULL; }
99
 
  /** Close connection.
100
 
   */
101
 
  virtual ~toConnectionSub()
102
 
  { }
103
 
  /** Query current running on connection or NULL.
104
 
   */
105
 
  toQuery *query()
106
 
  { return Query; }
107
 
  /** Set query currently running on connection. NULL means none.
108
 
   */
109
 
  void setQuery(toQuery *query)
110
 
  { Query=query; }
111
 
  /** Cancel anything running on this sub.
112
 
   */
113
 
  virtual void cancel(void)
114
 
  { }
115
 
};
116
 
 
117
 
/** This class is used to perform a query on a database connection.
118
 
 */
119
 
 
120
 
class toQuery {
121
 
public:
122
 
  /** Represent different modes to run a query in.
123
 
   */
124
 
  enum queryMode {
125
 
    /** Run the query normally on the main connection of the @ref toConnection object.
126
 
     */
127
 
    Normal,
128
 
    /** Run the query normally on the main backgrround connection of the
129
 
     * @ref toConnection object. This can be the same as the main connection depending
130
 
     * on settings.
131
 
     */
132
 
    Background,
133
 
    /** Run the query in a separate connection for long running queries.
134
 
     */
135
 
    Long,
136
 
    /** Run the query on all non occupied connections of the @ref toConnection object.
137
 
     */
138
 
    All
139
 
  };
140
 
 
141
 
  /** This structure is used to describe the resultset of a query.
142
 
   */
143
 
 
144
 
  struct queryDescribe {
145
 
    /** Column name
146
 
     */
147
 
    QString Name;
148
 
    /** Datatype of string.
149
 
     */
150
 
    QString Datatype;
151
 
    /** If column can contain null values.
152
 
     */
153
 
    bool Null;
154
 
    /** Preferred alignment of this kind of value.
155
 
     */
156
 
    bool AlignRight;
157
 
    /** Comment on column (Only filled out in column cache.
158
 
     */
159
 
    QString Comment;
160
 
  };
161
 
  /** Abstract parent of implementations of a query for a database provider
162
 
   * (See @ref toConnection::connectionImpl and @ref toConnectionProvider)
163
 
   */
164
 
  class queryImpl {
165
 
    toQuery *Parent;
166
 
  public:
167
 
    /** Get the parent query object. All the parameters of the query must be read from here.
168
 
     * nothing is passed to the functions.
169
 
     */
170
 
    toQuery *query()
171
 
    { return Parent; }
172
 
    
173
 
    /** Create a query implementation. The constructor must not perform any actions with the
174
 
     * database that could block for a noticable time (Like execute or parse a query). The
175
 
     * data for the query may not be available when this object created.
176
 
     * @param query Parent query object.
177
 
     */
178
 
    queryImpl(toQuery *query)
179
 
      : Parent(query)
180
 
    { }
181
 
    /** Destroy query implementation.
182
 
     */
183
 
    virtual ~queryImpl()
184
 
    { }
185
 
    /** Execute a query. Parameters can be gotten from the @ref toQuery object.
186
 
     */
187
 
    virtual void execute(void) = 0;
188
 
    /** Read the next value from the stream.
189
 
     * @return The value read from the query.
190
 
     */
191
 
    virtual toQValue readValue(void) = 0;
192
 
    /** Check if the end of the query has been reached.
193
 
     * @return True if all values have been read.
194
 
     */
195
 
    virtual bool eof(void) = 0;
196
 
    /** Get the number of rows processed in the last executed query.
197
 
     */
198
 
    virtual int rowsProcessed(void) = 0;
199
 
    /** Describe the currently running query.
200
 
     * @return A list of column descriptions of the query.
201
 
     */
202
 
    virtual std::list<queryDescribe> describe(void) = 0;
203
 
    /** Get number of columns in the resultset.
204
 
     * @return Column number.
205
 
     */
206
 
    virtual int columns(void) = 0;
207
 
    /** Cancel the current execution of a query. This will usually be called from another
208
 
     * thread than is executing the query.
209
 
     */
210
 
    virtual void cancel(void) = 0;
211
 
  };
212
 
 
213
 
private:
214
 
  toConnection &Connection;
215
 
  toConnectionSub *ConnectionSub;
216
 
  std::list<toQValue> Params;
217
 
  QCString SQL;
218
 
  queryMode Mode;
219
 
 
220
 
  queryImpl *Query;
221
 
  toQuery(const toQuery &);
222
 
public:
223
 
  /** Create a normal query.
224
 
   * @param conn Connection to create query on.
225
 
   * @param sql SQL to run.
226
 
   * @param params Parameters to pass to query.
227
 
   */
228
 
  toQuery(toConnection &conn,const toSQL &sql,const std::list<toQValue> &params);
229
 
  /** Create a normal query.
230
 
   * @param conn Connection to create query on.
231
 
   * @param sql SQL to run.
232
 
   * @param params Parameters to pass to query.
233
 
   */
234
 
  toQuery(toConnection &conn,const QString &sql,const std::list<toQValue> &params);
235
 
  /** Create a normal query.
236
 
   * @param conn Connection to create query on.
237
 
   * @param sql SQL to run.
238
 
   * @param arg1 Arguments to pass to query.
239
 
   */
240
 
  toQuery(toConnection &conn,const toSQL &sql,
241
 
          const QString &arg1=QString::null,const QString &arg2=QString::null,
242
 
          const QString &arg3=QString::null,const QString &arg4=QString::null,
243
 
          const QString &arg5=QString::null,const QString &arg6=QString::null,
244
 
          const QString &arg7=QString::null,const QString &arg8=QString::null,
245
 
          const QString &arg9=QString::null);
246
 
  /** Create a normal query.
247
 
   * @param conn Connection to create query on.
248
 
   * @param sql SQL to run.
249
 
   * @param arg1 Arguments to pass to query.
250
 
   */
251
 
  toQuery(toConnection &conn,const QString &sql,
252
 
          const QString &arg1=QString::null,const QString &arg2=QString::null,
253
 
          const QString &arg3=QString::null,const QString &arg4=QString::null,
254
 
          const QString &arg5=QString::null,const QString &arg6=QString::null,
255
 
          const QString &arg7=QString::null,const QString &arg8=QString::null,
256
 
          const QString &arg9=QString::null);
257
 
 
258
 
  /** Create a query.
259
 
   * @param conn Connection to create query on.
260
 
   * @param mode Mode to run query in.
261
 
   * @param sql SQL to run.
262
 
   * @param params Arguments to pass to query.
263
 
   */
264
 
  toQuery(toConnection &conn,queryMode mode,const toSQL &sql,const std::list<toQValue> &params);
265
 
  /** Create a query.
266
 
   * @param conn Connection to create query on.
267
 
   * @param mode Mode to run query in.
268
 
   * @param sql SQL to run.
269
 
   * @param params Arguments to pass to query.
270
 
   */
271
 
  toQuery(toConnection &conn,queryMode mode,const QString &sql,const std::list<toQValue> &params);
272
 
  /** Create a query. Don't runn any SQL using it yet. Observe though that the @ref
273
 
   * toConnectionSub object is assigned here so you know that all queries run using this
274
 
   * query object will run on the same actual connection to the database (Unless mode is All off
275
 
   * course).
276
 
   * @param conn Connection to create query for.
277
 
   * @param mode Mode to execute queries in.
278
 
   */
279
 
  toQuery(toConnection &conn,queryMode mode=Normal);
280
 
  /** Destroy query.
281
 
   */
282
 
  virtual ~toQuery();
283
 
 
284
 
  /** Execute an SQL statement using this query.
285
 
   * @param sql SQL to run.
286
 
   * @param params Parameters to pass to query.
287
 
   */
288
 
  void execute(const toSQL &sql,const std::list<toQValue> &params);
289
 
  /** Execute an SQL statement using this query.
290
 
   * @param sql SQL to run.
291
 
   * @param params Parameters to pass to query.
292
 
   */
293
 
  void execute(const QString &sql,const std::list<toQValue> &params);
294
 
 
295
 
  /** Connection object of this object.
296
 
   */
297
 
  toConnection &connection(void)
298
 
  { return Connection; }
299
 
  /** Actual database connection that this query is currently using.
300
 
   */
301
 
  toConnectionSub *connectionSub(void)
302
 
  { return ConnectionSub; }
303
 
  /** Parameters of the current query.
304
 
   */
305
 
  std::list<toQValue> &params(void)
306
 
  { return Params; }
307
 
  /** SQL to run. Observe that this string is in UTF8 format.
308
 
   */
309
 
  QCString sql(void)
310
 
  { return SQL; }
311
 
  /** Get the mode this query is executed in.
312
 
   */
313
 
  toQuery::queryMode mode(void) const
314
 
  { return Mode; }
315
 
 
316
 
  /** Read a value from the query. Convert the value NULL to the string {null}.
317
 
   * @return Value read.
318
 
   */
319
 
  toQValue readValue(void);
320
 
  /** Read a value from the query. Nulls are returned as empty @ref toQValue.
321
 
   * @return Value read.
322
 
   */
323
 
  toQValue readValueNull(void);
324
 
  /** Check if end of query is reached.
325
 
   * @return True if end of query is reached.
326
 
   */
327
 
  bool eof(void);
328
 
 
329
 
  /** Get the number of rows processed by the query.
330
 
   */
331
 
  int rowsProcessed(void)
332
 
  { return Query->rowsProcessed(); }
333
 
  /** Get a list of descriptions for the columns. This function is relatively slow.
334
 
   */
335
 
  std::list<queryDescribe> describe(void)
336
 
  { return Query->describe(); }
337
 
  /** Get the number of columns in the resultset of the query.
338
 
   */
339
 
  int columns(void)
340
 
  { return Query->columns(); }
341
 
 
342
 
  /** Execute a query and return all the values returned by it.
343
 
   * @param conn Connection to run query on.
344
 
   * @param sql SQL to run.
345
 
   * @param params Parameters to pass to query.
346
 
   * @return A list of @ref toQValues:s read from the query.
347
 
   */
348
 
  static std::list<toQValue> readQuery(toConnection &conn,
349
 
                                       const toSQL &sql,
350
 
                                       std::list<toQValue> &params);
351
 
  /** Execute a query and return all the values returned by it.
352
 
   * @param conn Connection to run query on.
353
 
   * @param sql SQL to run.
354
 
   * @param params Parameters to pass to query.
355
 
   * @return A list of @ref toQValues:s read from the query.
356
 
   */
357
 
  static std::list<toQValue> readQuery(toConnection &conn,
358
 
                                       const QString &sql,
359
 
                                       std::list<toQValue> &params);
360
 
  /** Execute a query and return all the values returned by it.
361
 
   * @param conn Connection to run query on.
362
 
   * @param sql SQL to run.
363
 
   * @param arg1 Parameters to pass to query.
364
 
   * @return A list of @ref toQValues:s read from the query.
365
 
   */
366
 
  static std::list<toQValue> readQuery(toConnection &conn,const toSQL &sql,
367
 
                                       const QString &arg1=QString::null,const QString &arg2=QString::null,
368
 
                                       const QString &arg3=QString::null,const QString &arg4=QString::null,
369
 
                                       const QString &arg5=QString::null,const QString &arg6=QString::null,
370
 
                                       const QString &arg7=QString::null,const QString &arg8=QString::null,
371
 
                                       const QString &arg9=QString::null);
372
 
  /** Execute a query and return all the values returned by it.
373
 
   * @param conn Connection to run query on.
374
 
   * @param sql SQL to run.
375
 
   * @param arg1 Parameters to pass to query.
376
 
   * @return A list of @ref toQValues:s read from the query.
377
 
   */
378
 
  static std::list<toQValue> readQuery(toConnection &conn,const QString &sql,
379
 
                                       const QString &arg1=QString::null,const QString &arg2=QString::null,
380
 
                                       const QString &arg3=QString::null,const QString &arg4=QString::null,
381
 
                                       const QString &arg5=QString::null,const QString &arg6=QString::null,
382
 
                                       const QString &arg7=QString::null,const QString &arg8=QString::null,
383
 
                                       const QString &arg9=QString::null);
384
 
  /** Execute a query and return all the values returned by it.
385
 
   * @param conn Connection to run query on.
386
 
   * @param sql SQL to run.
387
 
   * @param params Parameters to pass to query.
388
 
   * @return A list of @ref toQValues:s read from the query.
389
 
   */
390
 
  static std::list<toQValue> readQueryNull(toConnection &conn,
391
 
                                           const toSQL &sql,
392
 
                                           std::list<toQValue> &params);
393
 
  /** Execute a query and return all the values returned by it.
394
 
   * @param conn Connection to run query on.
395
 
   * @param sql SQL to run.
396
 
   * @param params Parameters to pass to query.
397
 
   * @return A list of @ref toQValues:s read from the query.
398
 
   */
399
 
  static std::list<toQValue> readQueryNull(toConnection &conn,
400
 
                                           const QString &sql,
401
 
                                           std::list<toQValue> &params);
402
 
  /** Execute a query and return all the values returned by it.
403
 
   * @param conn Connection to run query on.
404
 
   * @param sql SQL to run.
405
 
   * @param arg1 Parameters to pass to query.
406
 
   * @return A list of @ref toQValues:s read from the query.
407
 
   */
408
 
  static std::list<toQValue> readQueryNull(toConnection &conn,const toSQL &sql,
409
 
                                           const QString &arg1=QString::null,const QString &arg2=QString::null,
410
 
                                           const QString &arg3=QString::null,const QString &arg4=QString::null,
411
 
                                           const QString &arg5=QString::null,const QString &arg6=QString::null,
412
 
                                           const QString &arg7=QString::null,const QString &arg8=QString::null,
413
 
                                           const QString &arg9=QString::null);
414
 
  /** Execute a query and return all the values returned by it.
415
 
   * @param conn Connection to run query on.
416
 
   * @param sql SQL to run.
417
 
   * @param arg1 Parameters to pass to query.
418
 
   * @return A list of @ref toQValues:s read from the query.
419
 
   */
420
 
  static std::list<toQValue> readQueryNull(toConnection &conn,const QString &sql,
421
 
                                           const QString &arg1=QString::null,const QString &arg2=QString::null,
422
 
                                           const QString &arg3=QString::null,const QString &arg4=QString::null,
423
 
                                           const QString &arg5=QString::null,const QString &arg6=QString::null,
424
 
                                           const QString &arg7=QString::null,const QString &arg8=QString::null,
425
 
                                           const QString &arg9=QString::null);
426
 
  /** Cancel the current execution of a query.
427
 
   */
428
 
  void cancel(void);
429
 
};
430
 
 
431
 
/** A short representation of a @ref toQuery::queryDescribe
432
 
 */
433
 
typedef toQuery::queryDescribe toQDescribe;
434
 
/** A short representation of list<toQuery::queryDescribe>
435
 
 */
436
 
typedef std::list<toQDescribe> toQDescList;
437
 
 
438
 
/** Represent a database connection in TOra. Observe that this can mean several actual
439
 
 * connections to the database as queries that ae expected to run a long time are sometimes
440
 
 * executed in their own connection to make sure the interface doesn't lock up for a long time.
441
 
 */
442
 
class toConnection {
443
 
  QCString Provider;
444
 
  QString User;
445
 
  QString Password;
446
 
  QString Host;
447
 
  QString Database;
448
 
  QCString Version;
449
 
  std::list<QObject *> Widgets;
450
 
  std::list<QString> InitStrings;
451
 
  std::set<QString> Options;
452
 
  toLock Lock;
453
 
  std::list<toConnectionSub *> Connections;
454
 
  std::list<toConnectionSub *> Running;
455
 
  int BackgroundCount;
456
 
  toConnectionSub *BackgroundConnection;
457
 
  bool NeedCommit;
458
 
 
459
 
public:
460
 
 
461
 
  /** Class that could be used to throw exceptions in connection errors. Must use if you
462
 
   * want to indicate error offset.
463
 
   */
464
 
 
465
 
  class exception : public QString {
466
 
    int Offset;
467
 
  public:
468
 
    /** Create an exception with a string description.
469
 
     */
470
 
    exception(const QString &str,int offset=-1)
471
 
      : QString(str)
472
 
      { Offset=offset; }
473
 
    /** Get the offset of the error of the current statement.
474
 
     */
475
 
    int offset(void) const
476
 
    { return Offset; }
477
 
    /** Set the offset of the error of the error.
478
 
     */
479
 
    void setOffset(int offset)
480
 
    { Offset=offset; }
481
 
  };
482
 
 
483
 
  /** Contain information about a tablename.
484
 
   */
485
 
  struct objectName {
486
 
    /** The object name
487
 
     */
488
 
    QString Name;
489
 
    /** The schema that owns it
490
 
     */
491
 
    QString Owner;
492
 
    /** Object type
493
 
     */
494
 
    QString Type;
495
 
    /** Comment about this object
496
 
     */
497
 
    QString Comment;
498
 
    /** synonyms (used for faster disk caching...)
499
 
    */
500
 
    std::list <QString> Synonyms;
501
 
 
502
 
    /** Create an object name with filled in values.
503
 
     */
504
 
    objectName(const QString &owner,const QString &name,const QString &type=QString("TABLE"),const QString &comment=QString::null)
505
 
      : Name(name),Owner(owner),Type(type),Comment(comment)
506
 
    { }
507
 
 
508
 
    /** Create an empty object name.
509
 
     */
510
 
    objectName()
511
 
    { }
512
 
    bool operator < (const objectName &) const;
513
 
    bool operator == (const objectName &) const;
514
 
  };
515
 
 
516
 
  /** This class is an abstract baseclass to actually implement the comunication with the
517
 
   * database. 
518
 
   * (See also @ref toQuery::queryImpl and @ref toConnectionProvider)
519
 
   */
520
 
  class connectionImpl {
521
 
    toConnection *Connection;
522
 
  public:
523
 
    /** Get the parent connection object of this connection.
524
 
     */
525
 
    toConnection &connection(void)
526
 
    { return *Connection; }
527
 
    /** Create a new connection implementation for a connection.
528
 
     * @param conn Connection to implement.
529
 
     */
530
 
    connectionImpl(toConnection *conn)
531
 
    { Connection=conn; };
532
 
    /** Destructor.
533
 
     */
534
 
    virtual ~connectionImpl()
535
 
    { }
536
 
 
537
 
    /** Commit the supplied actual database connection.
538
 
     */
539
 
    virtual void commit(toConnectionSub *) = 0;
540
 
    /** Rollback the supplied actual database connection.
541
 
     */
542
 
    virtual void rollback(toConnectionSub *) = 0;
543
 
 
544
 
    /** If not true can never run more than one query per connection sub and TOra will
545
 
     * work around this limitation by opening more connections if needed.
546
 
     */
547
 
    virtual bool handleMultipleQueries()
548
 
    { return true; }
549
 
 
550
 
    /** Create a new connection to the database.
551
 
     */
552
 
    virtual toConnectionSub *createConnection(void) = 0;
553
 
    /** Close a connection to the database.
554
 
     */
555
 
    virtual void closeConnection(toConnectionSub *) = 0;
556
 
 
557
 
    /** Get the version of the database connected to.
558
 
     */
559
 
    virtual QCString version(toConnectionSub *) = 0;
560
 
 
561
 
    /** Return a string representation to address an object.
562
 
     * @param name The name to be quoted.
563
 
     * @return String addressing table.
564
 
     */
565
 
    virtual QString quote(const QString &name)
566
 
    { return name; }
567
 
    /** Perform the opposite of @ref quote.
568
 
     * @param name The name to be un-quoted.
569
 
     * @return String addressing table.
570
 
     */
571
 
    virtual QString unQuote(const QString &name)
572
 
    { return name; }
573
 
 
574
 
    /**
575
 
     * Get syntax analyzer for connection
576
 
     * @return A reference to the syntax analyzer to use for the connection.
577
 
     */
578
 
    virtual toSyntaxAnalyzer &analyzer();
579
 
 
580
 
    /** Extract available objects to query for connection. Any access to the
581
 
     * database should always be run using a long running query. If something
582
 
     * goes wrong should throw exception.
583
 
     * @return List of available objects.
584
 
     */
585
 
    virtual std::list<objectName> objectNames(void);
586
 
    /** Get synonyms available for connection. Any access to the
587
 
     * database should always be run using a long running query. If something
588
 
     * goes wrong should throw exception.
589
 
     * @param objects Available objects for the connection. Objects
590
 
     *                are sorted in owner and name order. Don't modify
591
 
     *                this list.
592
 
     * @return Map of synonyms to objectnames.
593
 
     */
594
 
    virtual std::map<QString,objectName> synonymMap(std::list<objectName> &objects);
595
 
    /* Extract available columns to query for a table.
596
 
     * @param table Table to get column for.
597
 
     * @return List of columns for table or view.
598
 
     */
599
 
    virtual toQDescList columnDesc(const objectName &table);
600
 
 
601
 
    /** Create a new query implementation for this connection.
602
 
     * @return A query implementation, allocated with new.
603
 
     */
604
 
    virtual toQuery::queryImpl *createQuery(toQuery *query,toConnectionSub *conn) = 0;
605
 
    /** Execute a query on an actual connection without caring about the result.
606
 
     * @param conn Connection to execute on.
607
 
     * @param sql SQL to execute.
608
 
     * @param params Parameters to pass to query.
609
 
     */
610
 
    virtual void execute(toConnectionSub *conn,const QCString &sql,toQList &params) = 0;
611
 
    /** Parse a query on an actual connection and report any syntax problems encountered.
612
 
     * Defaults to not implemented.
613
 
     * @param conn Connection to execute on.
614
 
     * @param sql SQL to parse
615
 
     */
616
 
    virtual void parse(toConnectionSub *conn,const QCString &sql);
617
 
  };
618
 
 
619
 
private:
620
 
 
621
 
  void addConnection(void);
622
 
  std::list<toConnectionSub *> &connections(void)
623
 
  { return Connections; }
624
 
 
625
 
  connectionImpl *Connection;
626
 
 
627
 
  class cacheObjects : public toTask {
628
 
    toConnection &Connection;
629
 
  public:
630
 
    cacheObjects(toConnection &conn)
631
 
      : Connection(conn)
632
 
    { }
633
 
    virtual void run(void);
634
 
  };
635
 
  friend class cacheObjects;
636
 
 
637
 
  bool ReadingCache;
638
 
  toSemaphore ReadingValues;
639
 
  bool Abort;
640
 
  std::map<objectName,toQDescList> ColumnCache;
641
 
  std::list<objectName> ObjectNames;
642
 
  std::map<QString,objectName> SynonymMap;
643
 
 
644
 
  toConnectionSub *mainConnection(void);
645
 
  toConnectionSub *longConnection(void);
646
 
  toConnectionSub *backgroundConnection(void);
647
 
  void freeConnection(toConnectionSub *);
648
 
  void readObjects(void);
649
 
 
650
 
  QString cacheFile();
651
 
public:
652
 
  /** Create a new connection.
653
 
   * @param provider Which database provider to use for this connection.
654
 
   * (See @ref to toDatabaseConnection)
655
 
   * @param user User to connect to the database with.
656
 
   * @param password Password to connect with.
657
 
   * @param host Host to connect to the database with.
658
 
   * @param database Database to connect to.
659
 
   * @param options Options used to connect to the database with.
660
 
   * @param cache Enable object cache for this connection.
661
 
   */
662
 
  toConnection(const QCString &provider,const QString &user,const QString &password,
663
 
               const QString &host,const QString &database,const std::set<QString> &options,
664
 
               bool cache=true);
665
 
  /** Create a copy of a connection. Will not cache objects, so objects will never be available
666
 
   *  in a subconnection.
667
 
   * @param conn Connection to copy.
668
 
   */
669
 
  toConnection(const toConnection &conn);
670
 
  /** Destroy connection.
671
 
   */
672
 
  virtual ~toConnection();
673
 
 
674
 
  //* Get the options for the connection.
675
 
  const std::set<QString> &options() const
676
 
  { return Options; }
677
 
  /** Try to close all the widgets associated with this connection.
678
 
   * @return True if all widgets agreed to close.
679
 
   */
680
 
  bool closeWidgets(void);
681
 
  /** Get username of connection.
682
 
   */
683
 
  const QString &user() const
684
 
  { return User; }
685
 
  /** Get password of connection.
686
 
   */
687
 
  const QString &password() const
688
 
  { return Password; }
689
 
  /** Change password of connection.
690
 
   */
691
 
  void setPassword(const QString &pwd)
692
 
  { Password=pwd; }
693
 
  /** Get host of connection.
694
 
   */
695
 
  const QString &host() const
696
 
  { return Host; }
697
 
  /** Get database of connection.
698
 
   */
699
 
  const QString &database() const
700
 
  { return Database; }
701
 
  /** Get version of connection.
702
 
   */
703
 
  const QCString &version() const
704
 
  { return Version; }
705
 
  /** Get provider of connection.
706
 
   */
707
 
  const QCString &provider() const;
708
 
 
709
 
  /** Change the current database. Observe that this only changes the record of what is the current database. You will still need
710
 
   * to change the database oppinion on what database is the current one.
711
 
   */
712
 
  void setDatabase(const QString &database)
713
 
  { Database=database; }
714
 
 
715
 
  /** Get a description of this connection.
716
 
   * @version Include version in returned string.
717
 
   */
718
 
  virtual QString description(bool version=true) const;
719
 
 
720
 
  /** Set if this connection needs to be commited.
721
 
   */
722
 
  void setNeedCommit(bool needCommit=true)
723
 
  { NeedCommit=needCommit; }
724
 
  /**
725
 
   * Get information about if the connection has uncommited data.
726
 
   *
727
 
   * @return Whether uncommited data is available.
728
 
   */
729
 
  bool needCommit(void) const
730
 
  { return NeedCommit; }
731
 
  /**
732
 
   * Commit connection. This will also close all extra connections except one.
733
 
   */
734
 
  virtual void commit(void);
735
 
  /**
736
 
   * Rollback connection. This will also close all extra connections except one.
737
 
   */
738
 
  virtual void rollback(void);
739
 
 
740
 
  /** Parse a query on an actual connection and report any syntax problems encountered.
741
 
   * Defaults to not implemented.
742
 
   * @param conn Connection to execute on.
743
 
   * @param sql SQL to parse
744
 
   */
745
 
  void parse(const QString &sql);
746
 
  /** Parse a query on an actual connection and report any syntax problems encountered.
747
 
   * Defaults to not implemented.
748
 
   * @param conn Connection to execute on.
749
 
   * @param sql SQL to parse
750
 
   */
751
 
  void parse(const toSQL &sql);
752
 
 
753
 
  /** Execute a statement without caring about the result.
754
 
   * @param sql SQL to execute
755
 
   * @param params Parameters to pass to query.
756
 
   */
757
 
  void execute(const toSQL &sql,
758
 
               toQList &params);
759
 
  /** Execute a statement without caring about the result.
760
 
   * @param sql SQL to execute
761
 
   * @param params Parameters to pass to query.
762
 
   */
763
 
  void execute(const QString &sql,
764
 
               toQList &params);
765
 
  /** Execute a statement without caring about the result.
766
 
   * @param sql SQL to execute
767
 
   * @param arg1 Parameters to pass to query.
768
 
   */
769
 
  void execute(const toSQL &sql,
770
 
               const QString &arg1=QString::null,const QString &arg2=QString::null,
771
 
               const QString &arg3=QString::null,const QString &arg4=QString::null,
772
 
               const QString &arg5=QString::null,const QString &arg6=QString::null,
773
 
               const QString &arg7=QString::null,const QString &arg8=QString::null,
774
 
               const QString &arg9=QString::null);
775
 
  /** Execute a statement without caring about the result.
776
 
   * @param sql SQL to execute
777
 
   * @param arg1 Parameters to pass to query.
778
 
   */
779
 
  void execute(const QString &sql,
780
 
               const QString &arg1=QString::null,const QString &arg2=QString::null,
781
 
               const QString &arg3=QString::null,const QString &arg4=QString::null,
782
 
               const QString &arg5=QString::null,const QString &arg6=QString::null,
783
 
               const QString &arg7=QString::null,const QString &arg8=QString::null,
784
 
               const QString &arg9=QString::null);
785
 
 
786
 
  /** Execute a statement without caring about the result on all open database connections.
787
 
   * @param sql SQL to execute
788
 
   * @param params Parameters to pass to query.
789
 
   */
790
 
  void allExecute(const toSQL &sql,
791
 
                  toQList &params);
792
 
  /** Execute a statement without caring about the result on all open database connections.
793
 
   * @param sql SQL to execute
794
 
   * @param params Parameters to pass to query.
795
 
   */
796
 
  void allExecute(const QString &sql,
797
 
                  toQList &params);
798
 
  /** Execute a statement without caring about the result on all open database connections.
799
 
   * @param sql SQL to execute
800
 
   * @param arg1 Parameters to pass to query.
801
 
   */
802
 
  void allExecute(const toSQL &sql,
803
 
                  const QString &arg1=QString::null,const QString &arg2=QString::null,
804
 
                  const QString &arg3=QString::null,const QString &arg4=QString::null,
805
 
                  const QString &arg5=QString::null,const QString &arg6=QString::null,
806
 
                  const QString &arg7=QString::null,const QString &arg8=QString::null,
807
 
                  const QString &arg9=QString::null);
808
 
  /** Execute a statement without caring about the result on all open database connections.
809
 
   * @param sql SQL to execute
810
 
   * @param arg1 Parameters to pass to query.
811
 
   */
812
 
  void allExecute(const QString &sql,
813
 
                  const QString &arg1=QString::null,const QString &arg2=QString::null,
814
 
                  const QString &arg3=QString::null,const QString &arg4=QString::null,
815
 
                  const QString &arg5=QString::null,const QString &arg6=QString::null,
816
 
                  const QString &arg7=QString::null,const QString &arg8=QString::null,
817
 
                  const QString &arg9=QString::null);
818
 
 
819
 
  /**
820
 
   * Add a object that uses this connection. This is needed to ensure that all widgets
821
 
   * that make use of a connection are destroyed when the connection is closed. Usually
822
 
   * tool windows need to call this function.
823
 
   *
824
 
   * @param widget The widget to add to the connection.
825
 
   */
826
 
  void addWidget(QObject *widget)
827
 
  { Widgets.insert(Widgets.end(),widget); }
828
 
  /**
829
 
   * Remove a widget from this connection. Should be called by the destructor of the
830
 
   * widget that has called addWidget.
831
 
   *
832
 
   * @see addWidget
833
 
   * @param widget Widget to remove from the widget list.
834
 
   */
835
 
  void delWidget(QObject *widget);
836
 
 
837
 
  /**
838
 
   * Add a statement to be run uppon making new connections.
839
 
   * @param sql Statement to run.
840
 
   */
841
 
  void addInit(const QString &sql);
842
 
  /**
843
 
   * Remove a statement that was added using @ref addInit.
844
 
   */
845
 
  void delInit(const QString &sql);
846
 
  /**
847
 
   * Get a list of the current init strings.
848
 
   */
849
 
  const std::list<QString> &toConnection::initStrings() const;
850
 
 
851
 
  /** Return a string representation to address an object.
852
 
   * @param name The name to be quoted.
853
 
   * @return String addressing table.
854
 
   */
855
 
  QString quote(const QString &name);
856
 
  /** Perform the opposite of @ref quote.
857
 
   * @param name The name to be un-quoted.
858
 
   * @return String addressing table.
859
 
   */
860
 
  QString unQuote(const QString &name);
861
 
 
862
 
  /**
863
 
   * Get the objects available for the current user. Do not modify the returned list.
864
 
   * @param block Indicate wether or not to block until cached objects are available.
865
 
   * @return A list of object available for the current user. The list is sorted in
866
 
   *         owner and name order.
867
 
   */
868
 
  std::list<objectName> &objects(bool block);
869
 
 
870
 
  /** Add a new object to the objectlist if it doesn't exist already.
871
 
   * @param object The object to add
872
 
   */
873
 
  void addIfNotExists(objectName &object);
874
 
 
875
 
  /**
876
 
   * Get syntax analyzer for connection
877
 
   * @return A reference to the syntax analyzer to use for the connection.
878
 
   */
879
 
  virtual toSyntaxAnalyzer &analyzer();
880
 
 
881
 
  /**
882
 
   * Get the synonyms available for objects. Do not modify the returned list.
883
 
   * @param block Indicate wether or not to block until cached objects are available.
884
 
   * @return A list of synonyms to objects available for the current user.
885
 
   */
886
 
  std::map<QString,objectName> &synonyms(bool block);
887
 
  /**
888
 
   * Get a list of the available columns for a table. This function caches the responses
889
 
   * and should be fairly fast after the first call. Do not modify the returned list.
890
 
   * @param table The table to describe.
891
 
   * @param nocache Don't use cached values even if they are available.
892
 
   * @return A list of the columns for a table.
893
 
   */
894
 
  toQDescList &columns(const objectName &table,bool nocache=false);
895
 
  /**
896
 
   * Reread the object and column cache.
897
 
   */
898
 
  void rereadCache(void);
899
 
  /**
900
 
   * Get the real object name of an object.
901
 
   * @param object Object name
902
 
   * @param block Block if not done caching object.
903
 
   */
904
 
  const objectName &realName(const QString &object,bool block);
905
 
  /**
906
 
   * Get the real object name of a synonym.
907
 
   * @param object Object name
908
 
   * @param synonym Filled with the synonym used to access the object returned or empty.
909
 
   * @param block Block if not done caching object.
910
 
   */
911
 
  const objectName &realName(const QString &object,QString &synonym,bool block);
912
 
  /** Check if cache is available or not.
913
 
   * @param synonyms If synonyms are needed or not.
914
 
   * @param block Block until cache is done.
915
 
   * @param true True if you need the cache, or just checking.
916
 
   * @return True if cache is available.
917
 
   */
918
 
  bool cacheAvailable(bool synonyms,bool block=false,bool need=true);
919
 
 
920
 
  /** Try to stop all running queries.
921
 
   */
922
 
  void cancelAll(void);
923
 
 
924
 
  /** load disk cache
925
 
   */
926
 
 
927
 
  bool loadDiskCache(void);
928
 
 
929
 
  /** write disk cache
930
 
   */
931
 
 
932
 
  void writeDiskCache(void);
933
 
 
934
 
  /** Get a list of currently running SQL.
935
 
   */
936
 
  std::list<QString> running(void);
937
 
 
938
 
  static QString cacheDir();
939
 
  
940
 
  friend class toQuery;
941
 
};
942
 
 
943
 
/** This class is used to implement new database providers.
944
 
 */
945
 
 
946
 
class toConnectionProvider {
947
 
  static std::map<QCString,toConnectionProvider *> *Providers;
948
 
  static std::map<QCString,toConnectionProvider *> *Types;
949
 
  QCString Provider;
950
 
  static void checkAlloc(void);
951
 
 
952
 
  /** Get the provider object for a given provider name.
953
 
   * @param provider Name of provider.
954
 
   * @return Reference to provider object.
955
 
   */
956
 
  static toConnectionProvider &fetchProvider(const QCString &provider);
957
 
protected:
958
 
  /** Add a provider to the list that this provider can handle.
959
 
   */
960
 
  void addProvider(const QCString &provider);
961
 
  /** Remove a provider from the list that this provider can handle.
962
 
   */
963
 
  void removeProvider(const QCString &provider);
964
 
public:
965
 
  /** Create a new provider with the specified name.
966
 
   * @param provider Name of the provider.
967
 
   */
968
 
  toConnectionProvider(const QCString &provider,bool add=true);
969
 
  /** Destructor.
970
 
   */
971
 
  virtual ~toConnectionProvider();
972
 
 
973
 
  /** Create an implementation of a connection to this database.
974
 
   * @param provider Provider to use for connection.
975
 
   * @param conn The connection object to use the created connection.
976
 
   * @return A connection implementation created with new.
977
 
   */
978
 
  virtual toConnection::connectionImpl *provideConnection(const QCString &provider,
979
 
                                                          toConnection *conn)=0;
980
 
  /** List the available hosts this database provider knows about.
981
 
   * @return A list of hosts.
982
 
   */
983
 
  virtual std::list<QString> providedHosts(const QCString &provider);
984
 
  /** List the available databases this provider knows about for a given host.
985
 
   * @param host Host to return connections for.
986
 
   * @param user That might be needed.
987
 
   * @param password That might be needed.
988
 
   * @return A list of databases available for a given host.
989
 
   */
990
 
  virtual std::list<QString> providedDatabases(const QCString &provider,
991
 
                                               const QString &host,
992
 
                                               const QString &user,
993
 
                                               const QString &pwd)=0;
994
 
  /** Will be called after program has been started and before connections have been opened.
995
 
   *  Use for initialization.
996
 
   */
997
 
  virtual void initialize(void)
998
 
  { }
999
 
 
1000
 
  /** Get a list of options available for the connection. An option with the name
1001
 
   * "-" indicates a break should be made to separate the rest of the options from the previous
1002
 
   * options. An option preceeded by "*" means selected by default. The * shoul be stripped before
1003
 
   * before passing it to the connection call.
1004
 
   */
1005
 
  virtual std::list<QString> providedOptions(const QCString &provider);
1006
 
 
1007
 
  /**
1008
 
   * Create and return configuration tab for this connectiontype. The returned widget should also
1009
 
   * be a childclass of @ref toSettingTab.
1010
 
   *
1011
 
   * @return A pointer to the widget containing the setup tab for this tool or NULL of
1012
 
   * no settings are available.
1013
 
   */
1014
 
  virtual QWidget *providerConfigurationTab(const QCString &provider,QWidget *parent);
1015
 
 
1016
 
  /** Get a list of names for providers.
1017
 
   */
1018
 
  static QWidget *configurationTab(const QCString &provider,QWidget *parent);
1019
 
  /** Get a list of names for providers.
1020
 
   */
1021
 
  static std::list<QCString> providers();
1022
 
  /** Get a list of options for a given provider.
1023
 
   */
1024
 
  static std::list<QString> options(const QCString &provider);
1025
 
  /** Implement a connection for a given provider.
1026
 
   * @param provider Provider to implement.
1027
 
   * @param conn Connection to create implementation for.
1028
 
   */
1029
 
  static toConnection::connectionImpl *connection(const QCString &provider,toConnection *conn);
1030
 
  /** Get a list of hosts this provider knows about.
1031
 
   */
1032
 
  static std::list<QString> hosts(const QCString &provider);
1033
 
  /** Get a list of databases for a given provider and host.
1034
 
   * @param provider Provider to fetch databases for.
1035
 
   * @param host Host to fetch databases for.
1036
 
   * @param user That might be needed.
1037
 
   * @param password That might be needed.
1038
 
   * @return List of known databases.
1039
 
   */
1040
 
  static std::list<QString> databases(const QCString &provider,const QString &host,
1041
 
                                      const QString &user,const QString &pwd);
1042
 
  /**
1043
 
   * Get connection specific settings.
1044
 
   *
1045
 
   * Setting names are hierachical separated by ':' instead of '/' usually used
1046
 
   * in filenames. As an example all settings for the tool 'Example' would be
1047
 
   * under the 'Example:{settingname}' name. Observe that the settings are stored
1048
 
   * under the main provider name as passed to the toConnectionProvider constructor.
1049
 
   *
1050
 
   * @param tag The name of the configuration setting.
1051
 
   * @param def Contents of this setting.
1052
 
   */
1053
 
  const QString &config(const QCString &tag,const QCString &def);
1054
 
  /**
1055
 
   * Change connectionspecific setting. Depending on the implementation this can change the
1056
 
   * contents on disk or not.
1057
 
   *
1058
 
   * Setting names are hierachical separated by ':' instead of '/' usually used
1059
 
   * in filenames. As an example all settings for the tool 'Example' would be
1060
 
   * under the 'Example:{settingname}' name. Observe that the settings are stored
1061
 
   * under the main provider name as passed to the toConnectionProvider constructor.
1062
 
   *
1063
 
   * @param tag The name of the configuration setting.
1064
 
   * @param def Default value of the setting, if it is not available.
1065
 
   */
1066
 
  void setConfig(const QCString &tag,const QCString &value);
1067
 
 
1068
 
  /** Call all initializers
1069
 
   */
1070
 
  static void initializeAll(void);
1071
 
};
1072
 
 
1073
 
#endif
1074
 
</pre>
1075
 
<HR>
1076
 
        <table>
1077
 
        <tr><td><small>Generated by: nneul on skyhawk on Wed Feb 23 19:49:58 2005, using kdoc 2.0a54.</small></td></tr>
1078
 
        </table>
1079
 
</BODY>
1080
 
</HTML>