buildParameters method

  1. @protected
void buildParameters({
  1. bool? getIsDeleted,
  2. int? pSize,
})

Implementation

@protected
void buildParameters({bool? getIsDeleted, int? pSize}) {
  _pagesize = pSize ?? _pagesize;
  _getIsDeleted = getIsDeleted ?? _getIsDeleted;
  if (_page > 0 && _pagesize > 0) {
    qparams
      ..limit = _pagesize
      ..offset = (_page - 1) * _pagesize;
  } else {
    qparams
      ..limit = _pagesize
      ..offset = _page;
  }
  for (DbParameter param in parameters) {
    if (param.columnName != null) {
      if (param.value is List && !param.hasParameter) {
        param.value = param.dbType == DbType.text || param.value[0] is String ? '\'${param.value.join('\',\'')}\'' : param.value.join(',');
        whereString += param.whereString.replaceAll('{field}', param.columnName!).replaceAll('?', param.value.toString());
        param.value = null;
      } else {
        if (param.value is Map<String, dynamic> && param.value['sql'] != null) {
          param
            ..whereString = param.whereString.replaceAll('?', param.value['sql'].toString())
            ..dbType = DbType.integer
            ..value = param.value['args'];
        }
        whereString += param.whereString.replaceAll('{field}', param.columnName!);
      }
      if (!param.whereString.contains('?')) {
      } else {
        switch (param.dbType) {
          case DbType.bool:
            param.value = param.value == null
                ? null
                : param.value == true
                    ? 1
                    : 0;
            param.value2 = param.value2 == null
                ? null
                : param.value2 == true
                    ? 1
                    : 0;
            break;
          case DbType.date:
          case DbType.datetime:
          case DbType.datetimeUtc:
            param.value = param.value == null ? null : (param.value as DateTime).millisecondsSinceEpoch;
            param.value2 = param.value2 == null ? null : (param.value2 as DateTime).millisecondsSinceEpoch;
            break;
          default:
        }
        if (param.value != null) {
          if (param.value is List) {
            for (var p in param.value) {
              whereArguments.add(p);
            }
          } else {
            whereArguments.add(param.value);
          }
        }
        if (param.value2 != null) {
          whereArguments.add(param.value2);
        }
      }
    } else {
      whereString += param.whereString;
    }
  }
  if (_tableObj!.softDeleteActivated) {
    if (whereString != '') {
      whereString = '${!_getIsDeleted ? 'ifnull(isDeleted,0)=0 AND' : ''} ($whereString)';
    } else if (!_getIsDeleted) {
      whereString = 'ifnull(isDeleted,0)=0';
    }
  }

  if (whereString != '') {
    qparams.whereString = whereString;
  }
  qparams
    ..whereArguments = whereArguments
    ..groupBy = groupByList.join(',')
    ..orderBy = orderByList.join(',')
    ..having = havingList.join(',');
}