KDb

KDb Namespace Reference

Typedefs

typedef QList< const KDbExpressionData * > ExpressionCallStack
 

Enumerations

enum  BLOBEscapingType {
  BLOBEscapingType::XHex = 1, BLOBEscapingType::ZeroXHex, BLOBEscapingType::Hex, BLOBEscapingType::Octal,
  BLOBEscapingType::ByteaHex
}
 
enum  ExpressionClass {
  UnknownExpression, UnaryExpression, ArithmeticExpression, LogicalExpression,
  RelationalExpression, SpecialBinaryExpression, ConstExpression, VariableExpression,
  FunctionExpression, AggregationExpression, FieldListExpression, TableListExpression,
  ArgumentListExpression, QueryParameterExpression, LastExpressionClass = QueryParameterExpression
}
 
enum  IdentifierEscapingType { DriverEscaping, KDbEscaping }
 
enum  ObjectType {
  UnknownObjectType = -1, AnyObjectType = 0, TableObjectType = 1, QueryObjectType = 2,
  LastObjectType = 2, KDbSystemTableObjectType = 128, IndexObjectType = 256
}
 
enum  Signedness { Signed = 0, Unsigned = 1 }
 
enum  SplitToTableAndFieldPartsOptions { FailIfNoTableOrFieldName = 0, SetFieldNameIfNoTableName = 1 }
 

Functions

KDB_EXPORT QVariant cstringToVariant (const char *data, KDbField::Type type, bool *ok, int length=-1, KDb::Signedness signedness=KDb::Signed)
 
KDB_EXPORT KDbEscapedString dateTimeToIsoString (const QVariant &v)
 
KDB_DEPRECATED_EXPORT KDbEscapedString dateTimeToSql (const QDateTime &v)
 
KDB_EXPORT KDbEscapedString dateTimeToSql (const QVariant &v)
 
KDB_EXPORT KDbEscapedString dateToIsoString (const QVariant &v)
 
KDB_EXPORT KDbEscapedString dateToSql (const QVariant &v)
 
KDB_EXPORT KDbField::Type defaultFieldTypeForGroup (KDbField::TypeGroup typeGroup)
 
KDB_EXPORT QString defaultFileBasedDriverId ()
 
KDB_EXPORT QString defaultFileBasedDriverMimeType ()
 
KDB_EXPORT bool deleteAllRecords (KDbConnection *conn, const QString &tableName)
 
bool deleteAllRecords (KDbConnection *conn, const KDbTableSchema &table)
 
KDB_EXPORT bool deleteRecords (KDbConnection *conn, const QString &tableName, const QString &keyname, KDbField::Type keytype, const QVariant &keyval)
 
bool deleteRecords (KDbConnection *conn, const KDbTableSchema &table, const QString &keyname, KDbField::Type keytype, const QVariant &keyval)
 
bool deleteRecords (KDbConnection *conn, const QString &tableName, const QString &keyname, const QString &keyval)
 
bool deleteRecords (KDbConnection *conn, const KDbTableSchema &table, const QString &keyname, const QString &keyval)
 
bool deleteRecords (KDbConnection *conn, const KDbTableSchema &table, const QString &keyname, int keyval)
 
bool deleteRecords (KDbConnection *conn, const QString &tableName, const QString &keyname, int keyval)
 
KDB_EXPORT bool deleteRecords (KDbConnection *conn, const QString &tableName, const QString &keyname1, KDbField::Type keytype1, const QVariant &keyval1, const QString &keyname2, KDbField::Type keytype2, const QVariant &keyval2)
 
KDB_EXPORT bool deleteRecords (KDbConnection *conn, const QString &tableName, const QString &keyname1, KDbField::Type keytype1, const QVariant &keyval1, const QString &keyname2, KDbField::Type keytype2, const QVariant &keyval2, const QString &keyname3, KDbField::Type keytype3, const QVariant &keyval3)
 
KDB_EXPORT QList< int > deserializeIntList (const QString &data, bool *ok)
 
KDB_EXPORT QStringList deserializeList (const QString &data)
 
KDB_EXPORT QVariant emptyValueForFieldType (KDbField::Type type)
 
KDB_EXPORT QString escapeBLOB (const QByteArray &array, BLOBEscapingType type)
 
KDB_EXPORT QString escapeIdentifier (const QString &string)
 
KDB_EXPORT QByteArray escapeIdentifier (const QByteArray &string)
 
KDB_EXPORT QString escapeIdentifier (const KDbDriver *driver, const QString &string)
 
KDB_EXPORT QByteArray escapeIdentifier (const KDbDriver *driver, const QByteArray &str)
 
KDB_EXPORT QString escapeIdentifierAndAddQuotes (const QString &string)
 
KDB_EXPORT QByteArray escapeIdentifierAndAddQuotes (const QByteArray &string)
 
KDB_EXPORT QString escapeString (const QString &string)
 
KDB_EXPORT KDbEscapedString escapeString (KDbDriver *drv, const QString &string)
 
KDB_EXPORT KDbEscapedString escapeString (KDbConnection *conn, const QString &string)
 
KDB_EXPORT QStringList fieldTypeNamesForGroup (KDbField::TypeGroup typeGroup)
 
KDB_EXPORT const QList< KDbField::TypefieldTypesForGroup (KDbField::TypeGroup typeGroup)
 
KDB_EXPORT QStringList fieldTypeStringsForGroup (KDbField::TypeGroup typeGroup)
 
KDB_EXPORT void getFieldProperties (const KDbField &field, QMap< QByteArray, QVariant > *values)
 
KDB_EXPORT void getHTMLErrorMesage (const KDbResultable &resultable, QString *msg, QString *details)
 
KDB_EXPORT void getHTMLErrorMesage (const KDbResultable &resultable, QString *msg)
 
KDB_EXPORT void getHTMLErrorMesage (const KDbResultable &resultable, KDbResultInfo *info)
 
KDB_EXPORT void getLimitsForFieldType (KDbField::Type type, qlonglong *minValue, qlonglong *maxValue, KDb::Signedness signedness=KDb::Signed)
 
KDB_EXPORT void getProperties (const KDbLookupFieldSchema *lookup, QMap< QByteArray, QVariant > *values)
 
KDB_EXPORT QString identifierExpectedMessage (const QString &valueName, const QVariant &v)
 
KDB_EXPORT tristate idForObjectName (KDbConnection *conn, int *id, const QString &objName, int objType)
 
template<typename T >
iif (bool ok, const T &value)
 
template<typename T >
iifNotEmpty (const T &string, const T &stringIfEmpty)
 
