Skip to content

Commit d8465f3

Browse files
committed
Fixed querys with more than 26 fields
1 parent fc6920a commit d8465f3

File tree

1 file changed

+22
-5
lines changed
  • src/internal/query_context

1 file changed

+22
-5
lines changed

src/internal/query_context/mod.rs

+22-5
Original file line numberDiff line numberDiff line change
@@ -492,20 +492,37 @@ struct OrderBy {
492492
struct NumberAsAZ(usize);
493493
impl fmt::Display for NumberAsAZ {
494494
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
495-
static ALPHABET: [char; 26] = [
495+
const LEN: usize = 26;
496+
static ALPHABET: [char; LEN] = [
496497
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
497498
'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
498499
];
499500
let mut x = self.0;
500501
match x {
501-
0..26 => f.write_char(ALPHABET[x]),
502+
0..LEN => f.write_char(ALPHABET[x]),
502503
_ => {
503-
while x > 26 {
504-
f.write_char(ALPHABET[x % 26])?;
505-
x /= 26;
504+
while x >= LEN {
505+
f.write_char(ALPHABET[x % LEN])?;
506+
x /= LEN;
507+
x -= 1;
506508
}
507509
f.write_char(ALPHABET[x])
508510
}
509511
}
510512
}
511513
}
514+
515+
#[cfg(test)]
516+
mod test {
517+
use super::NumberAsAZ;
518+
519+
#[test]
520+
fn test_number_as_az() {
521+
assert_eq!(NumberAsAZ(0).to_string(), "a");
522+
assert_eq!(NumberAsAZ(25).to_string(), "z");
523+
assert_eq!(NumberAsAZ(26).to_string(), "aa");
524+
assert_eq!(NumberAsAZ(27).to_string(), "ba");
525+
assert_eq!(NumberAsAZ(51).to_string(), "za");
526+
assert_eq!(NumberAsAZ(52).to_string(), "ab");
527+
}
528+
}

0 commit comments

Comments
 (0)