buildBetweenClause build clause in a specified table range. the result where clause will be low <= quotaCols < up. In other words, [low, up)
(buf *bytes.Buffer, quotaCols []string, low []string, up []string)
| 1148 | // buildBetweenClause build clause in a specified table range. |
| 1149 | // the result where clause will be low <= quotaCols < up. In other words, [low, up) |
| 1150 | func buildBetweenClause(buf *bytes.Buffer, quotaCols []string, low []string, up []string) { |
| 1151 | singleBetween := func(writeEqual bool) { |
| 1152 | buf.WriteString(quotaCols[0]) |
| 1153 | buf.WriteByte(greater) |
| 1154 | if writeEqual { |
| 1155 | buf.WriteByte(equal) |
| 1156 | } |
| 1157 | buf.WriteString(low[0]) |
| 1158 | buf.WriteString(" and ") |
| 1159 | buf.WriteString(quotaCols[0]) |
| 1160 | buf.WriteByte(less) |
| 1161 | buf.WriteString(up[0]) |
| 1162 | } |
| 1163 | // handle special cases with common prefix |
| 1164 | commonLen := getCommonLength(low, up) |
| 1165 | if commonLen > 0 { |
| 1166 | // unexpected case for low == up, return empty result |
| 1167 | if commonLen == len(low) { |
| 1168 | buf.WriteString("false") |
| 1169 | return |
| 1170 | } |
| 1171 | for i := 0; i < commonLen; i++ { |
| 1172 | if i > 0 { |
| 1173 | buf.WriteString(" and ") |
| 1174 | } |
| 1175 | buf.WriteString(quotaCols[i]) |
| 1176 | buf.WriteByte(equal) |
| 1177 | buf.WriteString(low[i]) |
| 1178 | } |
| 1179 | buf.WriteString(" and(") |
| 1180 | defer buf.WriteByte(')') |
| 1181 | quotaCols = quotaCols[commonLen:] |
| 1182 | low = low[commonLen:] |
| 1183 | up = up[commonLen:] |
| 1184 | } |
| 1185 | |
| 1186 | // handle special cases with only one column |
| 1187 | if len(quotaCols) == 1 { |
| 1188 | singleBetween(true) |
| 1189 | return |
| 1190 | } |
| 1191 | buf.WriteByte('(') |
| 1192 | singleBetween(false) |
| 1193 | buf.WriteString(")or(") |
| 1194 | buf.WriteString(quotaCols[0]) |
| 1195 | buf.WriteByte(equal) |
| 1196 | buf.WriteString(low[0]) |
| 1197 | buf.WriteString(" and(") |
| 1198 | buildCompareClause(buf, quotaCols[1:], low[1:], greater, true) |
| 1199 | buf.WriteString("))or(") |
| 1200 | buf.WriteString(quotaCols[0]) |
| 1201 | buf.WriteByte(equal) |
| 1202 | buf.WriteString(up[0]) |
| 1203 | buf.WriteString(" and(") |
| 1204 | buildCompareClause(buf, quotaCols[1:], up[1:], less, false) |
| 1205 | buf.WriteString("))") |
| 1206 | } |
| 1207 |
no test coverage detected