template<typename T >
iifNotEmpty (const QByteArray &string, const T &stringIfEmpty)
 
template<typename T >
iifNotEmpty (const T &string, const QByteArray &stringIfEmpty)
 
KDB_EXPORT bool importSqliteFile (const QString &inputFileName, const QString &outputFileName)
 
KDB_EXPORT KDbField::Type intToFieldType (int type)
 
KDB_EXPORT KDbField::TypeGroup intToFieldTypeGroup (int typeGroup)
 
KDB_EXPORT bool isBuiltinTableFieldProperty (const QByteArray &propertyName)
 
KDB_EXPORT bool isDefaultValueAllowed (const KDbField &field)
 
KDB_EXPORT bool isEmptyValue (KDbField::Type type, const QVariant &value)
 
KDB_EXPORT bool isExtendedTableFieldProperty (const QByteArray &propertyName)
 
KDB_EXPORT bool isIdentifier (const QString &s)
 
KDB_EXPORT bool isIdentifier (const QByteArray &s)
 
KDB_EXPORT bool isKDbSqlKeyword (const QByteArray &word)
 
KDB_EXPORT bool isLookupFieldSchemaProperty (const QByteArray &propertyName)
 
KDB_EXPORT quint64 lastInsertedAutoIncValue (QSharedPointer< KDbSqlResult > result, const QString &autoIncrementFieldName, const QString &tableName, quint64 *recordId=nullptr)
 
KDB_EXPORT quint64 lastInsertedAutoIncValue (KDbConnection *conn, const quint64 recordId, const QString &autoIncrementFieldName, const QString &tableName)
 
quint64 lastInsertedAutoIncValue (QSharedPointer< KDbSqlResult > result, const QString &autoIncrementFieldName, const KDbTableSchema &table, quint64 *recordId=nullptr)
 
KDB_EXPORT QStringList libraryPaths ()
 
KDB_EXPORT int loadIntPropertyValueFromDom (const QDomNode &node, bool *ok)
 
KDB_EXPORT QVariant loadPropertyValueFromDom (const QDomNode &node, bool *ok)
 
KDB_EXPORT QString loadStringPropertyValueFromDom (const QDomNode &node, bool *ok)
 
KDB_EXPORT KDbField::Type maximumForIntegerFieldTypes (KDbField::Type t1, KDbField::Type t2)
 
KDB_EXPORT QVariant notEmptyValueForFieldType (KDbField::Type type)
 
KDB_EXPORT QString numberToLocaleString (double value, int decimalPlaces)
 
KDB_EXPORT QString numberToLocaleString (double value, int decimalPlaces, const QLocale &locale)
 
KDB_EXPORT QString numberToString (double value, int decimalPlaces)
 
KDB_EXPORT QByteArray pgsqlByteaToByteArray (const char *data, int length=-1)
 
KDB_EXPORT QDomElement saveBooleanElementToDom (QDomDocument *doc, QDomElement *parentEl, const QString &elementName, bool value)
 
KDB_EXPORT QDomElement saveNumberElementToDom (QDomDocument *doc, QDomElement *parentEl, const QString &elementName, int value)
 
KDB_EXPORT QString serializeList (const QStringList &list)
 
KDB_EXPORT bool setFieldProperties (KDbField *field, const QMap< QByteArray, QVariant > &values)
 
KDB_EXPORT bool setFieldProperty (KDbField *field, const QByteArray &propertyName, const QVariant &value)
 
KDB_EXPORT tristate showConnectionTestDialog (QWidget *parent, const KDbConnectionData &data, KDbMessageHandler *msgHandler)
 
KDB_EXPORT QString simplifiedFieldTypeName (KDbField::Type type)
 
KDB_EXPORT bool splitToTableAndFieldParts (const QString &string, QString *tableName, QString *fieldName, SplitToTableAndFieldPartsOptions option=FailIfNoTableOrFieldName)
 
KDB_EXPORT QString sqlite3ProgramPath ()
 
KDB_EXPORT KDbEscapedString sqlWhere (KDbDriver *drv, KDbField::Type t, const QString &fieldName, const QVariant &value)
 
KDB_EXPORT QList< int > stringListToIntList (const QStringList &list, bool *ok=nullptr)
 
KDB_EXPORT QString stringToIdentifier (const QString &s)
 
KDB_EXPORT QVariant stringToVariant (const QString &s, QVariant::Type type, bool *ok)
 
KDB_EXPORT bool supportsVisibleDecimalPlacesProperty (KDbField::Type type)
 
KDB_EXPORT QString temporaryTableName (KDbConnection *conn, const QString &baseName)
 
KDB_EXPORT KDbEscapedString timeToIsoString (const QVariant &v)
 
KDB_EXPORT KDbEscapedString timeToSql (const QVariant &v)
 
KDB_EXPORT QString unescapeString (const QString &string, char quote, int *errorPosition=nullptr)
 
KDbEscapedString valueToSql (const KDbDriver *driver, KDbField::Type ftype, const QVariant &v)
 
KDB_EXPORT KDbEscapedString valueToSql (KDbField::Type ftype, const QVariant &v)
 
KDB_EXPORT QString variantToString (const QVariant &v)
 
KDB_EXPORT KDbVersionInfo version ()
 
KDB_EXPORT QByteArray xHexToByteArray (const char *data, int length=-1, bool *ok=nullptr)
 
KDB_EXPORT QByteArray zeroXHexToByteArray (const char *data, int length=-1, bool *ok=nullptr)
 

Detailed Description

A database connectivity and creation framework.

KDb is consisted of a general-purpose C++ Qt library and set of plugins delivering support for various database vendors.

Framework

KDbDriverManager KDbDriverMetaData KDbDriver

Database access

Database structure

Data representation

Tools

Drivers

Drivers are loaded as plugins on demand by KDbDriverManager. The IDs, descriptions and other details about drivers are given in their metadata by KDbDriverManager::driverMetaData(). The metadata is accessible without actually loading any driver.

KDb supports two families of databases, file and network-based while providing a single uniform API.

Each database driver implements of three main classes KDbDriver, KDbConnection, KDbCursor. The driver classes handle database-related specifics such as data types, naming and hide them behind a general purpose API. The connection classes act as a proxy between the KDb API and the native database. The cursor classes implement cursor functionality specific to the native database at record level.

Enumeration Type Documentation

enum KDb::BLOBEscapingType
strong

Escaping types for BLOBS. Used in escapeBLOB().

Enumerator
XHex 

Escaping like X'1FAD', used by sqlite (hex numbers)

ZeroXHex 

Escaping like 0x1FAD, used by mysql (hex numbers)

Hex 

Escaping like 1FAD without quotes or prefixes.

