KDb

KDbSimpleCommandLineApp.h
1 /* This file is part of the KDE project
2  Copyright (C) 2006 JarosÅ‚aw Staniek <[email protected]>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18 */
19 
20 #ifndef KDB_SIMPLECMDLINEAPP_H
21 #define KDB_SIMPLECMDLINEAPP_H
22 
23 #include <KDbConnection>
24 
25 #include <KAboutData>
26 
27 class KCmdLineOptions;
28 class KComponentData;
29 
30 //! @short A skeleton for creating a simple command line database application.
31 /*! This class creates a KComponentData object and automatically handles the following
32  command line options:
33  - --driver <id> (Database driver ID) or -drv
34  - --user <name> (Database user name) or -u
35  - --password (Prompt for password) or -p
36  - --host <name> (Server (host) name) or -h
37  - --port <number> (Server's port number)
38  - --local-socket <filename> (Server's local socket filename, if needed) or -s
39 
40  You can use this helper class to create test applications or small tools that open
41  a KDb-compatible database using command line arguments, do some data processing
42  and close the database.
43 */
44 class KDB_EXPORT KDbSimpleCommandLineApp : public KDbObject
45 {
46  Q_DECLARE_TR_FUNCTIONS(KDbSimpleCommandLineApp)
47 public:
49  int argc, char** argv,
50  const KCmdLineOptions &options, const char *programName,
51  const char *version, const char *shortDescription = 0,
52  KAboutData::LicenseKey licenseType = KAboutData::License_Unknown,
53  const char *copyrightStatement = 0, const char *text = 0,
54  const char *homePageAddress = 0, const char *bugsEmailAddress = "[email protected]");
55 
57 
58  //! @return program instance
59  const KComponentData &componentData() const;
60 
61  /*! Opens database @a databaseName for connection data
62  specified via the command line. @return true in success.
63  In details: the database driver is loaded, the connection is opened
64  and the database is used.
65  Use KDbObject methods to get status of the operation on failure. */
66  bool openDatabase(const QString& databaseName);
67 
68  /*! Closes database connection previously opened using openDatabase()
69  @return true on success. This method is called on destruction.
70  Use KDbObject methods to get status of the operation on failure. */
71  bool closeDatabase();
72 
73  /*! @return connection data for this application. */
74  KDbConnectionData* connectionData() const;
75 
76  /*! @return connection object for this application or 0 if there is no properly
77  opened connection. */
78  KDbConnection* connection() const;
79 
80 protected:
81  class Private;
82  Private * const d;
83  Q_DISABLE_COPY(KDbSimpleCommandLineApp)
84 };
85 
86 #endif
A skeleton for creating a simple command line database application.
unsigned int version()
Definition: KDb.cpp:336
Database specific connection data, e.g. host, port.
Provides database connection, allowing queries and data modification.
Definition: KDbConnection.h:51
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jun 25 2022 06:21:33 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.