Kexi API Documentation (2.0 alpha)

kexidb/utils.h File Reference

#include <qvaluelist.h>
#include <qvariant.h>
#include <kexidb/connection.h>
#include <kexidb/driver.h>

Go to the source code of this file.

Namespaces

namespace  KexiDB

Typedefs

typedef QValueList< uint > TypeGroupList

Enumerations

enum  SplitToTableAndFieldPartsOptions { FailIfNoTableOrFieldName = 0, SetFieldNameIfNoTableName = 1 }
 Used in splitToTableAndFieldParts(). More...
enum  BLOBEscapingType { BLOBEscapeXHex = 1, BLOBEscape0xHex, BLOBEscapeHex, BLOBEscapeOctal }
 Escaping types used in escapeBLOB(). More...

Functions

bool deleteRow (Connection &conn, TableSchema *table, const QString &keyname, const QString &keyval)
 for convenience
bool deleteRow (Connection &conn, const QString &tableName, const QString &keyname, const QString &keyval)
bool deleteRow (Connection &conn, TableSchema *table, const QString &keyname, int keyval)
bool deleteRow (Connection &conn, const QString &tableName, const QString &keyname, int keyval)
bool deleteRow (Connection &conn, const QString &tableName, const QString &keyname1, Field::Type keytype1, const QVariant &keyval1, const QString &keyname2, Field::Type keytype2, const QVariant &keyval2)
bool replaceRow (Connection &conn, TableSchema *table, const QString &keyname, const QString &keyval, const QString &valname, QVariant val, int ftype)
const TypeGroupList typesForGroup (Field::TypeGroup typeGroup)
QStringList typeNamesForGroup (Field::TypeGroup typeGroup)
QStringList typeStringsForGroup (Field::TypeGroup typeGroup)
Field::Type defaultTypeForGroup (Field::TypeGroup typeGroup)
bool isEmptyValue (Field *f, const QVariant &v)
void getHTMLErrorMesage (Object *obj, QString &msg, QString &details)
void getHTMLErrorMesage (Object *obj, QString &msg)
void getHTMLErrorMesage (Object *obj, ResultInfo *result)
QString sqlWhere (Driver *drv, Field::Type t, const QString fieldName, const QVariant value)
int idForObjectName (Connection &conn, const QString &objName, int objType)
int rowCount (Connection &conn, const QString &sql)
int rowCount (const TableSchema &tableSchema)
int rowCount (QuerySchema &querySchema)
int rowCount (TableOrQuerySchema &tableOrQuery)
int fieldCount (TableOrQuerySchema &tableOrQuery)
void connectionTestDialog (QWidget *parent, const ConnectionData &data, MessageHandler &msgHandler)
QMap< QString, QStringtoMap (const ConnectionData &data)
void fromMap (const QMap< QString, QString > &map, ConnectionData &data)
bool splitToTableAndFieldParts (const QString &string, QString &tableName, QString &fieldName, SplitToTableAndFieldPartsOptions option=FailIfNoTableOrFieldName)
bool supportsVisibleDecimalPlacesProperty (Field::Type type)
QString formatNumberForVisibleDecimalPlaces (double value, int decimalPlaces)
bool isBuiltinTableFieldProperty (const QCString &propertyName)
bool isExtendedTableFieldProperty (const QCString &propertyName)
Field::Type intToFieldType (int type)
bool setFieldProperties (Field &field, const QMap< QCString, QVariant > &values)
bool setFieldProperty (Field &field, const QCString &propertyName, const QVariant &value)
QVariant loadPropertyValueFromDom (const QDomNode &node)
int loadIntPropertyValueFromDom (const QDomNode &node, bool *ok)
QString loadStringPropertyValueFromDom (const QDomNode &node, bool *ok)
QDomElement saveNumberElementToDom (QDomDocument &doc, QDomElement &parentEl, const QString &elementName, int value)
QDomElement saveBooleanElementToDom (QDomDocument &doc, QDomElement &parentEl, const QString &elementName, bool value)
QVariant emptyValueForType (Field::Type type)
QVariant notEmptyValueForType (Field::Type type)
QString escapeBLOB (const QByteArray &array, BLOBEscapingType type)
QByteArray pgsqlByteaToByteArray (const char *data, int length)
QString variantToString (const QVariant &v)
QVariant stringToVariant (const QString &s, QVariant::Type type, bool &ok)
bool isDefaultValueAllowed (Field *field)
void getLimitsForType (Field::Type type, int &minValue, int &maxValue)
void debugRowData (const RowData &rowData)
Field::Type maximumForIntegerTypes (Field::Type t1, Field::Type t2)
QVariant cstringToVariant (const char *data, KexiDB::Field *f, int length=-1)