Octal 

Escaping like 'zk\000$x', used by PostgreSQL.

(only non-printable characters are escaped using octal numbers); see https://www.postgresql.org/docs/9.5/interactive/datatype-binary.html

ByteaHex 

"bytea hex" escaping, e.g.

E''::bytea used by PostgreSQL (only non-printable characters are escaped using octal numbers); see https://www.postgresql.org/docs/9.5/interactive/datatype-binary.html

Definition at line 535 of file KDb.h.

Classes of expressions.

Enumerator
LastExpressionClass 

This line should be at the end of the list.

Definition at line 44 of file KDbExpressionData.h.

Escaping type for identifiers.

Enumerator
DriverEscaping 

Identifiers are escaped by driver.

KDbEscaping 

Identifiers are escaped using KDb's generic convention.

Definition at line 144 of file KDbGlobal.h.

Object types set like table or query.

Enumerator
UnknownObjectType 

helper

AnyObjectType 

helper

KDbSystemTableObjectType 

helper, not used in storage (allows to select KDb system tables may be or'd with TableObjectType)

IndexObjectType 

special

Definition at line 130 of file KDbGlobal.h.

A property of numeric values.

Enumerator
Signed 

Values can be both positive and negative.

Unsigned 

Values can be both non-negative.

Definition at line 150 of file KDbGlobal.h.

Used in splitToTableAndFieldParts().

Enumerator
FailIfNoTableOrFieldName 

default value for splitToTableAndFieldParts()

SetFieldNameIfNoTableName 

see splitToTableAndFieldParts()

Definition at line 246 of file KDb.h.

Function Documentation

QVariant KDb::cstringToVariant ( const char *  data,
KDbField::Type  type,
bool *  ok,
int  length = -1,
KDb::Signedness  signedness = KDb::Signed 
)
Returns
QVariant value converted from a data string

Conversion is based on the information about type type. type has to be an element from KDbField::Type, not greater than KDbField::LastType. For unsupported type this function fails. length value controls number of characters used in the conversion. It is optional value for all cases but for the BLOB type because for it data is not null-terminated so the length cannot be measured. The value of signedness controls the conversion in case of integer types; numbers can be limited to unsigned or not. If ok is not 0 *ok is set to false on failure and to true on success. On failure a null QVariant is returned. The function fails if data is 0. For rules of conversion to the boolean type see the documentation of QVariant::toBool(), QVariant::toDate() for date type, QVariant::toDateTime() for date+time type, QVariant::toTime() for time type.

Todo:
use KDbDriverBehavior::TEXT_TYPE_MAX_LENGTH for Text type?
Todo:
date/time?

Definition at line 1992 of file KDb.cpp.

KDbEscapedString KDb::dateTimeToIsoString ( const QVariant v)

Converts date/time value to its string representation in ISO 8601 DateTime format - with "T" delimiter.

The string is enclosed with single quotes "'". It is compatible with SQLite format for the date/time type. It is used as default implementation for drivers in KDbDriver::dateTimeToSql().

If the v value is convertible to KDbDateTime then KDbDateTime::toString() is used to obtain the result. Otherwise the value is converted to QDateTime and QDateTime::toString() is used as well as QTime::toString() to obtain the result. If the time's milliseconds value is zero, it is not included.

"<INVALID_DATETIME>" string is returned for invalid (also null) time values.

For specification of the ISO format see https://www.w3.org/TR/NOTE-datetime.

Example value: "'1994-11-05T13:15:30'", not "'1994-11-05 13:15:30'".

Since
3.2.0

Definition at line 2305 of file KDb.cpp.

KDbEscapedString KDb::dateTimeToSql ( const QDateTime v)

Converts date/time value to its string representation in ISO 8601 DateTime format - with "T" delimiter.

Note
This method is deprecated since 3.1.1, use KDb::dateTimeToIsoString() which has identical effect. The ISO format is no longer used for creating KDBSQL statements. Prior to this version it was used to generate date/time constants in KDb::valueToSql(KDbField::Type ftype, const QVariant& v) for KDbField::DateTime type. KDb::dateTimeToIsoString() is still used as default implementation for drivers in KDbDriver::dateTimeToSql().

KDb 3.1.0 improved type safety for KDBSQL so Text type are no longer compatible with Date/Time types. By implementing wish https://bugs.kde.org/393094 format of date/time constants for KDBSQL has been strictly defined in a backend-independent way. See https://community.kde.org/Kexi/Plugins/Queries/SQL_Constants for details.

Definition at line 2290 of file KDb.cpp.

KDbEscapedString KDb::dateTimeToSql ( const QVariant v)

Converts date/time value to its string representation required by KDBSQL commands.

The value can be of type QDateTime or KDbDateTime. If the value is not one of these types or is invalid QDateTime or is a null KDbDateTime then "<INVALID_DATETIME>" is returned. If the value is of type KDbDateTime that is not null then even if some components of the date/time are invalid, properly formatted string is returned. If the time's milliseconds value is zero, it is not included.

See https://community.kde.org/Kexi/Plugins/Queries/SQL_Constants for details.

Example values: "#1994-11-05 13:15#", "#1994-11-05 13:9:30#", "#1994-9-05 13:15:30.921#".

Since
3.2.0

Definition at line 2285 of file KDb.cpp.

KDbEscapedString KDb::dateToIsoString ( const QVariant v)

Converts date value to its string representation in ISO 8601 DateTime format.

The string is enclosed with single quotes "'". It is compatible with SQLite format for the date type. It is used as default implementation for drivers in KDbDriver::dateToSql().

If the v value is convertible to KDbDate then KDbDate::toString() is used to obtain the result. Otherwise the value is converted to QDate and QDate::toString(Qt::ISODate) is used to obtain the result.

"<INVALID_DATE>" string is returned for invalid (also null) date values.

For specification of the ISO format see https://www.w3.org/TR/NOTE-datetime.

Example value: "'1994-11-05'".

Since
3.2.0

Definition at line 2295 of file KDb.cpp.

KDbEscapedString KDb::dateToSql ( const QVariant v)

Converts date value to its string representation required by KDBSQL commands.

The value can be of type QDate or KDbDate. If the value is not one of these types or is invalid QDate or is a null KDbDate then "<INVALID_DATE>" is returned. If the value is of type KDbDate that is not null then even if some components of the date are invalid, properly formatted string is returned.

Example values: "#1994-11-05", "#1994-9-05#".

See https://community.kde.org/Kexi/Plugins/Queries/SQL_Constants for details.

Since
3.2.0

Definition at line 2231 of file KDb.cpp.

KDbField::Type KDb::defaultFieldTypeForGroup ( KDbField::TypeGroup  typeGroup)
Returns
default field type for field type group typeGroup, for example, KDbField::Integer for KDbField::IntegerGroup. It is used e.g. in KexiAlterTableDialog, to properly fill 'type' property when user selects type group for a field.

Definition at line 500 of file KDb.cpp.

QString KDb::defaultFileBasedDriverId ( )
Returns
default file-based driver ID (currently, "org.kde.kdb.sqlite").

Definition at line 1975 of file KDb.cpp.

QString KDb::defaultFileBasedDriverMimeType ( )
Returns
default file-based driver MIME type (typically something like "application/x-kexiproject-sqlite")

Definition at line 1970 of file KDb.cpp.

bool KDb::deleteAllRecords ( KDbConnection conn,
const QString tableName 
)

Deletes all records from table tableName.

Definition at line 384 of file KDb.cpp.

bool KDb::deleteAllRecords ( KDbConnection conn,
const KDbTableSchema table 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 109 of file KDb.h.

bool KDb::deleteRecords ( KDbConnection conn,
const QString tableName,
const QString keyname,
KDbField::Type  keytype,
const QVariant keyval 
)

Deletes records using one generic criteria.

Returns
true on success and false on failure and if conn is nullptr

Definition at line 342 of file KDb.cpp.

bool KDb::deleteRecords ( KDbConnection conn,
const KDbTableSchema table,
const QString keyname,
KDbField::Type  keytype,
const QVariant keyval 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 60 of file KDb.h.

bool KDb::deleteRecords ( KDbConnection conn,
const QString tableName,
const QString keyname,
const QString keyval 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 67 of file KDb.h.

bool KDb::deleteRecords ( KDbConnection conn,
const KDbTableSchema table,
const QString keyname,
const QString keyval 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 74 of file KDb.h.

bool KDb::deleteRecords ( KDbConnection conn,
const KDbTableSchema table,
const QString keyname,
int  keyval 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 81 of file KDb.h.

bool KDb::deleteRecords ( KDbConnection conn,
const QString tableName,
const QString keyname,
int  keyval 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 88 of file KDb.h.

bool KDb::deleteRecords ( KDbConnection conn,
const QString tableName,
const QString keyname1,
KDbField::Type  keytype1,
const QVariant keyval1,
const QString keyname2,
KDbField::Type  keytype2,
const QVariant keyval2 
)

Deletes records with two generic criterias.

Definition at line 353 of file KDb.cpp.

bool KDb::deleteRecords ( KDbConnection conn,
const QString tableName,
const QString keyname1,
KDbField::Type  keytype1,
const QVariant keyval1,
const QString keyname2,
KDbField::Type  keytype2,
const QVariant keyval2,
const QString keyname3,
KDbField::Type  keytype3,
const QVariant keyval3 
)

Deletes records with three generic criterias.

Definition at line 367 of file KDb.cpp.

QList< int > KDb::deserializeIntList ( const QString data,
bool *  ok 
)
Returns
int list converted from data which was built using serializeList(). Separators are ',' characters, escaping is assumed as "\\,". If ok is not 0, *ok is set to result of the conversion.
See also
KDb::stringListToIntList()

Definition at line 1850 of file KDb.cpp.

QStringList KDb::deserializeList ( const QString data)
Returns
string list converted from data which was built using serializeList(). Separators are ',' characters, escaping is assumed as "\\,".

Definition at line 1821 of file KDb.cpp.

QVariant KDb::emptyValueForFieldType ( KDbField::Type  type)

Used in KDb::emptyValueForFieldType()

Returns
equivalent of empty (default) value that can be set for a database field of type type

In particular returns:

  • empty string for text types,
  • 0 for integer and floating-point types,
  • false for boolean types,
  • a null byte array for BLOB type,
  • current date, time, date+time is returned (measured at client side) for date, time and date/time types respectively,
  • a null QVariant for unsupported values such as KDbField::InvalidType.

Definition at line 1222 of file KDb.cpp.

KDB_EXPORT QString KDb::escapeBLOB ( const QByteArray array,
BLOBEscapingType  type 
)
Returns
a string containing escaped, printable representation of array. Escaping is controlled by type. For empty array, QString() is returned, so if you want to use this function in an SQL statement, empty arrays should be detected and "NULL" string should be put instead. This is helper, used in KDbDriver::escapeBLOB() and KDb::variantToString().
QString KDb::escapeIdentifier ( const QString string)
Returns
string string with applied KDBSQL identifier escaping

This escaping can be used for field, table, database names, etc. Use it for user-visible backend-independent statements.

See also
KDb::escapeIdentifierAndAddQuotes()

Definition at line 1334 of file KDb.cpp.

QByteArray KDb::escapeIdentifier ( const QByteArray string)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 1340 of file KDb.cpp.

KDB_EXPORT QString KDb::escapeIdentifier ( const KDbDriver driver,
const QString string 
)
Returns
string string with applied driver-specific identifier escaping if driver is not KDbSQL general identifier escaping when driver is 0.

This escaping can be used for field, table, database names, etc.

See also
KDb::escapeIdentifier

Definition at line 408 of file KDbDriver.cpp.

KDB_EXPORT QByteArray KDb::escapeIdentifier ( const KDbDriver driver,
const QByteArray str 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 415 of file KDbDriver.cpp.

QString KDb::escapeIdentifierAndAddQuotes ( const QString string)
Returns
string string with applied KDBSQL identifier escaping and enclosed in " quotes

This escaping can be used for field, table, database names, etc. Use it for user-visible backend-independent statements.

See also
KDb::escapeIdentifier

Definition at line 1346 of file KDb.cpp.

QByteArray KDb::escapeIdentifierAndAddQuotes ( const QByteArray string)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 1351 of file KDb.cpp.

QString KDb::escapeString ( const QString string)
Returns
escaped string string for the KDBSQL dialect, i.e. doubles single quotes ("'") and inserts the string into single quotes. Quotes "'" are prepended and appended. Also escapes \n, \r, \t, \\, \0. Use it for user-visible backend-independent statements.
See also
unescapeString()

Definition at line 1356 of file KDb.cpp.

KDbEscapedString KDb::escapeString ( KDbDriver drv,
const QString string 
)

Returns escaped string string.

If drv driver is present, it is used to perform escaping, otherwise escapeString() is used so the KDBSQL dialect-escaping is performed.

Since
3.1.0

Definition at line 1385 of file KDb.cpp.

KDbEscapedString KDb::escapeString ( KDbConnection conn,
const QString string 
)

Returns escaped string string.

If conn is present, its driver is used to perform escaping, otherwise escapeString() is used so the KDBSQL dialect-escaping is performed.

Since
3.1.0

Definition at line 1390 of file KDb.cpp.

QStringList KDb::fieldTypeNamesForGroup ( KDbField::TypeGroup  typeGroup)
Returns
list of translated field type names for field type group typeGroup.

Definition at line 490 of file KDb.cpp.

const QList< KDbField::Type > KDb::fieldTypesForGroup ( KDbField::TypeGroup  typeGroup)
Returns
list of field types for field type group typeGroup.

Definition at line 485 of file KDb.cpp.

QStringList KDb::fieldTypeStringsForGroup ( KDbField::TypeGroup  typeGroup)
Returns
list of (nontranslated) field type names for field type group typeGroup.

Definition at line 495 of file KDb.cpp.

void KDb::getFieldProperties ( const KDbField field,
QMap< QByteArray, QVariant > *  values 
)

Gets property values for field. Properties from extended schema are included. values is cleared before filling. The same number of properties in the same order is returned. This function is used e.g. for altering table design. Nothing is performed if values is nullptr.

Todo:
IMPORTANT: values->insert("defaultWidth", field.defaultWidth());

Definition at line 787 of file KDb.cpp.

void KDb::getHTMLErrorMesage ( const KDbResultable resultable,
QString msg,
QString details 
)

Sets HTML-formatted error message with extra details obtained from result object.

Sets string pointed by msg to an error message retrieved from resultable, and string pointed by details to details of this error (server message and result number). Does nothing if there is no error (resultable.result().isError() == false) or if msg or details is nullptr. In this case strings pointer by msg and details strings are not changed. If the string pointed by msg is not empty, it is not modified and message obtained from resultable is appended to the string pointed by details instead.

Definition at line 505 of file KDb.cpp.

void KDb::getHTMLErrorMesage ( const KDbResultable resultable,
QString msg 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This methods works similarly but appends both a message and a description to string pointed by msg.

Definition at line 565 of file KDb.cpp.

void KDb::getHTMLErrorMesage ( const KDbResultable resultable,
KDbResultInfo info 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This methods similarly but outputs message to info instead.

Definition at line 570 of file KDb.cpp.

void KDb::getLimitsForFieldType ( KDbField::Type  type,
qlonglong *  minValue,
qlonglong *  maxValue,
KDb::Signedness  signedness = KDb::Signed 
)

Provides limits for values of type type.

The result is put into integers pointed by minValue and maxValue. The limits are machine-independent,. what is useful for format and protocol compatibility. Supported types are Byte, ShortInteger, Integer and BigInteger. The value of signedness controls the values; they can be limited to unsigned or not. Results for BigInteger or non-integer types are the same as for Integer due to limitation of int type. Signed integers are assumed. minValue and maxValue must not be 0.

Todo:
always ok?

<

Todo:
cannot return anything larger?

Definition at line 1920 of file KDb.cpp.

void KDb::getProperties ( const KDbLookupFieldSchema lookup,
QMap< QByteArray, QVariant > *  values 
)

Gets property values for the lookup schema lookup. values is not cleared before filling. This function is used e.g. for altering table design. Nothing is performed if values is nullptr. If lookup is nullptr, all returned values are null.

Definition at line 758 of file KDb.cpp.

QString KDb::identifierExpectedMessage ( const QString valueName,
const QVariant v 
)
Returns
useful message "Value of "valueName" field must be an identifier. "v" is not a valid identifier.". It is also used by KDbIdentifierValidator.

Definition at line 2199 of file KDb.cpp.

tristate KDb::idForObjectName ( KDbConnection conn,
int *  id,
const QString objName,
int  objType 
)

Finds an identifier for object objName of type objType.

On success true is returned and *id is set to the value of the identifier. On failure or if conn is nullptr, false is returned. If there is no object with specified name and type, cancelled value is returned.

Definition at line 579 of file KDb.cpp.

template<typename T >
T KDb::iif ( bool  ok,
const T &  value 
)
Returns
value if ok is true, else returns default value T().

Definition at line 841 of file KDb.h.

template<typename T >
T KDb::iifNotEmpty ( const T &  string,
const T &  stringIfEmpty 
)
Returns
string if it is not empty, else returns stringIfEmpty.

This function is an optimization in cases when string is a result of expensive functioncall because any evaluation will be performed once, not twice. Another advantage is simpified code through the functional approach. The function expects bool isEmpty() method to be present in type T, so T can typically be QString or QByteArray.

Definition at line 820 of file KDb.h.

template<typename T >
T KDb::iifNotEmpty ( const QByteArray string,
const T &  stringIfEmpty 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 827 of file KDb.h.

template<typename T >
T KDb::iifNotEmpty ( const T &  string,
const QByteArray stringIfEmpty 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 834 of file KDb.h.

bool KDb::importSqliteFile ( const QString inputFileName,
const QString outputFileName 
)

Imports file in SQL format from inputFileName into outputFileName. Works for any SQLite 3 dump file. Requires access to executing the "sqlite3" command. File named outputFileName will be silently overwritten with a new SQLite 3 database file.

Returns
true on success.

Definition at line 2091 of file KDb.cpp.

KDbField::Type KDb::intToFieldType ( int  type)
Returns
type of field for integer value type. If type cannot be casted to KDbField::Type or is not normal type, i.e. type > KDbField::LastType (e.g. KDbField::Null), KDbField::InvalidType is returned. This can be used when type information is deserialized from a string or QVariant.
See also
KDbField::typesCount() KDbField::specialTypesCount()

Definition at line 670 of file KDb.cpp.

KDbField::TypeGroup KDb::intToFieldTypeGroup ( int  typeGroup)
Returns
type group of field for integer value typeGroup. If typeGroup cannot be casted to KDbField::TypeGroup, KDbField::InvalidGroup is returned. This can be used when type information is deserialized from a string or QVariant.
See also
KDbField::typeGroupsCount()

Definition at line 678 of file KDb.cpp.

bool KDb::isBuiltinTableFieldProperty ( const QByteArray propertyName)

for KDb::isBuiltinTableFieldProperty()

Returns
true if propertyName is a builtin field property.

Definition at line 734 of file KDb.cpp.

bool KDb::isDefaultValueAllowed ( const KDbField field)
Returns
true if setting default value for field field is allowed. Fields with unique (and thus primary key) flags set do not accept default values.

Definition at line 1915 of file KDb.cpp.

bool KDb::isEmptyValue ( KDbField::Type  type,
const QVariant value 
)
Returns
true if value value represents an empty (but not null) value.
  • Case 1: If field type type is of any text type (KDbField::isTextType(type) == true) then the function returns true if value casted to a QString value is empty and not null.
  • Case 2: If field type type is KDbField::BLOB then the function returns if value casted to a QByteArray value is empty and not null.
  • Case 3: If field type type is of any other type then the function returns true if value.isNull().
See also
KDbField::hasEmptyProperty()

Definition at line 429 of file KDb.cpp.

bool KDb::isExtendedTableFieldProperty ( const QByteArray propertyName)

for isExtendedTableProperty()

Returns
true if propertyName is an extended field property.

Definition at line 954 of file KDb.cpp.

KDb::isIdentifier ( const QString s)
Returns
true if s is a valid identifier, i.e. starts with a letter or '_' character and contains only letters, numbers and '_' character.
Since
3.1

Definition at line 2133 of file KDb.cpp.

KDB_EXPORT bool KDb::isKDbSqlKeyword ( const QByteArray word)
Returns
true if the word is an reserved KDBSQL keyword See generated/sqlkeywords.cpp.
Todo:
add function returning list of keywords.
bool KDb::isLookupFieldSchemaProperty ( const QByteArray propertyName)

for isLookupFieldSchemaProperty()

Returns
true if propertyName is belongs to lookup field's schema.

Definition at line 976 of file KDb.cpp.

KDB_EXPORT quint64 KDb::lastInsertedAutoIncValue ( QSharedPointer< KDbSqlResult result,
const QString autoIncrementFieldName,
const QString tableName,
quint64 *  recordId = nullptr 
)

Returns value of last inserted record for an autoincrement field.

This method internally fetches values of the last inserted record for which result was returned and returns selected field's value. The field belong to tableName table. The field must be of integer type, there must be a record inserted using query for which the result is returned. std::numeric_limits<quint64>::max() is returned on error or if result is null. The last inserted record is identified by a magical record identifier, usually called ROWID (PostgreSQL has it as well as SQLite; see KDbDriverBehavior::ROW_ID_FIELD_RETURNS_LAST_AUTOINCREMENTED_VALUE). ROWID's value will be assigned back to recordId if this pointer is not nullptr.

Definition at line 392 of file KDb.cpp.

KDB_EXPORT quint64 KDb::lastInsertedAutoIncValue ( KDbConnection conn,
const quint64  recordId,
const QString autoIncrementFieldName,
const QString tableName 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Accepts recordId that can be obtained from KDbPreparedStatement::lastInsertRecordId() or KDbSqlResult::lastInsertRecordId().

Definition at line 407 of file KDb.cpp.

quint64 KDb::lastInsertedAutoIncValue ( QSharedPointer< KDbSqlResult result,
const QString autoIncrementFieldName,
const KDbTableSchema table,
quint64 *  recordId = nullptr 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 144 of file KDb.h.

QStringList KDb::libraryPaths ( )
Returns
a list of paths that KDb will search when dynamically loading libraries (plugins) This is basicaly list of directories returned QCoreApplication::libraryPaths() that have readable subdirectory "kdb".
See also
QCoreApplication::libraryPaths()

Definition at line 2051 of file KDb.cpp.

int KDb::loadIntPropertyValueFromDom ( const QDomNode node,
bool *  ok 
)

Convenience version of loadPropertyValueFromDom().

Returns
int value.

Definition at line 1097 of file KDb.cpp.

QVariant KDb::loadPropertyValueFromDom ( const QDomNode node,
bool *  ok 
)
Returns
property value loaded from a DOM node, written in a QtDesigner-like notation: <number>int</number> or <bool>bool</bool>, etc. Supported types are "string", "cstring", "bool", "number". For invalid values null QVariant is returned. Validity of the returned value can be checked using the ok parameter and QVariant::type().
Todo:
add more QVariant types

Definition at line 1123 of file KDb.cpp.

QString KDb::loadStringPropertyValueFromDom ( const QDomNode node,
bool *  ok 
)

Convenience version of loadPropertyValueFromDom().

Returns
QString value.

Definition at line 1110 of file KDb.cpp.

KDbField::Type KDb::maximumForIntegerFieldTypes ( KDbField::Type  t1,
KDbField::Type  t2 
)
Returns
type that's maximum of two integer types t1 and t2, e.g. Integer for (Byte, Integer). If one of the types is not of the integer group, KDbField::InvalidType is returned. Returned type may not fit to the result of evaluated expression that involves the arguments. For example, 100 is within Byte type, maximumForIntegerFieldTypes(Byte, Byte) is Byte but result of 100 * 100 exceeds the range of Byte.

Definition at line 1944 of file KDb.cpp.

QVariant KDb::notEmptyValueForFieldType ( KDbField::Type  type)

Used in KDb::notEmptyValueForFieldType()

Returns
a value that can be set for a database field of type type having "notEmpty" property set.

It works in a similar way as QVariant KDb::emptyValueForFieldType(KDbField::Type type) with the following differences:

  • " " string (a single space) is returned for Text and LongText types
  • a byte array with saved "filenew" PNG image (icon) for BLOB type Returns null QVariant for unsupported values like KDbField::InvalidType.

Definition at line 1275 of file KDb.cpp.

QString KDb::numberToLocaleString ( double  value,
int  decimalPlaces 
)

Returns number converted to string using default locale.

This method is similar to KDb::numberToString() but the string is formatted using QLocale::toString().

See also
KDb::numberToString() KDbField::visibleDecimalPlaces()

Definition at line 659 of file KDb.cpp.

QString KDb::numberToLocaleString ( double  value,
int  decimalPlaces,
const QLocale locale 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns number converted to string using specified locale.

Definition at line 665 of file KDb.cpp.

QString KDb::numberToString ( double  value,
int  decimalPlaces 
)
Returns
string constructed by converting value. If decimalPlaces is < 0, all meaningful fractional digits are returned (up to 10). If automatically is 0, just integer part is returned. If automatically is > 0, fractional part should take exactly N digits: if the fractional part is shorter than N, additional zeros are appended. Examples: numberToString(12.345, 6) == "12.345000" numberToString(12.345, 0) == "12" numberToString(12.345, -1) == "12.345" numberToString(12.0, -1) == "12" numberToString(0.0, -1) == "0"
Note
No rounding is performed
No thousands group separator is used. Decimal symbol is '.'.
See also
KDb::numberToLocaleString() KDbField::visibleDecimalPlaces()

Definition at line 654 of file KDb.cpp.

QByteArray KDb::pgsqlByteaToByteArray ( const char *  data,
int  length = -1 
)
Returns
byte array converted from data of length length. If length is negative, the data is assumed to point to a null-terminated string and its length is determined dynamically. data is escaped in format used by PostgreSQL's bytea datatype described at https://www.postgresql.org/docs/8.1/interactive/datatype-binary.html This function is used by PostgreSQL KDb and migration drivers.

Definition at line 1669 of file KDb.cpp.

QDomElement KDb::saveBooleanElementToDom ( QDomDocument doc,
QDomElement parentEl,
const QString elementName,
bool  value 
)

Creates a new DOM element named elementName with boolean value value in doc document within parent element parentEl. This method is like saveNumberElementToDom() but creates "bool" tags. True/false values will be saved as "true"/"false" strings. Example: saveBooleanElementToDom(doc, parentEl, "visible", true) creates:

<visible><bool>true</bool></visible>
Returns
the reference to element created with tag elementName. Null element is returned if doc or parentEl is nullptr or if elementName is empty.

Definition at line 1183 of file KDb.cpp.

QDomElement KDb::saveNumberElementToDom ( QDomDocument doc,
QDomElement parentEl,
const QString elementName,
int  value 
)

Creates a new DOM element named elementName with numeric value value in doc document within parent element parentEl. The value will be enclosed in "number" element and "elementName" element. Example: saveNumberElementToDom(doc, parentEl, "height", 15) creates:

<height><number>15</number></height>
Returns
the reference to element created with tag elementName. Null element is returned if doc or parentEl is nullptr or if elementName is empty.

Definition at line 1169 of file KDb.cpp.

QString KDb::serializeList ( const QStringList list)
Returns
string converted from list list. Separators are ',' characters, "," and "\\" are escaped.
See also
KDb::deserializeList()

Definition at line 1791 of file KDb.cpp.

bool KDb::setFieldProperties ( KDbField field,
const QMap< QByteArray, QVariant > &  values 
)

Sets property values for field.

Returns
true if all the values are valid and allowed. On failure contents of field is undefined. Properties from extended schema are also supported. This function is used e.g. by KDbAlterTableHandler when property information comes in form of text. If field is nullptr nothing is performed and false is returned.
Todo:
IMPORTANT: defaultWidth

Definition at line 833 of file KDb.cpp.

bool KDb::setFieldProperty ( KDbField field,
const QByteArray propertyName,
const QVariant value 
)

Sets value of a single property for field.

Returns
true if the property has been found and the value is valid for this property. On failure contents of field is not modified. Properties from extended schema are also supported as well as custom properties (using KDbField::setCustomProperty()).

This function is used e.g. by KDbAlterTableHandler when property information comes in form of text. If field is nullptr nothing is performed and false is returned.

Todo:
IMPORTANT: defaultWidth

Definition at line 981 of file KDb.cpp.

tristate KDb::showConnectionTestDialog ( QWidget parent,
const KDbConnectionData data,
KDbMessageHandler msgHandler 
)

Shows connection test dialog.

Shows connection test dialog with a progress bar indicating connection testing (within a separate thread). data is used to perform a (temporary) test connection. msgHandler can be used for error handling. parent is used as dialog's parent widget.

The dialog is modal so the call is blocking.

On successful connecting, a successfull message of type KDbMessageHandler::Information is passed to msgHandler. After testing, temporary connection is closed.

Returns
true for successfull connecting, for failed connecting and cancelled if the test has been cancelled.

Definition at line 592 of file KDb.cpp.

QString KDb::simplifiedFieldTypeName ( KDbField::Type  type)
Returns
a slightly simplified field type name type type. For KDbField::BLOB type it returns a translated "Image" string or other, depending on the mime type. For numbers (either floating-point or integer) it returns a translated "Number" string. For other types KDbField::typeGroupName() is returned.
Todo:
support names of other BLOB subtypes
Todo:
support names of other BLOB subtypes

Definition at line 1959 of file KDb.cpp.

bool KDb::splitToTableAndFieldParts ( const QString string,
QString tableName,
QString fieldName,
SplitToTableAndFieldPartsOptions  option = FailIfNoTableOrFieldName 
)

Splits string like "table.field" into "table" and "field" parts. On success, a table name is passed to tableName and a field name is passed to fieldName. The function fails if either:

  • string is empty, or
  • string does not contain '.' character and option is FailIfNoTableOrFieldName (the default), or
  • '.' character is the first of last character of string (in this case table name or field name could become empty what is not allowed).
  • tableName or fieldName is nullptr

If option is SetFieldNameIfNoTableName and string does not contain '.', string is passed to fieldName and tableName is set to QString() without failure.

If function fails, tableName and fieldName remain unchanged.

Returns
true on success.

Definition at line 603 of file KDb.cpp.

QString KDb::sqlite3ProgramPath ( )
Returns
absolute path to "sqlite3" program. Empty string is returned if the program was not found.

Definition at line 2082 of file KDb.cpp.

KDbEscapedString KDb::sqlWhere ( KDbDriver drv,
KDbField::Type  t,
const QString fieldName,
const QVariant value 
)

Function useful for building WHERE parts of SQL statements. Constructs an SQL string like "fielname = value" for specific drv driver, field type t, fieldName and value. If value is null, "fieldname IS NULL" string is returned.

Definition at line 440 of file KDb.cpp.

QList< int > KDb::stringListToIntList ( const QStringList list,
bool *  ok = nullptr 
)
Returns
int list converted from string list. If ok is not 0, *ok is set to result of the conversion.

Definition at line 1774 of file KDb.cpp.

QString KDb::stringToIdentifier ( const QString s)
Returns
valid identifier based on s. Non-alphanumeric characters (or spaces) are replaced with '_'. If a number is at the beginning, '_' is added at start. Empty strings are not changed. Case remains unchanged.

Definition at line 2166 of file KDb.cpp.

QVariant KDb::stringToVariant ( const QString s,
QVariant::Type  type,
bool *  ok 
)
Returns
variant value of type type for a string s that was previously serialized using variantToString( const QVariant& v ) function. ok is set to the result of the operation. With exception for types mentioned in documentation of variantToString(), QVariant::convert() is used for conversion.

Definition at line 1867 of file KDb.cpp.

bool KDb::supportsVisibleDecimalPlacesProperty ( KDbField::Type  type)
Returns
true if type supports "visibleDecimalPlaces" property.
Todo:
add check for decimal type as well

Definition at line 623 of file KDb.cpp.

QString KDb::temporaryTableName ( KDbConnection conn,
const QString baseName 
)
Returns
new temporary name suitable for creating new table. The name has mask tmp__{baseName}{rand} where baseName is passed as argument and {rand} is a 10 digits long hexadecimal number. baseName can be empty. It is adviced to use the returned name as quickly as possible for creating new physical table. It is not 100% guaranteed that table with this name will not exist at an attempt of creation but it is very unlikely. The function checks for existence of a table with temporary name for connection conn. Empty string is returned if conn is nullptr or is not open or if checking for existence of table with temporary name failed.

Definition at line 2063 of file KDb.cpp.

KDbEscapedString KDb::timeToIsoString ( const QVariant v)

Converts time value to its string representation in ISO 8601 Time format.

The string is enclosed with single quotes "'". It is compatible with SQLite format for the time type. It is used as default implementation for drivers in KDbDriver::timeToSql().

If the v value is convertible to KDbTime then KDbTime::toString() is used to obtain the result. Otherwise the value is converted to QTime and QTime::toString() is used to obtain the result. If the time's milliseconds value is zero, it is not included.

"<INVALID_TIME>" string is returned for invalid (also null) time values.

For specification of the ISO format see https://www.w3.org/TR/NOTE-datetime.

Example values: "'13:15:30.123'", "'13:15:30'".

Since
3.2.0

Definition at line 2300 of file KDb.cpp.

KDbEscapedString KDb::timeToSql ( const QVariant v)

Converts time value to its string representation required by KDBSQL commands.

The value can be of type QTime or KDbTime. If the value is not one of these types or is invalid QTime or is a null KDbTime then "<INVALID_TIME>" is returned. If the value is of type KDbTime that is not null then even if some components of the time are invalid, properly formatted string is returned. If the time's milliseconds value is zero, it is not included.

See https://community.kde.org/Kexi/Plugins/Queries/SQL_Constants for details.

Example values: "#13:15#", "#13:9:30#", "#13:15:30.921#, "#7:20 AM#".

Since
3.2.0

Definition at line 2257 of file KDb.cpp.

KDB_EXPORT QString KDb::unescapeString ( const QString string,
char  quote,
int *  errorPosition = nullptr 
)

Unescapes characters in string string for the KDBSQL dialect.

The operation depends on quote character, which can be be ' or ". string is assumed to be properly constructed. This is assured by the lexer's grammar. Used by lexer to recognize the CHARACTER_STRING_LITERAL token.

Returns
unescaped string and sets value pointed by errorPosition (if any) to -1 on success; and to index of problematic character on failure. The function fails when unsupported quote character is passed or for unsupported sequences.

Example sequences for ' character quote:

  • \' -> ' (escaping)
  • " -> " (escaping)
  • '' -> ' (repeated quote escapes too)
  • "" -> "" (repeated but this is not the quote)
  • ' -> (disallowed, escaping needed)
  • " -> " Example sequences for " character quote:
  • \' -> ' (escaping)
  • " -> " (escaping) - " -> " (disallowed, escaping needed) - "" -> " (repeated quote escapes too)
  • '' -> '' (repeated but this is not the quote)
  • ' -> '

Following sequences are always unescaped (selection based on a mix of MySQL and C/JavaScript):

  • \0 -> NULL (QChar())
  • -> backspace 0x8
  • -> form feed 0xc

  • -> new line 0xa
  • -> carriage return 0xd
  • -> horizontal tab 0x9
  • -> vertical tab 0xb
  • \ -> backslash
  • \? -> ? (useful when '?' placeholders are used)
  • % -> (useful when '' wildcards are used e.g. for the LIKE operator)
  • _ -> (useful when '_' pattern is used e.g. for the LIKE operator)
  • -> a character for which hh (exactly 2 digits) is interpreted as an hexadecimal number, 00 <= hh <= FF. Widely supported by programming languages. Can be also 00 <= hh <= ff. Example: translates to "©".
  • -> 16-bit unicode character, exactly 4 digits, each x is a hexadecimal digit, case insensitive; known from JavaScript, Java, C/C++. 0000 <= xxxxxx <= FFFF Example: translates to "♥".
  • {xxxxxx} -> 24-bit unicode "code point" character, each x is a hexadecimal digit, case insensitive; known from JavaScript (ECMAScript 6). 0 <= xxxxxx <= 10FFFF Example: {1D306} translates to "𝌆"
Note
Characters without special meaning can be escaped, but then the "\" character is skipped, e.g. "\a" == "a".
Trailing "\" character in string is ignored.
octal notation is not supported, it may be confusing and conflicting when combined with other characters (\0012 is not the same as \012). The industry is moving away from it and EcmaScript 5 deprecates it.

See also:

KDbEscapedString KDb::valueToSql ( KDbField::Type  ftype,
const QVariant v 
)

Escapes and converts value v (for type ftype) to string representation required by KDBSQL commands. For Date/Time type KDb::dateTimeToSql() is used. For BLOB type KDb::escapeBlob() with BLOBEscapingType::ZeroXHex conversion type is used.

Definition at line 2209 of file KDb.cpp.

QString KDb::variantToString ( const QVariant v)
Returns
string value serialized from a variant value v. This functions works like QVariant::toString() except the case when v is of type:

This function is needed for handling values of random type, for example "defaultValue" property of table fields can contain value of any type. Note: the returned string is an unescaped string.

Definition at line 1856 of file KDb.cpp.

KDbVersionInfo KDb::version ( )
Returns
runtime information about version of the KDb library.
See also
KDbConnection::databaseVersion() KDbConnection::serverVersion() KDbDriverMetaData::version()

Definition at line 336 of file KDb.cpp.

QByteArray KDb::xHexToByteArray ( const char *  data,
int  length = -1,
bool *  ok = nullptr 
)
Returns
byte array converted from data of length length. If length is negative, the data is assumed to point to a null-terminated string and its length is determined dynamically. data is escaped in format X'*', where * is one or more hexadecimal digits. Both A-F and a-f letters are supported. Even and odd number of digits are supported. If ok is not 0, *ok is set to result of the conversion. See BLOBEscapingType::XHex.

Definition at line 1719 of file KDb.cpp.

QByteArray KDb::zeroXHexToByteArray ( const char *  data,
int  length = -1,
bool *  ok = nullptr 
)
Returns
byte array converted from data of length length. If length is negative, the data is assumed to point to a null-terminated string and its length is determined dynamically. data is escaped in format 0x*, where * is one or more hexadecimal digits. Both A-F and a-f letters are supported. Even and odd number of digits are supported. If ok is not 0, *ok is set to result of the conversion. See BLOBEscapingType::ZeroXHex.
byte array converted from data of length length. data is escaped in format 0x*, where * is one or more bytes in hexadecimal format. See BLOBEscapingType::ZeroXHex.

Definition at line 1748 of file KDb.cpp.

This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed Sep 23 2020 23:05:41 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.