示例#1
0
void IDBCursorBackend::deleteFunction(PassRefPtr<IDBCallbacks> prpCallbacks, ExceptionCode&)
{
    LOG(StorageAPI, "IDBCursorBackend::delete");
    ASSERT(m_transaction->mode() != IndexedDB::TransactionMode::ReadOnly);
    RefPtr<IDBKeyRange> keyRange = IDBKeyRange::create(primaryKey());
    m_transaction->database().deleteRange(m_transaction->id(), m_objectStoreID, keyRange.release(), prpCallbacks);
}
示例#2
0
void Table::save(Database *db)
{
    QSqlQuery q = db->exec(db->sqlGenertor()->saveRecord(this, db->tableName(metaObject()->className())));

    if(status() == Added && isPrimaryKeyAutoIncrement())
        setProperty(primaryKey().toLatin1().data(), q.lastInsertId());

    foreach(TableSetBase *ts, tableSets)
        ts->save(db);
    setStatus(FeatchedFromDB);
}
示例#3
0
void Table::propertyChanged(QString propName)
{
    if(propName == primaryKey())
        return;

    _changedProperties.insert(propName);
    if(_status == FeatchedFromDB)
        _status = Modified;

    if(_status == NewCreated)
        _status = Added;
}
示例#4
0
QString QFieldPrivate::commonSqlDescription() const
{
    QString rs;

    if (autoIncrement())
        rs += QLatin1String(" AUTO_INCREMENT");

    if (acceptsNull())
        rs += QLatin1String(" NULL");
    else
        rs += QLatin1String(" NOT NULL");

    if (primaryKey())
        rs += QLatin1String(" PRIMARY KEY");

    return rs;
}
示例#5
0
QString SqliteDriver::sqlCreateTable(FLTableMetaData *tmd)
{
#ifndef FL_QUICK_CLIENT
  if (!tmd)
    return QString::null;

  QString primaryKey(QString::null);
  QString sql = "CREATE TABLE " + tmd->name() + " (";

  FLFieldMetaData *field;
  FLTableMetaData::FLFieldMetaDataList *fieldList = tmd->fieldList();

  unsigned int unlocks = 0;
  QDictIterator<FLFieldMetaData> it(*fieldList);
  while ((field = it.current()) != 0) {
    ++it;
    if (field->type() == FLFieldMetaData::Unlock)
      unlocks++;
  }
  if (unlocks > 1) {
#ifdef FL_DEBUG
    qWarning("FLManager : " + QApplication::tr("No se ha podido crear la tabla ") + tmd->name());
    qWarning("FLManager : " + QApplication::tr("Hay más de un campo tipo unlock. Solo puede haber uno."));
#endif

    return QString::null;
  }

  QDictIterator<FLFieldMetaData> it2(*fieldList);
  while ((field = it2.current()) != 0) {
    ++it2;
    sql += field->name();
    switch (field->type()) {
      case QVariant::Int:
        sql += " INTEGER";
        break;

      case QVariant::UInt:
        sql += " INTEGER";
        break;

      case QVariant::Bool:
      case FLFieldMetaData::Unlock:
        sql += " BOOLEAN";
        break;

      case QVariant::Double:
        sql += " FLOAT";
        break;

      case QVariant::Time:
        sql += " VARCHAR(20)";
        break;

      case QVariant::Date:
        sql += " VARCHAR(20)";
        break;

      case QVariant::Pixmap:
        sql += " TEXT";
        break;

      case QVariant::String:
        sql += " VARCHAR";
        break;

      case QVariant::StringList:
        sql += " TEXT";
        break;

      case QVariant::ByteArray:
        sql += " CLOB";
        break;

      case FLFieldMetaData::Serial:
        sql += " INTEGER";
        if (!field->isPrimaryKey())
          sql += " PRIMARY KEY";
        break;
    }

    int longitud = field->length();
    if (longitud > 0)
      sql += "(" + QString::number(longitud) + ")";

    if (field->isPrimaryKey()) {
      if (primaryKey.isEmpty()) {
        sql += " PRIMARY KEY";
        primaryKey = field->name();
      } else {
#ifdef FL_DEBUG
        qWarning(QApplication::tr("FLManager : Tabla -> ") +
                 tmd->name() + QApplication::tr(" . Se ha intentado poner una segunda clave primaria para el campo ") +
                 field->name() + QApplication::tr(" , pero el campo ") + primaryKey +
                 QApplication::tr(" ya es clave primaria. Sólo puede existir una clave primaria en FLTableMetaData, use FLCompoundKey para crear claves compuestas."));
#endif

        return QString::null;
      }
    } else {
      if (field->isUnique())
        sql += " UNIQUE";
      if (!field->allowNull())
        sql += " NOT NULL";
      else
        sql += " NULL";
    }

    if (it2.current())
      sql += ",";
  }

  sql += ");";

  QString createIndex = "CREATE INDEX " + tmd->name() + "_pkey ON " + tmd->name() + " (" + tmd->primaryKey() + ");";

  sql += createIndex;

  return sql;

#endif //FL_QUICK_CLIENT

  return QString::null;
}
示例#6
0
bool QOrmObject::needPrimaryKey()
{
    return (primaryKey().isNull() || primaryKey() == 0) && !isSaved();
}
/* ---------------------------------------------------------------- */
bool
Dbtup::createTrigger(Tablerec* table, const CreateTrigReq* req)
{
  if (ERROR_INSERTED(4003)) {
    CLEAR_ERROR_INSERT_VALUE;
    return false;
  }
  TriggerType::Value ttype = req->getTriggerType();
  TriggerActionTime::Value ttime = req->getTriggerActionTime();
  TriggerEvent::Value tevent = req->getTriggerEvent();

  DLList<TupTriggerData>* tlist = findTriggerList(table, ttype, ttime, tevent);
  ndbrequire(tlist != NULL);

  TriggerPtr tptr;
  if (!tlist->seize(tptr))
    return false;

  // Set trigger id
  tptr.p->triggerId = req->getTriggerId();

  //  ndbout_c("Create TupTrigger %u = %u %u %u %u", tptr.p->triggerId, table, ttype, ttime, tevent);

  // Set index id
  tptr.p->indexId = req->getIndexId();

  // Set trigger type etc
  tptr.p->triggerType = ttype;
  tptr.p->triggerActionTime = ttime;
  tptr.p->triggerEvent = tevent;

  tptr.p->sendBeforeValues = true;
  if ((tptr.p->triggerType == TriggerType::SUBSCRIPTION) &&
      ((tptr.p->triggerEvent == TriggerEvent::TE_UPDATE) ||
       (tptr.p->triggerEvent == TriggerEvent::TE_DELETE))) {
    jam();
    tptr.p->sendBeforeValues = false;
  }
  /*
  tptr.p->sendOnlyChangedAttributes = false;
  if (((tptr.p->triggerType == TriggerType::SUBSCRIPTION) ||
      (tptr.p->triggerType == TriggerType::SUBSCRIPTION_BEFORE)) &&
      (tptr.p->triggerEvent == TriggerEvent::TE_UPDATE)) {
    jam();
    tptr.p->sendOnlyChangedAttributes = true;
  }
  */
  tptr.p->sendOnlyChangedAttributes = !req->getReportAllMonitoredAttributes();
  // Set monitor all
  tptr.p->monitorAllAttributes = req->getMonitorAllAttributes();
  tptr.p->monitorReplicas = req->getMonitorReplicas();
  tptr.p->m_receiverBlock = refToBlock(req->getReceiverRef());

  tptr.p->attributeMask.clear();
  if (tptr.p->monitorAllAttributes) {
    jam();
    for(Uint32 i = 0; i < table->m_no_of_attributes; i++) {
      if (!primaryKey(table, i)) {
        jam();
        tptr.p->attributeMask.set(i);
      }
    }
  } else {
    // Set attribute mask
    jam();
    tptr.p->attributeMask = req->getAttributeMask();
  }
  return true;
}//Dbtup::createTrigger()
示例#8
0
QVariant Table::primaryValue() const
{
    return property(primaryKey().toLatin1().data());
}
示例#9
0
bool Table::isPrimaryKeyAutoIncrement() const
{
    return TableModel::model(metaObject()->className())->field(primaryKey())->isAutoIncrement;
}