Typedef Documentation

typedef QValueList<uint> KexiDB::TypeGroupList
 

Definition at line 86 of file kexidb/utils.h.


Enumeration Type Documentation

enum KexiDB::BLOBEscapingType
 

Escaping types used in escapeBLOB().

Enumeration values:
BLOBEscapeXHex  escaping like X'1FAD', used by sqlite (hex numbers)
BLOBEscape0xHex  escaping like 0x1FAD, used by mysql (hex numbers)
BLOBEscapeHex  escaping like 1FAD without quotes or prefixes
BLOBEscapeOctal  (only non-printable characters are escaped using octal numbers) See http://www.postgresql.org/docs/8.1/interactive/datatype-binary.html

Definition at line 379 of file kexidb/utils.h.

enum KexiDB::SplitToTableAndFieldPartsOptions
 

Used in splitToTableAndFieldParts().

Enumeration values:
FailIfNoTableOrFieldName  default value for splitToTableAndFieldParts()
SetFieldNameIfNoTableName  see splitToTableAndFieldParts()

Definition at line 262 of file kexidb/utils.h.


Function Documentation

void KexiDB::connectionTestDialog QWidget parent,
const ConnectionData &  data,
MessageHandler &  msgHandler
 

shows connection test dialog with a progress bar indicating connection testing (within a second thread). data is used to perform a (temporary) test connection. msgHandler is used to display errors. On successful connecting, a message is displayed. After testing, temporary connection is closed.

Referenced by KexiDBConnectionTabWidget::slotTestConnection().

QVariant KexiDB::cstringToVariant const char *  data,
KexiDB::Field f,
int  length = -1
[inline]
 

Returns:
QVariant value converted from null-terminated data string. In case of BLOB type, data is not nul lterminated, so passing length is needed.
Todo:
date/time?

Definition at line 437 of file kexidb/utils.h.

References KexiDB::Field::BigInteger, KexiDB::Field::BLOB, KexiDB::Field::isFPNumericType(), KexiDB::Field::isIntegerType(), KexiDB::Field::isTextType(), KexiDB::Field::type(), and KexiDB::Field::variantType().

Referenced by KexiMigration::PqxxMigrate::drv_copyTable(), KexiMigration::MySQLMigrate::drv_copyTable(), KexiDB::MySqlCursor::storeCurrentRow(), and KexiDB::MySqlCursor::value().

void KexiDB::debugRowData const RowData rowData  ) 
 

Shows debug information about rowData row data.

Field::Type KexiDB::defaultTypeForGroup Field::TypeGroup  typeGroup  ) 
 

Returns:
default field type for type group typeGroup, for example, Field::Integer for Field::IntegerGroup. It is used e.g. in KexiAlterTableDialog, to properly fill 'type' property when user selects type group for a field.

Referenced by KexiTableDesignerView::slotBeforeCellChanged(), and KexiTableDesignerView::slotRowUpdated().

bool KexiDB::deleteRow Connection &  conn,
const QString tableName,
const QString keyname1,
Field::Type  keytype1,
const QVariant &  keyval1,
const QString keyname2,
Field::Type  keytype2,
const QVariant &  keyval2
[inline]
 

Delete row with two generic criterias.

Definition at line 66 of file kexidb/utils.h.

bool KexiDB::deleteRow Connection &  conn,
const QString tableName,
const QString keyname,
int  keyval
[inline]
 

Definition at line 58 of file kexidb/utils.h.

References KexiDB::Field::Integer.

bool KexiDB::deleteRow Connection &  conn,
TableSchema *  table,
const QString keyname,
int  keyval
[inline]
 

Definition at line 51 of file kexidb/utils.h.

References KexiDB::Field::Integer, and KexiDB::SchemaData::name().

bool KexiDB::deleteRow Connection &  conn,
const QString tableName,
const QString keyname,
const QString keyval
[inline]
 

Definition at line 44 of file kexidb/utils.h.

References KexiDB::Field::Text.

bool KexiDB::deleteRow Connection &  conn,
TableSchema *  table,
const QString keyname,
const QString keyval
[inline]
 

