KDb

SybaseDriver.cpp
1/* This file is part of the KDE project
2Copyright (C) 2007 Sharan Rao <sharanrao@gmail.com>
3
4This program is free software; you can redistribute it and/or
5modify it under the terms of the GNU Library General Public
6License as published by the Free Software Foundation; either
7version 2 of the License, or (at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12Library General Public License for more details.
13
14You should have received a copy of the GNU Library General Public License
15along with this program; see the file COPYING. If not, write to
16the 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
27K_PLUGIN_CLASS_WITH_JSON(SybaseDriver, "kdb_sybasedriver.json")
28
29SybaseDriver::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
88SybaseDriver::~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
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
145KDbEscapedString 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}
Database specific connection data, e.g. host, port.
Generic options for a single connection. The options are accessible using key/value pairs....
Provides database connection, allowing queries and data modification.
Database driver's abstraction.
Definition KDbDriver.h:50
int features() const
Specialized string for escaping.
@ Integer
Definition KDbField.h:90
@ Boolean
Definition KDbField.h:92
@ ShortInteger
Definition KDbField.h:89
@ BigInteger
Definition KDbField.h:91
@ LongText
Definition KDbField.h:99
#define K_PLUGIN_CLASS_WITH_JSON(classname, jsonFile)
Provides database connection, allowing queries and data modification.
Sybase database driver.
virtual KDbEscapedString escapeString(const QString &str) const
Escape a string for use as a value.
virtual bool isSystemDatabaseName(const QString &n) const
virtual KDbConnection * drv_createConnection(const KDbConnectionData &connData, const KDbConnectionOptions &options)
virtual QByteArray drv_escapeIdentifier(const QString &str) const
virtual bool drv_isSystemFieldName(const QString &n) const
virtual KDbEscapedString escapeBLOB(const QByteArray &array) const
Escape BLOB value array.
@ ZeroXHex
Escaping like 0x1FAD, used by mysql (hex numbers)
KDB_EXPORT QString escapeBLOB(const QByteArray &array, BLOBEscapingType type)
QByteArray & replace(QByteArrayView before, QByteArrayView after)
QByteArray toLower() const const
bool contains(const QSet< T > &other) const const
bool isEmpty() const const
QString & replace(QChar before, QChar after, Qt::CaseSensitivity cs)
QByteArray toLatin1() const const
QByteArray toUtf8() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:20:59 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.