KDb

SybaseDriver.cpp
1 /* This file is part of the KDE project
2 Copyright (C) 2007 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 
21 #include "SybaseDriver.h"
22 #include "SybaseConnection.h"
23 #include "KDbField.h"
24 #include "KDbDriverBehavior.h"
25 #include "KDb.h"
26 
27 K_PLUGIN_CLASS_WITH_JSON(SybaseDriver, "kdb_sybasedriver.json")
28 
29 SybaseDriver::SybaseDriver(QObject *parent, const QVariantList &args)
30  : KDbDriver(parent, args)
31 {
32  // Sybase supports Nested Transactions. Ignore for now
33  beh->features = IgnoreTransactions | CursorForward;
34 
35  // Last value assigned is stored in variable @@IDENTITY
36  beh->ROW_ID_FIELD_NAME = "@@IDENTITY";
37 
38  beh->ROW_ID_FIELD_RETURNS_LAST_AUTOINCREMENTED_VALUE = true ;
39 
40  beh->_1ST_ROW_READ_AHEAD_REQUIRED_TO_KNOW_IF_THE_RESULT_IS_EMPTY = false;
41  beh->USING_DATABASE_REQUIRED_TO_CONNECT = false;
42 
43  // for Sybase ASA this field is "DEFAULT AUTOINCREMENT"
44  // for MSSQL and Sybase ASE it's IDENTITY
45  beh->AUTO_INCREMENT_FIELD_OPTION = "IDENTITY";
46  beh->AUTO_INCREMENT_PK_FIELD_OPTION = beh->AUTO_INCREMENT_FIELD_OPTION + " PRIMARY KEY ";
47 
48  // confirm
49  //beh->SELECT_1_SUBQUERY_SUPPORTED = true;
50 
51  beh->OPENING_QUOTATION_MARK_BEGIN_FOR_IDENTIFIER = '"';
52  beh->CLOSING_QUOTATION_MARK_BEGIN_FOR_IDENTIFIER = '"';
53 
54  initDriverSpecificKeywords(m_keywords);
55 
56  //predefined properties
57  beh->properties["client_library_version"] = ""; //!< @todo
58  beh->properties["default_server_encoding"] = ""; //!< @todo
59 
60  // datatypes
61  // integers
62  beh->typeNames[KDbField::Byte] = "TINYINT";
63  beh->typeNames[KDbField::ShortInteger] = "SMALLINT";
64  beh->typeNames[KDbField::Integer] = "INT";
65  beh->typeNames[KDbField::BigInteger] = "BIGINT";
66 
67  // boolean
68  beh->typeNames[KDbField::Boolean] = "BIT";
69 
70  // date and time. There's only one integrated datetime datatype in Sybase
71  // Though there are smalldatetime (4 bytes) and datetime (8 bytes) data types
72  beh->typeNames[KDbField::Date] = "DATETIME";
73  beh->typeNames[KDbField::DateTime] = "DATETIME";
74  beh->typeNames[KDbField::Time] = "DATETIME"; // or should we use timestamp ?
75 
76  // floating point
77  beh->typeNames[KDbField::Float] = "REAL"; // 4 bytes
78  beh->typeNames[KDbField::Double] = "DOUBLE PRECISION"; // 8 bytes
79 
80  // strings
81  beh->typeNames[KDbField::Text] = "VARCHAR";
82  beh->typeNames[KDbField::LongText] = "TEXT";
83 
84  // Large Binary Objects
85  beh->typeNames[KDbField::BLOB] = "IMAGE";
86 }
87 
88 SybaseDriver::~SybaseDriver()
89 {
90 }
91 
93  const KDbConnectionOptions &options)
94 {
95  return new SybaseConnection(this, connData, options);
96 }
97 
99 {
100  if (m_systemDatabases.isEmpty()) {
101  m_systemDatabases << "master" << "model" << "sybsystemprocs" << "tempdb"
102  << "sybsecurity" << "sybsystemdb" << "pubs2" << "pubs3"
103  << "dbccdb";
104  }
105  return m_systemDatabases.contains(n.toLatin1().toLower());
106 }
107 
109 {
110  return false;
111 }
112 
114 {
115  return KDbEscapedString("'") + KDbEscapedString(str).replace("\'", "\\''") + '\'';
116 }
117 
119 {
121 }
122 
124 {
125  //! @todo needs any modification ?
126  return KDbEscapedString("'") + KDbEscapedString(str).replace("\'", "\\''") + '\'';
127 }
128 
130 {
131  //! @todo verify
132  return QByteArray("\"") + QByteArray(str.toUtf8()).replace("\\", "\\\\").replace("\"", "\"\"")
133  + "\"";
134 }
135 
137 {
138  // verify
139  return QByteArray("\"") + str
140  .replace("\\", "\\\\")
141  .replace("\"", "\"\"")
142  + "\"";
143 }
144 
145 KDbEscapedString SybaseDriver::addLimitTo1(const QString& sql, bool add)
146 {
147  // length of "select" is 6
148  // eg: before: select foo from foobar
149  // after: select TOP 1 foo from foobar
150  return add ? KDbEscapedString(sql).trimmed().insert(6, " TOP 1 ") : KDbEscapedString(sql);
151 }
virtual bool isSystemDatabaseName(const QString &n) const
QByteArray toLower() const const
Sybase database driver.
Definition: SybaseDriver.h:26
@ Text
Definition: KDbField.h:98
@ ZeroXHex
Escaping like 0x1FAD, used by mysql (hex numbers)
Specialized string for escaping.
virtual QByteArray drv_escapeIdentifier(const QString &str) const
Database driver's abstraction.
Definition: KDbDriver.h:49
QByteArray toLatin1() const const
Provides database connection, allowing queries and data modification.
@ Integer
Definition: KDbField.h:90
QByteArray toUtf8() const const
@ BigInteger
Definition: KDbField.h:91
@ Double
Definition: KDbField.h:97
bool contains(const T &value) const const
@ LongText
Definition: KDbField.h:99
QByteArray & replace(int pos, int len, const char *after)
QString & replace(int position, int n, QChar after)
@ Byte
Definition: KDbField.h:87
KDB_EXPORT QString escapeBLOB(const QByteArray &array, BLOBEscapingType type)
virtual KDbEscapedString escapeBLOB(const QByteArray &array) const
Escape BLOB value array.
virtual bool drv_isSystemFieldName(const QString &n) const
@ Boolean
Definition: KDbField.h:92
int features() const
Definition: KDbDriver.cpp:108
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
virtual KDbConnection * drv_createConnection(const KDbConnectionData &connData, const KDbConnectionOptions &options)
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
bool isEmpty() const const
virtual KDbEscapedString escapeString(const QString &str) const
Escape a string for use as a value.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon May 8 2023 04:07:52 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.