for convenience

Definition at line 37 of file kexidb/utils.h.

References KexiDB::Connection::driver(), KexiDB::Connection::executeSQL(), KexiDB::SchemaData::name(), and KexiDB::Field::Text.

Referenced by KexiDB::Connection::createTable(), KexiDB::Connection::dropTable(), KexiDB::Connection::removeDataBlock(), KexiDB::Connection::removeObject(), and KexiDB::replaceRow().

QVariant KexiDB::emptyValueForType Field::Type  type  ) 
 

Returns:
an empty value that can be set for a database field of type type having "null" property set. Empty string is returned for text type, 0 for integer or floating-point types, false for boolean type, empty null byte array for BLOB type. For date, time and date/time types current date, time, date+time is returned, respectively. Returns null QVariant for unsupported values like KexiDB::Field::InvalidType. This function is efficient (uses a cache) and is heavily used by the AlterTableHandler for filling new columns.

Referenced by KexiDB::AlterTableHandler::execute(), and KexiDB::notEmptyValueForType().

QString KexiDB::escapeBLOB const QByteArray &  array,
BLOBEscapingType  type
 

Returns:
a string containing escaped, printable representation of array. Escaping is controlled by type. For empty array QString::null 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 Driver::escapeBLOB() and KexiDB::variantToString().

Referenced by KexiDB::SQLiteDriver::escapeBLOB(), KexiDB::pqxxSqlDriver::escapeBLOB(), KexiDB::MySqlDriver::escapeBLOB(), KexiCSVExport::exportData(), and KexiDB::variantToString().

int KexiDB::fieldCount TableOrQuerySchema &  tableOrQuery  ) 
 

Returns:
a number of columns that can be retrieved from table or query schema. In case of query, expanded fields are counted. Can return -1 if tableOrQuery has neither table or query assigned.

Referenced by KexiDB::PreparedStatement::generateStatementString(), and KexiCSVExportWizard::showPage().

QString KexiDB::formatNumberForVisibleDecimalPlaces double  value,
int  decimalPlaces
 

Returns:
string constructed by converting value. If decimalPlaces is < 0, all meaningful fractional digits are returned. 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. For example, "12.345" becomes "12.345000" if N=6.
No rounding is actually performed. KLocale::formatNumber() and KLocale::decimalSymbol() are used to get locale settings.

See also:
KexiDB::Field::visibleDecimalPlaces()

Referenced by KexiTableEdit::setupContents(), and KexiTextFormatter::valueToText().

void KexiDB::fromMap const QMap< QString, QString > &  map,
ConnectionData &  data
 

Restores connection data data from map.

void KexiDB::getHTMLErrorMesage Object *  obj,
ResultInfo *  result
 

This methods works like above, but works on result's members instead.

void KexiDB::getHTMLErrorMesage Object *  obj,
QString msg
 

This methods works like above, but appends both a message and a description to msg.

void KexiDB::getHTMLErrorMesage Object *  obj,
QString msg,
QString details
 

Sets msg to an error message retrieved from object obj, and details to details of this error (server message and result number). Does nothing if obj is null or no error occurred. msg and details strings are not overwritten. If msg is not empty, obj's error message is appended to details.

Referenced by KexiTableViewData::deleteRow(), KexiDB::getHTMLErrorMesage(), KexiTableViewData::saveRow(), KexiBrowser::setProject(), and KexiGUIMessageHandler::showErrorMessage().

void KexiDB::getLimitsForType Field::Type  type,
int &  minValue,
int &  maxValue
 

Gets limits for values of type type. The result is put into minValue and maxValue. Supported types are Byte, ShortInteger, Integer and BigInteger Results for BigInteger or non-integer types are the same as for Integer due to limitation of int type. Signed integers are assumed.

Todo:
add support for unsigned flag

Referenced by KexiQueryParameters::getParameters().

int KexiDB::idForObjectName Connection &  conn,
const QString objName,
int  objType
 

Returns:
identifier for object objName of type objType or 0 if such object does not exist.

Referenced by KexiDBSubForm::setFormName(), and KexiSubReport::setReportName().

Field::Type KexiDB::intToFieldType int  type  ) 
 

Returns:
type of field for integer value type. If type cannot be casted to KexiDB::Field::Type, KexiDB::Field::InvalidType is returned. This can be used when type information is deserialized from a string or QVariant.

