Merge pull request #341 from gwenn/column-index

Make Statement::column_index case insensitive (#330)
This commit is contained in:
gwenn 2018-03-27 21:14:00 +02:00 committed by GitHub
commit 2aebdeb46a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 3 deletions

View File

@ -1,8 +1,8 @@
environment: environment:
matrix: matrix:
- TARGET: 1.21.0-x86_64-pc-windows-gnu - TARGET: 1.24.1-x86_64-pc-windows-gnu
MSYS2_BITS: 64 MSYS2_BITS: 64
- TARGET: 1.21.0-x86_64-pc-windows-msvc - TARGET: 1.24.1-x86_64-pc-windows-msvc
VCPKG_DEFAULT_TRIPLET: x64-windows VCPKG_DEFAULT_TRIPLET: x64-windows
VCPKGRS_DYNAMIC: 1 VCPKGRS_DYNAMIC: 1
- TARGET: nightly-x86_64-pc-windows-msvc - TARGET: nightly-x86_64-pc-windows-msvc

View File

@ -45,7 +45,7 @@ impl<'conn> Statement<'conn> {
let bytes = name.as_bytes(); let bytes = name.as_bytes();
let n = self.column_count(); let n = self.column_count();
for i in 0..n { for i in 0..n {
if bytes == self.stmt.column_name(i).to_bytes() { if bytes.eq_ignore_ascii_case(self.stmt.column_name(i).to_bytes()) {
return Ok(i); return Ok(i);
} }
} }
@ -785,4 +785,30 @@ mod test {
let y: Result<i64> = stmt.query_row(&[&1i32], |r| r.get(0)); let y: Result<i64> = stmt.query_row(&[&1i32], |r| r.get(0));
assert_eq!(3i64, y.unwrap()); assert_eq!(3i64, y.unwrap());
} }
#[test]
fn test_query_by_column_name() {
let db = Connection::open_in_memory().unwrap();
let sql = "BEGIN;
CREATE TABLE foo(x INTEGER, y INTEGER);
INSERT INTO foo VALUES(1, 3);
END;";
db.execute_batch(sql).unwrap();
let mut stmt = db.prepare("SELECT y FROM foo").unwrap();
let y: Result<i64> = stmt.query_row(&[], |r| r.get("y"));
assert_eq!(3i64, y.unwrap());
}
#[test]
fn test_query_by_column_name_ignore_case() {
let db = Connection::open_in_memory().unwrap();
let sql = "BEGIN;
CREATE TABLE foo(x INTEGER, y INTEGER);
INSERT INTO foo VALUES(1, 3);
END;";
db.execute_batch(sql).unwrap();
let mut stmt = db.prepare("SELECT y as Y FROM foo").unwrap();
let y: Result<i64> = stmt.query_row(&[], |r| r.get("y"));
assert_eq!(3i64, y.unwrap());
}
} }