コード例 #1
0
  private void updateInDB() {

    if (_mWhereClause != null) {
      ContentValues lValues = new ContentValues();
      String[] lArgs = new String[_mWhereClauseColumns.length];
      int lSize = _mListOfColumns.size();

      for (int i = 0; i < lSize; i++) {

        String lColumnName = _mListOfColumns.get(i).getName();
        TCell lCell = cellByName(lColumnName);
        String lColumnValue = lCell.asString();
        DBAccessMode lAccessMode = lCell.getDBAccessMode();

        if (lAccessMode == DBAccessMode.UPDATE) lValues.put(lColumnName, lColumnValue);
      }

      for (int i = 0; i < _mWhereClauseColumns.length; i++) {

        if (indexOfColumn(_mWhereClauseColumns[i]) == -1) {
          PuUtils.showMessage(
              _mContext,
              "Erreur Column",
              "Column "
                  + _mWhereClauseColumns[i]
                  + " de clause Where  "
                  + "n'est pas une column de client data table :"
                  + _mCDTName);
          return;
        } else if (lValues.containsKey(_mWhereClauseColumns[i])) {
          PuUtils.showMessage(
              _mContext,
              "Erreur Column",
              "impossible de definir la colonne "
                  + _mWhereClauseColumns[i]
                  + " de clause Where comme colonne à modifier dans le CDT:"
                  + _mCDTName);
          return;
        }
        TCell lCell = cellByName(_mWhereClauseColumns[i]);
        lArgs[i] = lCell.asString();
      }
      if (lValues.size() != 0)
        _mSqliteDataBase.update(_mTableName, lValues, _mWhereClause.toString(), lArgs);
    } else PuUtils.showMessage(_mContext, "Erreur Update", "Clause where non definit");
  }
コード例 #2
0
  private void deleteFromDB() {

    if (_mWhereClause != null) {

      String[] lArgs = new String[_mWhereClauseColumns.length];

      for (int i = 0; i < _mWhereClauseColumns.length; i++) {
        TCell lCell = cellByName(_mWhereClauseColumns[i]);

        lArgs[i] = lCell.asString();
        if (lCell.asString().equals(""))
          Log.e(TAG_Error, "Valeur vide pour la clé de suppression :" + _mWhereClauseColumns[i]);
      }

      _mSqliteDataBase.delete(_mTableName, _mWhereClause.toString(), lArgs);
    } else PuUtils.showMessage(_mContext, "Erreur delete", "Clause where non definit");
  }
コード例 #3
0
  private void insertInDB() {

    ContentValues lValues = new ContentValues();

    int lSize = _mListOfColumns.size();

    for (int i = 0; i < lSize; i++) {

      String lColumnName = _mListOfColumns.get(i).getName();
      TCell lCell = cellByName(lColumnName);
      String lColumnValue = lCell.asString();
      DBAccessMode lAccessMode = lCell.getDBAccessMode();

      if (lAccessMode == DBAccessMode.INSERT) lValues.put(lColumnName, lColumnValue);
    }
    if (lValues.size() == 0) {
      PuUtils.showMessage(_mContext, "Erreur insertion", "Acune valeur définie pour inserer");
      return;
    }
    _mSqliteDataBase.insertOrThrow(_mTableName, null, lValues);
  }
コード例 #4
0
    @Override
    public int compare(TRow pRow1, TRow pRow2) {

      int lCompare = 0;
      int lIndexOfCoulmn = 0;

      // init Cells to compare
      TCell lCellRow1 = pRow1.getCell(indexOfColumn(_mListOfSortedColumnsName[lIndexOfCoulmn]));
      TCell lCellRow2 = pRow2.getCell(indexOfColumn(_mListOfSortedColumnsName[lIndexOfCoulmn]));

      for (int i = 0; i < _mListOfSortedColumnsName.length; i++) {

        // Update cells with the differents values of columns names
        lCellRow1 = pRow1.getCell(indexOfColumn(_mListOfSortedColumnsName[i]));
        lCellRow2 = pRow2.getCell(indexOfColumn(_mListOfSortedColumnsName[i]));

        switch (lCellRow1.getValueType()) {
          case INTEGER:
            // If eguals , incremente lIndexOfColumn to pass to the next
            // columns comparaison
            if (lCellRow1.asInteger() == lCellRow2.asInteger())
              if (lIndexOfCoulmn < _mListOfSortedColumnsName.length - 1) lIndexOfCoulmn++;
              else break;
            break;
          case DOUBLE:
            // If eguals , incremente lIndexOfColumn to pass to the next columns comparaison
            if (lCellRow1.asDouble() == lCellRow2.asDouble())
              if (lIndexOfCoulmn < _mListOfSortedColumnsName.length - 1) lIndexOfCoulmn++;
              else break;
            break;

          case BOOLEAN:
          case TEXT:
            if (lCellRow1.asString().equals(lCellRow2.asString()))
              if (lIndexOfCoulmn < _mListOfSortedColumnsName.length - 1) lIndexOfCoulmn++;
              else break;
            break;

          default:
            break;
        }
        // Update cells with the differents values of columns names
        lCellRow1 = pRow1.getCell(indexOfColumn(_mListOfSortedColumnsName[lIndexOfCoulmn]));
        lCellRow2 = pRow2.getCell(indexOfColumn(_mListOfSortedColumnsName[lIndexOfCoulmn]));

        switch (lCellRow1.getValueType()) {
          case INTEGER:
            lCompare = lCellRow1.asInteger() - lCellRow2.asInteger();
            break;
          case DOUBLE:
            lCompare = Double.compare(lCellRow1.asDouble(), lCellRow2.asDouble());
            break;
          case BOOLEAN:
          case TEXT:
            lCompare = lCellRow1.asString().compareTo(lCellRow2.asString());
            break;
          default:
            break;
        }
      }
      // inverse sort
      if (_mSortType == TRowSortOrder.DESC) lCompare = -lCompare;

      return lCompare;
    }