Referenced by KexiTableDesignerView::buildField(), KexiDB::SQLiteConnection::drv_changeFieldProperty(), setIntToFieldType(), KexiTableDesignerView::slotPropertyChanged(), and KexiTableDesignerView::slotRowUpdated().

bool KexiDB::isBuiltinTableFieldProperty const QCString &  propertyName  ) 
 

Returns:
true if propertyName is a builtin field property.

Referenced by KexiDB::setFieldProperties().

bool KexiDB::isDefaultValueAllowed Field *  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. False is returned aslo if field is 0.

Referenced by KexiDB::RowEditBuffer::at(), and KexiDB::Connection::insertRow().

bool KexiDB::isEmptyValue Field *  f,
const QVariant &  v
[inline]
 

Returns:
true if v represents an empty (but not null) value. Values of some types (as for strings) can be both empty and not null.

Definition at line 105 of file kexidb/utils.h.

References KexiDB::Field::hasEmptyProperty().

Referenced by KexiTableViewData::saveRow().

bool KexiDB::isExtendedTableFieldProperty const QCString &  propertyName  ) 
 

Returns:
true if propertyName is an extended field property.

Referenced by KexiDB::setFieldProperties(), and KexiDB::setFieldProperty().

int KexiDB::loadIntPropertyValueFromDom const QDomNode &  node,
bool *  ok
 

Convenience version of loadPropertyValueFromDom().

Returns:
int value.

Referenced by KexiDB::Connection::loadExtendedTableSchemaData().

QVariant KexiDB::loadPropertyValueFromDom const QDomNode &  node  ) 
 

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. You can check the validity of the returned value using QVariant::type().

Referenced by KexiDB::Connection::loadExtendedTableSchemaData(), and KexiDB::LookupFieldSchema::loadFromDom().

QString KexiDB::loadStringPropertyValueFromDom const QDomNode &  node,
bool *  ok
 

Convenience version of loadPropertyValueFromDom().

Returns:
QString value.

Field::Type KexiDB::maximumForIntegerTypes Field::Type  t1,
Field::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, Field::InvalidType is returned.

Referenced by KexiDB::maximumForIntegerTypes(), and KexiDB::BinaryExpr::type().

QVariant KexiDB::notEmptyValueForType Field::Type  type  ) 
 

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 emptyValueForType( KexiDB::Field::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 KexiDB::Field::InvalidType. This function is efficient (uses a cache) and is heavily used by the AlterTableHandler for filling new columns.

Referenced by KexiDB::AlterTableHandler::execute().

QByteArray KexiDB::pgsqlByteaToByteArray const char *  data,
int  length
 

Returns:
byte array converted from data of length length. data is escaped in format used by PostgreSQL's bytea datatype described at http://www.postgresql.org/docs/8.1/interactive/datatype-binary.html This function is used by PostgreSQL KexiDB and migration drivers.

Referenced by KexiMigration::PqxxMigrate::drv_copyTable(), pgsqlByteaToByteArray(), and KexiDB::pgsqlCStrToVariant().

bool KexiDB::replaceRow Connection &  conn,
TableSchema *  table,
const QString keyname,
const QString keyval,
const QString valname,
QVariant  val,
int  ftype
[inline]
 

Definition at line 75 of file kexidb/utils.h.

References KexiDB::deleteRow(), KexiDB::SchemaData::name(), and KexiDB::Field::Text.

int KexiDB::rowCount TableOrQuerySchema &  tableOrQuery  ) 
 

Like above but operates on a table or query schema variant.

int KexiDB::rowCount QuerySchema &  querySchema  ) 
 

Like above but operates on a query schema.

int KexiDB::rowCount const TableSchema &  tableSchema  ) 
 

Returns:
number of rows that can be retrieved from tableSchema. The table must be created or retrieved using a Connection object, i.e. tableSchema.connection() must not return 0. For SQL data sources it does not fetch any records, only "COUNT(*)" SQL aggregation is used at the backed. -1 is returned if error occurred.

int KexiDB::rowCount Connection &  conn,
const QString sql
 

Returns:
number of rows that can be retrieved after executing sql statement within a connection conn. The statement should be of type SELECT. For SQL data sources it does not fetch any records, only "COUNT(*)" SQL aggregation is used at the backed. -1 is returned if error occured.

