Exemplo n.º 1
0
CardView::CardView(Table table, QSqlRelationalTableModel &model, int row)
	:ui(new Ui::CardView),
	mTable(table),
	mModel(model),
	mRow(row),
	isInsert(row == -1)
{
	ui->setupUi(this);



	for (int i=0; i < mTable.colums().size(); ++i)
	{
		auto column = mTable.colums()[i];

		QWidget* widget = column.isForeingKey()
						? createForeingLinkItem(column, mModel.data(mModel.index(row, i)))
						: createSimpleItem(column.columnType(), mModel.data(mModel.index(row, i)));

		if(!isInsert && column.isPrimaryKey())
			widget->setEnabled(false);

		if(column.isAutoInc())
			widget->setEnabled(false);

		ui->formLayout->addRow(column.caption(), widget);
	}
}
Exemplo n.º 2
0
bool QOrmAttributeInfo::writeIndex(QOrmObject *obj, QVariant pk)
{
    if(!isPrimaryKey()) return false;

    obj->d->indexes.replace(d->indexIndex, pk);
    return true;
}
Exemplo n.º 3
0
string Field::getDefinition() const {
    string value = _name + " " + getTypeStr();

    if (isPrimaryKey())
        value += " PRIMARY KEY";

    if (isNotNull())
        value += " NOT NULL";

    return trim(value);
}
Exemplo n.º 4
0
QVariant QOrmAttributeInfo::readIndex(QOrmObject *obj)
{
    if (!isPrimaryKey()) return QVariant();

    if (isForeignKey())
    {
        QOrmObject* ofk = readForeignKey(obj);
        if (ofk) return refAttribute().read(ofk);
    }
    return obj->d->indexes.at(d->indexIndex);
}
Exemplo n.º 5
0
void QOrmAttributeInfo::load(QOrmObject *obj, QVariant value)
{
    if (!d->valid) return;

    if (!d->f_ld)
    {
        if (isForeignKey() || isPrimaryKey()) writeIndex(obj, value);
        if (d->metaProperty.type() < QVariant::UserType)
            //d->metaProperty.write(obj, value);
            obj->setProperty(d->property, value);
        return;
    }

    (obj->*(d->f_ld))(value);
}
Exemplo n.º 6
0
QString QOrmAttributeInfo::store(QOrmObject *obj)
{
    if (!d->f_st)
    {
        QVariant v = read(obj);
        if (v.isNull())
        {
            if (isForeignKey() || isPrimaryKey())
                v = readIndex(obj);
        }
        else
        {
            //qDebug()<<QOrm::isOrmObject(v)<<v<<isForeignKey();
            if (isForeignKey() && QOrm::isOrmObject(v))
            //if (QOrm::isOrmObject(v))
            {
                QOrmObject *fk = v.value<QOrmObject*>();
                if (!fk) v = QVariant();
                else v = refAttribute().readIndex(fk);
            }
        }

        switch (v.type())
        {
            case QVariant::Date:
            case QVariant::DateTime:
            case QVariant::Time:
            case QVariant::String:
                return '\'' + v.toString() + '\'';
            case QVariant::Invalid:
            case QVariant::UserType:
                return "NULL";
            case QVariant::Int:
            case QVariant::Double:
            default:
                return v.toString();
        }
    }

    return (obj->*(d->f_st))();
}
// LCOV_EXCL_START :dpm
// -----------------------------------------------------------------------
// Print function for debugging
// -----------------------------------------------------------------------
void NAColumn::print(FILE* ofd, const char* indent, const char* title,
                     CollHeap *c, char *buf) const
{
    const Int32 A = 0x18, D = 0x19; // up-arrow, down-arrow; just to be cute
  char ckstr[3+1];
  SortOrdering cko = getClusteringKeyOrdering();
  if (cko == ASCENDING)		sprintf(ckstr, "ck%c", A);
  else if (cko == DESCENDING)	sprintf(ckstr, "ck%c", D);
  else				ckstr[0] = '\0';

  Space * space = (Space *)c;
  char mybuf[1000];
  sprintf(mybuf,"%s%s %-8s %-16s %d\t| %2s %2s %2s %3s %s %s\n",
          title, indent, colName_.data(),
          type_->getTypeSQLname(TRUE/*terse*/).data(), position_,
          isIndexKey()        ? "ik"  : "",
          isPartitioningKey() ? "hp"  : "",
          isPrimaryKey()      ? "pk"  : "",
          ckstr,
          isComputedColumn() ? computedColumnExpression_ : "",
          isReferencedForHistogram() ? "refForHist" :
          isReferenced() ? "ref" : "");
  PRINTIT(ofd, c, space, buf, mybuf);
}