Exemplo n.º 1
1
QxSqlQuery & QxSqlQuery::bind(const QVariant & vValue, QSql::ParamType paramType /* = QSql::In */)
{
   verifyQuery();
   qAssert(m_lstSqlElement.count() <= 0);
   qAssert(! m_sQuery.isEmpty() && (qx::QxSqlDatabase::getSingleton()->getSqlPlaceHolderStyle() == qx::QxSqlDatabase::ph_style_question_mark));

   QString sKey = QString::number(m_lstValue.count() + 1);
   m_lstValue.insert(sKey, type_bind_value(vValue, paramType));
   return (* this);
}
Exemplo n.º 2
0
QxDataMember_QObject::QxDataMember_QObject(const QMetaObject * pMetaObject, const QString & sKey) : IxDataMember(sKey), m_metaObject(pMetaObject)
{
   m_bAccessDataPointer = false;
   if (! m_metaObject) { qAssert(false); return; }
   int index = m_metaObject->indexOfProperty(qPrintable(sKey));
   if (index == -1) { qAssert(false); return; }
   m_metaProperty = m_metaObject->property(index);
   m_sSqlType = QxClassX::getSqlTypeByClassName(m_metaProperty.typeName());
}
Exemplo n.º 3
0
void execute_client(IxService * pService, const QString & sMethod)
{
   if (pService == NULL) { qAssert(false); return; }
   if (sMethod.isEmpty()) { qAssert(false); return; }
   QxTransaction_ptr pTransaction;
   pTransaction.reset(new QxTransaction());
   pService->setTransaction(pTransaction);
   pTransaction->executeClient(pService, sMethod);
   pTransaction->setMessageReturn(pService->getMessageReturn());
}
Exemplo n.º 4
0
QxSqlQuery & QxSqlQuery::bind(const QString & sKey, const QVariant & vValue, QSql::ParamType paramType /* = QSql::In */)
{
   verifyQuery();
   qAssert(m_lstSqlElement.count() <= 0);
   qAssert(! m_sQuery.isEmpty() && (qx::QxSqlDatabase::getSingleton()->getSqlPlaceHolderStyle() != qx::QxSqlDatabase::ph_style_question_mark));

   if (sKey.isEmpty() || m_lstValue.exist(sKey)) { qAssert(false); return (* this); }
   if (! m_sQuery.contains(sKey)) { qAssert(false); return (* this); }
   m_lstValue.insert(sKey, type_bind_value(vValue, paramType));
   return (* this);
}
Exemplo n.º 5
0
void * IxSqlQueryBuilder::existIdX(long lIndex, const QVariant & idOwner, const QVariant & idData)
{
   QString sIdOwner = idOwner.toString(); QString sIdData = idData.toString();
   if (! m_pIdX || sIdOwner.isEmpty() || sIdData.isEmpty()) { qAssert(false); return NULL; }
   if ((lIndex < 0) || (lIndex >= m_pIdX->count())) { qAssert(false); return NULL; }

   type_id idX(sIdOwner, sIdData);
   type_ptr_by_id_ptr pHash = m_pIdX->at(lIndex);
   if (! pHash || ! pHash->contains(idX)) { return NULL; }

   return pHash->value(idX);
}
Exemplo n.º 6
0
bool IxSqlQueryBuilder::insertIdX(long lIndex, const QVariant & idOwner, const QVariant & idData, void * ptr)
{
   QString sIdOwner = idOwner.toString(); QString sIdData = idData.toString();
   if (! m_pIdX || sIdOwner.isEmpty() || sIdData.isEmpty()) { qAssert(false); return false; }
   if ((lIndex < 0) || (lIndex >= m_pIdX->count())) { qAssert(false); return false; }

   type_id idX(sIdOwner, sIdData);
   type_ptr_by_id_ptr pHash = m_pIdX->at(lIndex);
   if (! ptr || ! pHash || pHash->contains(idX)) { qAssert(false); return false; }
   pHash->insert(idX, ptr);

   return true;
}
Exemplo n.º 7
0
QString QxSqlIsNull::toString() const
{
   qAssert(m_lstColumns.count() == 1);
   QString sReturn, sColumn(m_lstColumns.at(0));
   qAssert(! sColumn.isEmpty());

   switch (m_type)
   {
      case _is_null:       sReturn = sColumn + " IS NULL";        break;
      case _is_not_null:   sReturn = sColumn + " IS NOT NULL";    break;
      default:             qAssert(false);
   }

   return sReturn;
}
Exemplo n.º 8
0
void * QxDataMember_QObject::getDataVoidPtr(const void * pOwner) const
{
   Q_UNUSED(pOwner);
   qDebug("[QxOrm] qx::QxDataMember_QObject::getDataVoidPtr() : '%s'", "cannot access to the data-member pointer with Qt introspection engine");
   qAssert(false);
   return NULL;
}
Exemplo n.º 9
0
void IxSqlQueryBuilder::initIdX(long lAllRelationCount)
{
   if (! m_bCartesianProduct) { qAssert(false); return; }
   m_pIdX.reset(new type_lst_ptr_by_id());
   for (long l = 0; l < (lAllRelationCount + 1); ++l)
   { type_ptr_by_id_ptr pItem = type_ptr_by_id_ptr(new type_ptr_by_id()); m_pIdX->append(pItem); }
}
QString QxSqlGenerator_Standard::getLimit(const QxSqlLimit * pLimit) const
{
   if (! pLimit) { qAssert(false); return ""; }
   QString sStartRow = pLimit->getStartRow_ParamKey();
   QString sRowsCount = pLimit->getRowsCount_ParamKey();
   return ("LIMIT " + sRowsCount + " OFFSET " + sStartRow);
}
Exemplo n.º 11
0
boost::any QxDataMember_QObject::getDataPtr(void * pOwner)
{
   Q_UNUSED(pOwner);
   qDebug("[QxOrm] qx::QxDataMember_QObject::getDataPtr() : '%s'", "cannot access to the data-member pointer with Qt introspection engine");
   qAssert(false);
   return boost::any();
}
Exemplo n.º 12
0
void QxInvalidValueX::insert(const QxInvalidValue & invalidValue)
{
   if (invalidValue.getMessage().isEmpty()) { qAssert(false); return; }
   QxInvalidValue clone = invalidValue;
   clone.setPath(m_sCurrentPath);
   m_lstInvalidValues.append(clone);
}
Exemplo n.º 13
0
void QxSqlGenerator_Oracle::initSqlTypeByClassName() const
{
   QHash<QString, QString> * lstSqlType = qx::QxClassX::getAllSqlTypeByClassName();
   if (! lstSqlType) { qAssert(false); return; }

   lstSqlType->insert("bool", "SMALLINT");
   lstSqlType->insert("qx_bool", "SMALLINT");
   lstSqlType->insert("short", "SMALLINT");
   lstSqlType->insert("int", "INTEGER");
   lstSqlType->insert("long", "INTEGER");
   lstSqlType->insert("long long", "INTEGER");
   lstSqlType->insert("float", "FLOAT");
   lstSqlType->insert("double", "FLOAT");
   lstSqlType->insert("long double", "FLOAT");
   lstSqlType->insert("unsigned short", "SMALLINT");
   lstSqlType->insert("unsigned int", "INTEGER");
   lstSqlType->insert("unsigned long", "INTEGER");
   lstSqlType->insert("unsigned long long", "INTEGER");
   lstSqlType->insert("std::string", "VARCHAR2(4000)");
   lstSqlType->insert("std::wstring", "VARCHAR2(4000)");
   lstSqlType->insert("QString", "VARCHAR2(4000)");
   lstSqlType->insert("QVariant", "CLOB");
   lstSqlType->insert("QUuid", "VARCHAR2(255)");
   lstSqlType->insert("QDate", "DATE");
   lstSqlType->insert("QTime", "DATE");
   lstSqlType->insert("QDateTime", "TIMESTAMP");
   lstSqlType->insert("QByteArray", "BLOB");
   lstSqlType->insert("qx::QxDateNeutral", "VARCHAR2(8)");
   lstSqlType->insert("qx::QxTimeNeutral", "VARCHAR2(6)");
   lstSqlType->insert("qx::QxDateTimeNeutral", "VARCHAR2(14)");
}
Exemplo n.º 14
0
QString IxSqlRelation::tableAliasOwner(QxSqlRelationParams & params) const
{
   if (! m_pClassOwner) { qAssert(false); return ""; }
   QString sTableAliasOwner = (m_pClassOwner->getName() + "_" + QString::number(params.indexOwner()));
   if (params.indexOwner() <= 0) { sTableAliasOwner = params.builder().table(); }
   sTableAliasOwner.replace(".", "_");
   return sTableAliasOwner;
}
Exemplo n.º 15
0
QString QxSoftDelete::buildSqlQueryToUpdate() const
{
   if (this->isEmpty()) { return ""; }
   else if (! m_sSqlQueryToUpdate.isEmpty()) { return m_sSqlQueryToUpdate; }
   else if (m_eMode == QxSoftDelete::mode_flag) { return (m_sColumn + " = '1'"); }
   else if (m_eMode == QxSoftDelete::mode_date_time) { return (m_sColumn + " = '" + QDateTime::currentDateTime().toString(QX_DAO_SOFT_DELETE_QDATETIME_FORMAT) + "'"); }
   qAssert(false); return "";
}
Exemplo n.º 16
0
QString QxSoftDelete::buildSqlQueryToCreateTable() const
{
   if (this->isEmpty()) { return ""; }
   else if (! m_sSqlQueryToCreateTable.isEmpty()) { return m_sSqlQueryToCreateTable; }
   else if (m_eMode == QxSoftDelete::mode_flag) { return (m_sColumn + " " + "TEXT"); }
   else if (m_eMode == QxSoftDelete::mode_date_time) { return (m_sColumn + " " + "TEXT"); }
   qAssert(false); return "";
}
Exemplo n.º 17
0
void QxInvalidValueX::insert(const QString & sMessage)
{
   if (sMessage.isEmpty()) { qAssert(false); return; }
   QxInvalidValue invalidValue;
   invalidValue.setMessage(sMessage);
   invalidValue.setPath(m_sCurrentPath);
   m_lstInvalidValues.append(invalidValue);
}
Exemplo n.º 18
0
QxSqlQuery & QxSqlQuery::query(const QString & sQuery)
{
   if (! sQuery.isEmpty())
   { qAssert(m_lstSqlElement.count() <= 0); }

   clear();
   m_sQuery = sQuery;
   return (* this);
}
Exemplo n.º 19
0
void QxSqlGenerator_Oracle::resolveLimit(QSqlQuery & query, const QxSqlLimit * pLimit) const
{
   if (! pLimit) { qAssert(false); return; }
   QString sMinRow = pLimit->getStartRow_ParamKey();
   QString sMaxRow = pLimit->getMaxRow_ParamKey();
   int iMinRow(pLimit->getStartRow()), iMaxRow(pLimit->getMaxRow());
   bool bQuestionMark = (qx::QxSqlDatabase::getSingleton()->getSqlPlaceHolderStyle() == qx::QxSqlDatabase::ph_style_question_mark);
   if (bQuestionMark) { query.addBindValue(iMaxRow); query.addBindValue(iMinRow); }
   else { query.bindValue(sMaxRow, iMaxRow); query.bindValue(sMinRow, iMinRow); }
}
Exemplo n.º 20
0
void QxFactoryX::registerFactory(const QString & sKey, IxFactory * pFactory)
{
   QMutexLocker locker(& m_oMutexFactoryX);
   qAssert(! sKey.isEmpty() && ! m_mapFactoryX.contains(sKey));

   if (! pFactory || sKey.isEmpty() || m_mapFactoryX.contains(sKey))
      return;

   m_mapFactoryX.insert(sKey, pFactory);
}
Exemplo n.º 21
0
QString QxSoftDelete::buildSqlQueryToFetch(const QString & sTable /* = QString() */) const
{
   QString sCurrTable = (sTable.isEmpty() ? m_sTable : sTable);
   sCurrTable.replace(".", "_");
   if (this->isEmpty()) { return ""; }
   else if (! m_sSqlQueryToFetch.isEmpty()) { return m_sSqlQueryToFetch; }
   else if (m_eMode == QxSoftDelete::mode_flag) { return ("(" + sCurrTable + "." + m_sColumn + " IS NULL" + " OR " + sCurrTable + "." + m_sColumn + " = ''" + " OR " + sCurrTable + "." + m_sColumn + " = '0'" + ")"); }
   else if (m_eMode == QxSoftDelete::mode_date_time) { return ("(" + sCurrTable + "." + m_sColumn + " IS NULL" + " OR " + sCurrTable + "." + m_sColumn + " = ''" + ")"); }
   qAssert(false); return "";
}
Exemplo n.º 22
0
void IxModel::clear(bool bUpdateColumns /* = false */)
{
   if (! m_pCollection) { qAssert(false); return; }
   if (! bUpdateColumns && (m_pCollection->_count() <= 0)) { return; }
   beginResetModel();
   m_pCollection->_clear();
   for (long l = (m_lstChild.count() - 1); l >= 0; l--)
   { removeListOfChild(l); }
   m_lstChild.clear();
   if (bUpdateColumns) { generateRoleNames(); }
   endResetModel();
}
Exemplo n.º 23
0
bool IxSqlRelation::verifyOffset(QxSqlRelationParams & params, bool bId) const
{
   if (! qx::QxSqlDatabase::getSingleton()->getVerifyOffsetRelation()) { return true; }
   IxDataMember * p = (bId ? this->getDataId() : this->getDataMember());
   QString table = (bId ? this->tableAlias(params) : this->tableAliasOwner(params));
   if (! p || table.isEmpty()) { return true; }
   QString sSuffixAlias = ((! bId && (params.indexOwner() > 0)) ? QString("_" + QString::number(params.indexOwner())) : QString());
   int index = params.query().record().indexOf(p->getSqlAlias(table) + sSuffixAlias);
   qAssert(index == params.offset());

   return (index == params.offset());
}
Exemplo n.º 24
0
void QxInvalidValueX::insert(const QxInvalidValueX & other)
{
   for (long l = 0; l < other.count(); l++)
   {
      QxInvalidValue invalidValue = other.at(l);
      if (invalidValue.getMessage().isEmpty()) { qAssert(false); continue; }
      QString sOtherPath = invalidValue.getPath();
      QString sCurrPath = m_sCurrentPath;
      sCurrPath += ((! m_sCurrentPath.isEmpty() && ! sOtherPath.isEmpty()) ? QString(".") : QString(""));
      sCurrPath += sOtherPath;
      invalidValue.setPath(sCurrPath);
      m_lstInvalidValues.append(invalidValue);
   }
}
Exemplo n.º 25
0
bool QxCache::insert(const QString & sKey, const boost::any & anyObj, long lCost /* = 1 */, const QDateTime & dt /* = QDateTime() */)
{
   if (sKey.isEmpty()) { qAssert(false); return false; }
   this->remove(sKey);

   QMutexLocker locker(& m_oMutexCache);
   lCost = ((lCost < 0) ? 0 : lCost);
   QDateTime dtTemp(dt); if (! dtTemp.isValid()) { dtTemp = QDateTime::currentDateTime(); }
   QxCache::type_qx_cache item = boost::make_tuple(lCost, dtTemp, anyObj);
   bool bInsertOk = m_cache.insert(sKey, item);
   if (bInsertOk) { m_lCurrCost += lCost; updateCost(); }

   return bInsertOk;
}
Exemplo n.º 26
0
void QxSqlQuery::fetchSqlResult(QSqlQuery & query)
{
   bool bCheckRecord = true;
   m_pSqlResult.reset(new QxSqlResult());
   if (query.size() > 0) { m_pSqlResult->values.reserve(query.size()); }
   while (query.next())
   {
      if (bCheckRecord)
      {
         bCheckRecord = false;
         QSqlRecord record = query.record();
         m_pSqlResult->positionByKey.reserve(record.count());
         for (int i = 0; i < record.count(); i++)
         { m_pSqlResult->positionByKey.insert(record.fieldName(i), i); }
         qAssert(record.count() == m_pSqlResult->positionByKey.count());
      }
      QVector<QVariant> lst;
      lst.reserve(m_pSqlResult->positionByKey.count());
      for (long j = 0; j < m_pSqlResult->positionByKey.count(); j++)
      { lst.append(query.value(j)); }
      qAssert(lst.count() == m_pSqlResult->positionByKey.count());
      m_pSqlResult->values.append(lst);
   }
}
Exemplo n.º 27
0
QString QxSqlCompare::toString() const
{
   qAssert((m_lstColumns.count() == 1) && (m_lstKeys.count() == 1));
   QString sReturn, sColumn(m_lstColumns.at(0)), sKey(m_lstKeys.at(0));
   qAssert(! sColumn.isEmpty() && ! sKey.isEmpty());

   switch (m_type)
   {
      case _is_equal_to:                     sReturn = sColumn + " = " + sKey;            break;
      case _is_not_equal_to:                 sReturn = sColumn + " <> " + sKey;           break;
      case _is_greater_than:                 sReturn = sColumn + " > " + sKey;            break;
      case _is_greater_than_or_equal_to:     sReturn = sColumn + " >= " + sKey;           break;
      case _is_less_than:                    sReturn = sColumn + " < " + sKey;            break;
      case _is_less_than_or_equal_to:        sReturn = sColumn + " <= " + sKey;           break;
      case _like:                            sReturn = sColumn + " LIKE " + sKey;         break;
      case _not_like:                        sReturn = sColumn + " NOT LIKE " + sKey;     break;
      case _starts_with:                     sReturn = sColumn + " LIKE " + sKey;         break;
      case _ends_with:                       sReturn = sColumn + " LIKE " + sKey;         break;
      case _contains_string:                 sReturn = sColumn + " LIKE " + sKey;         break;
      default:                               qAssert(false);
   }

   return sReturn;
}
Exemplo n.º 28
0
void QxSqlCompare::resolve(QSqlQuery & query) const
{
   qAssert((m_lstKeys.count() == 1) && (m_lstValues.count() == 1));
   QString sKey(m_lstKeys.at(0));
   QVariant vValue(m_lstValues.at(0));

   QString sWildCard = m_pSqlGenerator->getWildCard();
   if (m_type == _starts_with) { vValue = QVariant(vValue.toString() + sWildCard); }
   else if (m_type == _ends_with) { vValue = QVariant(sWildCard + vValue.toString()); }
   else if (m_type == _contains_string) { vValue = QVariant(sWildCard + vValue.toString() + sWildCard); }

   bool bQuestionMark = (qx::QxSqlDatabase::getSingleton()->getSqlPlaceHolderStyle() == qx::QxSqlDatabase::ph_style_question_mark);
   if (bQuestionMark) { query.addBindValue(vValue); }
   else { query.bindValue(sKey, vValue); }
}
Exemplo n.º 29
0
void QxSqlGenerator_Oracle::postProcess(QString & sql, const QxSqlLimit * pLimit) const
{
   if (! pLimit) { qAssert(false); return; }
   QString sMinRow = pLimit->getStartRow_ParamKey();
   QString sMaxRow = pLimit->getMaxRow_ParamKey();
   QString sReplace = "%SQL_QUERY%";

   QString sqlPaging;
   sqlPaging += "SELECT * FROM ";
   sqlPaging += "   ( SELECT a.*, ROWNUM rnum FROM ";
   sqlPaging += "      ( " + sReplace + " ) a ";
   sqlPaging += "     WHERE ROWNUM <= " + sMaxRow + " ) ";
   sqlPaging += "WHERE rnum >= " + sMinRow;
   sqlPaging.replace(sReplace, sql);
   sql = sqlPaging;
}
Exemplo n.º 30
0
void QxInvalidValueX::insert(const IxValidator * pValidator)
{
   if (! pValidator) { return; }
   IxDataMember * pDataMember = pValidator->getDataMember();
   QString sMessage = pValidator->getMessage();
   sMessage.replace("%NAME%", (pDataMember ? pDataMember->getName() : QString()));
   sMessage.replace("%CONSTRAINT%", pValidator->getConstraint().toString());
   QVariantList lstConstraints = pValidator->getConstraints();
   for (long l = 0; l < lstConstraints.count(); l++)
   { sMessage.replace("%CONSTRAINT_" + QString::number(l) + "%", lstConstraints.at(l).toString()); }
   if (sMessage.isEmpty()) { qAssert(false); return; }

   QxInvalidValue invalidValue;
   invalidValue.setValidator(pValidator);
   invalidValue.setMessage(sMessage);
   invalidValue.setPropertyName(pDataMember ? pDataMember->getName() : QString());
   invalidValue.setPath(m_sCurrentPath);
   m_lstInvalidValues.append(invalidValue);
}