KDb

XbaseDriver.cpp
1 /* This file is part of the KDE project
2  Copyright (C) 2008 Sharan Rao <[email protected]>
3 
4  This program 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 program 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 program; see the file COPYING. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19 
20 #include "XbaseDriver.h"
21 
22 #include "KDbConnection.h"
23 #include "KDbDriverManager.h"
24 #include "KDbDriverBehavior.h"
25 #include "KDb.h"
26 
27 
28 #include "XbaseConnection.h"
29 
30 K_PLUGIN_CLASS_WITH_JSON(xBaseDriver, "kdb_xbasedriver.json")
31 
32 class KDbxBaseDriverPrivate {
33 
34 public:
35  xBaseDriverPrivate()
36  : internalDriver(0)
37  {
38  }
39 
40  KDbDriver* internalDriver;
41 
42 };
43 
44 xBaseDriver::xBaseDriver(QObject *parent, const QVariantList &args)
45  : KDbDriver(parent, args)
46  ,dp( new xBaseDriverPrivate() )
47 {
48  KDbDriverManager manager;
49  dp->internalDriver = manager.driver(KDb::defaultFileBasedDriverId());
50 
51 // d->isFileDriver = true ;
52  beh->features = SingleTransactions | CursorForward;
53 
54  // Everything below is for the SQLite (default file based) driver
55 
56  //special method for autoincrement definition
57  beh->SPECIAL_AUTO_INCREMENT_DEF = true;
58  beh->AUTO_INCREMENT_FIELD_OPTION = ""; //not available
59  beh->AUTO_INCREMENT_TYPE = "INTEGER";
60  beh->AUTO_INCREMENT_PK_FIELD_OPTION = "PRIMARY KEY";
61  beh->AUTO_INCREMENT_REQUIRES_PK = true;
62  beh->ROW_ID_FIELD_NAME = "OID";
63  beh->IS_DB_OPEN_AFTER_CREATE = true;
64 
65  beh->OPENING_QUOTATION_MARK_BEGIN_FOR_IDENTIFIER = '"';
66  beh->CLOSING_QUOTATION_MARK_BEGIN_FOR_IDENTIFIER = '"';
67  beh->SELECT_1_SUBQUERY_SUPPORTED = true;
68 
69  // As we provide a wrapper over SQLite, this aspect will be hidden by SQLite to us.
70  beh->_1ST_ROW_READ_AHEAD_REQUIRED_TO_KNOW_IF_THE_RESULT_IS_EMPTY=false;
71 
72  initDriverSpecificKeywords(keywords);
73 
74  // Ditto like SQLite , as it won't matter
75  beh->typeNames[KDbField::Byte]="Byte";
76  beh->typeNames[KDbField::ShortInteger]="ShortInteger";
77  beh->typeNames[KDbField::Integer]="Integer";
78  beh->typeNames[KDbField::BigInteger]="BigInteger";
79  beh->typeNames[KDbField::Boolean]="Boolean";
80  beh->typeNames[KDbField::Date]="Date";
81  beh->typeNames[KDbField::DateTime]="DateTime";
82  beh->typeNames[KDbField::Time]="Time";
83  beh->typeNames[KDbField::Float]="Float";
84  beh->typeNames[KDbField::Double]="Double";
85  beh->typeNames[KDbField::Text]="Text";
86  beh->typeNames[KDbField::LongText]="CLOB";
87  beh->typeNames[KDbField::BLOB]="BLOB";
88 }
89 
90 xBaseDriver::~xBaseDriver()
91 {
92  delete dp;
93 }
94 
95 KDbConnection* xBaseDriver::drv_createConnection(const KDbConnectionData& connData,
96  const KDbConnectionOptions &options)
97 {
98  if ( !dp->internalDriver ) {
99  return nullptr;
100  }
101  return new xBaseConnection(this, dp->internalDriver, connData, options);
102 }
103 
104 bool xBaseDriver::isSystemObjectName( const QString& n ) const
105 {
106  if ( !dp->internalDriver ) {
107  return false;
108  }
109  return dp->internalDriver->isSystemObjectName(n);
110 }
111 
112 bool xBaseDriver::isSystemDatabaseName(const QString& n) const
113 {
114  Q_UNUSED(n);
115  return false;
116 }
117 
118 bool xBaseDriver::drv_isSystemFieldName( const QString& n ) const
119 {
120  if ( !dp->internalDriver ) {
121  return false;
122  }
123  return dp->internalDriver->isSystemFieldName(n);
124 }
125 
126 KDbEscapedString xBaseDriver::escapeString(const QString& str) const
127 {
128  if ( !dp->internalDriver ) {
129  return KDbEscapedString("'") + str + '\'';
130  }
131  return dp->internalDriver->escapeString(str);
132 }
133 
134 KDbEscapedString xBaseDriver::escapeString(const QByteArray& str) const
135 {
136  if ( !dp->internalDriver ) {
137  return KDbEscapedString("'") + str + '\'';
138  }
139  return dp->internalDriver->escapeString(str);
140 }
141 
142 KDbEscapedString xBaseDriver::escapeBLOB(const QByteArray& array) const
143 {
144  if ( !dp->internalDriver ) {
145  return array;
146  }
147  return dp->internalDriver->escapeBLOB(array);
148 }
149 
150 QByteArray xBaseDriver::drv_escapeIdentifier( const QString& str) const
151 {
152  if ( !dp->internalDriver ) {
153  return str;
154  }
155  return dp->internalDriver->escapeIdentifier(str);
156 }
157 
158 QByteArray xBaseDriver::drv_escapeIdentifier( const QByteArray& str) const
159 {
160  if ( !dp->internalDriver ) {
161  return str;
162  }
163  return dp->internalDriver->escapeIdentifier(str);
164 }
@ Text
Definition: KDbField.h:98
Specialized string for escaping.
Database driver's abstraction.
Definition: KDbDriver.h:49
@ Integer
Definition: KDbField.h:90
Provides database connection, allowing queries and data modification.
@ BigInteger
Definition: KDbField.h:91
@ Double
Definition: KDbField.h:97
@ LongText
Definition: KDbField.h:99
@ Byte
Definition: KDbField.h:87
KDB_EXPORT QString defaultFileBasedDriverId()
Definition: KDb.cpp:1975
@ Boolean
Definition: KDbField.h:92
int features() const
Definition: KDbDriver.cpp:106
Database specific connection data, e.g. host, port.
Generic options for a single connection. The options are accessible using key/value pairs....
@ Float
Definition: KDbField.h:96
A driver manager for finding and loading driver plugins.
Provides database connection, allowing queries and data modification.
Definition: KDbConnection.h:51
#define K_PLUGIN_CLASS_WITH_JSON(classname, jsonFile)
@ ShortInteger
Definition: KDbField.h:89
KDbDriver * driver(const QString &id)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jun 25 2022 06:21:40 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.