insertAll method

Future<void> insertAll(
  1. List<TRow> rows
)

Inserts rows in batches within SQL Server's row and parameter limits.

Implementation

Future<void> insertAll(List<TRow> rows) async {
  if (rows.isEmpty) return;
  _checkDecimalAgreement();
  final resolved = await _dialect();
  final writable = binding.writableColumns;
  if (writable.isEmpty) {
    throw StateError(
      'Inserting into ${binding.qualifiedName} would write no columns.',
    );
  }
  // 2100 is the server's ceiling; 2000 leaves room and keeps the arithmetic
  // obvious. 1000 is the VALUES row limit.
  final perStatement = (2000 ~/ writable.length).clamp(1, 1000);
  for (var start = 0; start < rows.length; start += perStatement) {
    final end = (start + perStatement).clamp(0, rows.length);
    await _insertBatch(rows.sublist(start, end), writable, resolved);
  }
}