21#include "kexidbschema.h"
22#include "kexidbfieldlist.h"
27#include <api/variant.h>
37 : Kross::Api::Class<T>(name)
39 , m_fieldlist(fieldlist)
41 this->
template addFunction0<Kross::Api::Variant>(
"name",
this, &KexiDBSchema<T>::name);
42 this->
template addFunction1<void, Kross::Api::Variant>(
"setName",
this, &KexiDBSchema<T>::setName);
44 this->
template addFunction0<Kross::Api::Variant>(
"caption",
this, &KexiDBSchema<T>::caption);
45 this->
template addFunction1<void, Kross::Api::Variant>(
"setCaption",
this, &KexiDBSchema<T>::setCaption);
47 this->
template addFunction0<Kross::Api::Variant>(
"description",
this, &KexiDBSchema<T>::description);
48 this->
template addFunction1<void, Kross::Api::Variant>(
"setDescription",
this, &KexiDBSchema<T>::setDescription);
50 this->
template addFunction0<KexiDBFieldList>(
"fieldlist",
this, &KexiDBSchema<T>::fieldlist);
54KexiDBSchema<T>::~KexiDBSchema<T>() {
58const TQString KexiDBSchema<T>::name()
const {
59 return m_schema->name();
63void KexiDBSchema<T>::setName(
const TQString& name) {
64 m_schema->setName(name);
68const TQString KexiDBSchema<T>::caption()
const {
69 return m_schema->caption();
73void KexiDBSchema<T>::setCaption(
const TQString& caption) {
74 m_schema->setCaption(caption);
78const TQString KexiDBSchema<T>::description()
const {
79 return m_schema->description();
83void KexiDBSchema<T>::setDescription(
const TQString& description) {
84 m_schema->setDescription(description);
99 this->addFunction0<KexiDBQuerySchema>(
"query",
this, &KexiDBTableSchema::query);
102KexiDBTableSchema::~KexiDBTableSchema() {
105const TQString KexiDBTableSchema::getClassName()
const {
106 return "Kross::KexiDB::KexiDBTableSchema";
109::KexiDB::TableSchema* KexiDBTableSchema::tableschema() {
110 return static_cast< ::KexiDB::TableSchema*
>(m_schema);
114 return new KexiDBQuerySchema( tableschema()->query() );
121KexiDBQuerySchema::KexiDBQuerySchema(::KexiDB::QuerySchema* queryschema)
124 this->addFunction0<Kross::Api::Variant>(
"statement",
this, &KexiDBQuerySchema::statement);
125 this->addFunction1<void, Kross::Api::Variant>(
"setStatement",
this, &KexiDBQuerySchema::setStatement);
126 this->addFunction1<Kross::Api::Variant, Kross::Api::Variant>(
"setWhereExpression",
this, &KexiDBQuerySchema::setWhereExpression);
129KexiDBQuerySchema::~KexiDBQuerySchema() {
132const TQString KexiDBQuerySchema::getClassName()
const {
133 return "Kross::KexiDB::KexiDBQuerySchema";
136::KexiDB::QuerySchema* KexiDBQuerySchema::queryschema() {
137 return static_cast< ::KexiDB::QuerySchema*
>(m_schema);
140const TQString KexiDBQuerySchema::statement()
const {
141 return static_cast< ::KexiDB::QuerySchema*
>(m_schema)->statement();
144void KexiDBQuerySchema::setStatement(
const TQString& statement) {
145 static_cast< ::KexiDB::QuerySchema*
>(m_schema)->setStatement(statement);
148bool KexiDBQuerySchema::setWhereExpression(
const TQString& whereexpression) {
149 ::KexiDB::BaseExpr* oldexpr =
static_cast< ::KexiDB::QuerySchema*
>(m_schema)->whereExpression();
152 TQString s = whereexpression;
154 TQRegExp re(
"[\"',]{1,1}");
156 s.remove(TQRegExp(
"^[\\s,]+"));
157 int pos = s.find(
'=');
159 TQString key = s.left(pos).stripWhiteSpace();
160 s = s.mid(pos + 1).stripWhiteSpace();
165 if(re.cap(0) ==
",") {
166 value = s.left(sp).stripWhiteSpace();
167 s = s.mid(sp+1).stripWhiteSpace();
170 int ep = s.find(re.cap(0),sp+1);
171 value = s.mid(sp+1,ep-1);
180 ::KexiDB::Field* field =
static_cast< ::KexiDB::QuerySchema*
>(m_schema)->field(key);
182 throw Kross::Api::Exception::Ptr(
new Kross::Api::Exception(TQString(
"Invalid WHERE-expression: Field \"%1\" does not exists in tableschema \"%2\".").arg(key).arg(m_schema->name())) );
185 if(! v.cast(field->variantType()))
186 throw Kross::Api::Exception::Ptr(
new Kross::Api::Exception(TQString(
"Invalid WHERE-expression: The for Field \"%1\" defined value is of type \"%2\" rather then the expected type \"%3\"").arg(key).arg(v.typeName()).arg(field->variantType())) );
188 static_cast< ::KexiDB::QuerySchema*
>(m_schema)->addToWhereExpression(field,v);
191 catch(Kross::Api::Exception::Ptr e) {
192 Kross::krosswarning(
"Exception in Kross::KexiDB::KexiDBQuerySchema::setWhereExpression: ");
193 static_cast< ::KexiDB::QuerySchema*
>(m_schema)->setWhereExpression(oldexpr);
The KexiDBTableSchema object implements a KexiDBSchema for queries.
The KexiDBSchema object provides common functionality for schemas like KexiDBTableSchema or KexiDBQue...
The KexiDBTableSchema object implements a KexiDBSchema for tables.
KrossKexiDB provides access to the KexiDB database functionality.