Referenced by KexiCSVExport::exportData(), KexiDB::rowCount(), and KexiCSVExportWizard::showPage().

QDomElement KexiDB::saveBooleanElementToDom QDomDocument &  doc,
QDomElement &  parentEl,
const QString elementName,
bool  value
 

Saves boolean element for value value to doc document within parent element parentEl. Like saveNumberElementToDom() but creates "bool" tags. True/false values will be saved as "true"/"false" strings.

Returns:
the reference to element created with tag elementName.

Referenced by KexiDB::LookupFieldSchema::saveToDom().

QDomElement KexiDB::saveNumberElementToDom QDomDocument &  doc,
QDomElement &  parentEl,
const QString elementName,
int  value
 

Saves integer element for value value to doc document within parent element parentEl. The value will be enclosed in "number" element and "elementName" element. Example: saveNumberElementToDom(doc, parentEl, "height", 15) will create

      <height><number>15</number></height>
Returns:
the reference to element created with tag elementName.

Referenced by KexiDB::LookupFieldSchema::saveToDom().

bool KexiDB::setFieldProperties Field &  field,
const QMap< QCString, 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 coming from extended schema are also supported. This function is used e.g. by AlterTableHandler when property information comes in form of text.

Referenced by KexiTableDesignerView::buildField(), and KexiDB::AlterTableHandler::InsertFieldAction::simplifyActions().

bool KexiDB::setFieldProperty Field &  field,
const QCString &  propertyName,
const QVariant &  value
 

Sets property value for field.

Returns:
true if the property has been found and the value is valid for this property. On failure contents of field is undefined. Properties coming from extended schema are also supported as well as QVariant customProperty(const QString& propertyName) const;
This function is used e.g. by AlterTableHandler when property information comes in form of text.

Referenced by KexiDB::AlterTableHandler::ChangeFieldPropertyAction::execute(), and KexiDB::AlterTableHandler::ChangeFieldPropertyAction::updateTableSchema().

bool KexiDB::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).

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

If function fails, tableName and fieldName remain unchanged.

Returns:
true on success.

Referenced by KexiDB::QuerySchema::findTableField(), and KexiQueryDesignerGuiEditor::slotBeforeCellChanged().

QString KexiDB::sqlWhere Driver *  drv,
Field::Type  t,
const QString  fieldName,
const QVariant  value
[inline]
 

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 130 of file kexidb/utils.h.

References KexiDB::Driver::valueToSQL().

Referenced by KexiDB::Connection::loadDataBlock(), and KexiDB::Connection::storeDataBlock().

QVariant KexiDB::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.

Referenced by KexiDB::Connection::setupField().

bool KexiDB::supportsVisibleDecimalPlacesProperty Field::Type  type  ) 
 

Returns:
true if type supports "visibleDecimalPlaces" property.

Referenced by KexiDB::setFieldProperties(), KexiDB::setFieldProperty(), KexiDB::Connection::loadExtendedTableSchemaData(), KexiDB::Field::setVisibleDecimalPlaces(), KexiDB::Connection::storeExtendedTableSchemaData(), and KexiTableDesignerViewPrivate::updatePropertiesVisibility().

QMap<QString,QString> KexiDB::toMap const ConnectionData &  data  ) 
 

Saves connection data data into map.

Referenced by KexiMainWindowImpl::showProjectMigrationWizard().

QStringList KexiDB::typeNamesForGroup Field::TypeGroup  typeGroup  ) 
 

Returns:
list of i18n'd type names for type group typeGroup.

Referenced by KexiTableDesignerView::getSubTypeListData().

const TypeGroupList KexiDB::typesForGroup Field::TypeGroup  typeGroup  ) 
 

Returns:
list of types for type group typeGroup.

QStringList KexiDB::typeStringsForGroup Field::TypeGroup  typeGroup  ) 
 

Returns:
list of (not-i18n'd) type names for type group typeGroup.

Referenced by KexiTableDesignerView::getSubTypeListData().

QString KexiDB::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 ByteArray. In this case KexiDB::escapeBLOB(v.toByteArray(), KexiDB::BLOBEscapeHex) is used. 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.

Referenced by buildValuesForKexi__Fields(), and KexiDB::Field::debugString().

KDE Logo
This file is part of the documentation for Kexi 2.0 alpha.
Documentation copyright © 2002-2007 the Kexi Team.
Generated on Tue Apr 1 20:49:35 2008 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003