Exemple #1
0
  public static void select(
      DbConnection conn,
      String tblName,
      String colName,
      String qual,
      boolean distinct,
      IeciTdLongIntegerArrayList vals)
      throws Exception {

    DbSelectStatement stmt = null;

    try {

      stmt = new DbSelectStatement();
      /* String sql = */ stmt.create(conn, tblName, colName, qual, distinct);
      stmt.execute();

      while (stmt.next()) {
        vals.add(stmt.getLongInteger(1));
      }

      stmt.release();

    } catch (Exception e) {
      DbSelectStatement.ensureRelease(stmt, e);
    }
  }
Exemple #2
0
  public static int selectCountDistinct(
      DbConnection conn, String with, String tblName, String qual, String distinctFields)
      throws Exception {

    int val = 0;
    DbSelectStatement stmt = null;
    String stmtText;

    try {
      stmt = new DbSelectStatement();
      if (qual == null) stmtText = "SELECT COUNT(DISTINCT " + distinctFields + ") FROM " + tblName;
      else stmtText = "SELECT COUNT(DISTINCT " + distinctFields + ") FROM " + tblName + " " + qual;

      if (with != null) {
        stmtText = with + Constants.BLANK + stmtText;
      }

      stmt.create(conn, stmtText);
      stmt.execute();

      if (stmt.next()) val = stmt.getLongInteger(1);
      else val = 0;

      stmt.release();

      return val;

    } catch (Exception e) {
      DbSelectStatement.ensureRelease(stmt, e);
      throw e;
    }
  }
Exemple #3
0
  private static int selectCountBase(DbConnection conn, String stmtText) throws Exception {
    int val = 0;
    DbSelectStatement stmt = null;
    try {
      stmt = new DbSelectStatement();

      stmt.create(conn, stmtText);
      stmt.execute();

      if (stmt.next()) val = stmt.getLongInteger(1);
      else val = 0;

      stmt.release();

      return val;

    } catch (Exception e) {
      DbSelectStatement.ensureRelease(stmt, e);
      throw e;
    }
  }
Exemple #4
0
  public static int selectCount(
      DbConnection conn, String tblName, String colName, String qual, boolean distinct)
      throws Exception {

    int val = 0;
    DbSelectStatement stmt = null;
    StringBuffer stmtText = new StringBuffer();

    try {
      stmt = new DbSelectStatement();

      stmtText.append("SELECT ");

      stmtText.append("COUNT(");

      if (distinct) {
        stmtText.append("DISTINCT ");
      }

      stmtText.append(colName).append(") FROM ").append(tblName);

      if (qual != null) stmtText.append(" ").append(qual);

      stmt.create(conn, stmtText.toString());
      stmt.execute();

      if (stmt.next()) val = stmt.getLongInteger(1);
      else val = 0;

      stmt.release();

      return val;

    } catch (Exception e) {
      DbSelectStatement.ensureRelease(stmt, e);
      throw e;
    }
  }
Exemple #5
0
  public static int selectLongInteger(
      DbConnection conn, String tblName, String colName, String qual) throws Exception {

    int val = DbDataType.NULL_LONG_INTEGER;
    DbSelectStatement stmt = null;

    try {

      stmt = new DbSelectStatement();
      /* String sql = */ stmt.create(conn, tblName, colName, qual, false);
      stmt.execute();

      if (stmt.next()) {
        val = stmt.getLongInteger(1);
        stmt.release();
        return val;
      } else throw new IeciTdException(DbError.EC_NOT_FOUND, DbError.EM_NOT_FOUND);

    } catch (Exception e) {
      DbSelectStatement.ensureRelease(stmt, e);
      throw e;
    }
  }