desugarDuplicateVariables method

List<Variable<Object>> desugarDuplicateVariables(
  1. List<Variable<Object>> original,
  2. List<int> syntacticOccurences
)

For dialects that don't support named or explicitly-indexed variables, translates a variable assignment to avoid using that feature.

For instance, the SQL snippet WHERE x = :a OR y = :a would be translated to WHERE x = ? OR y = ?. Then, original would contain the value for the single variable and syntacticOccurences would contain two values (1 and 1) referencing the original variable.

Implementation

List<Variable> desugarDuplicateVariables(
  List<Variable> original,
  List<int> syntacticOccurences,
) {
  if (supportsIndexedParameters) return original;

  return [
    for (final occurence in syntacticOccurences)
      // Variables in SQL are 1-indexed
      original[occurence - 1],
  ];
}