Handle COPY IN in batch_execute

This commit is contained in:
Steven Fackler 2014-10-05 17:31:25 -07:00
parent 58dd5fe12b
commit b69ae99a51
2 changed files with 18 additions and 0 deletions

View File

@ -690,6 +690,13 @@ impl InnerPostgresConnection {
opt.map(|b| String::from_utf8_lossy(b[]).into_string())
}).collect());
}
CopyInResponse { .. } => {
try_pg!(self.write_messages([
CopyFail {
message: "COPY queries cannot be directly executed",
},
Sync]));
}
ErrorResponse { fields } => {
try!(self.wait_for_ready());
return PostgresDbError::new(fields);

View File

@ -750,3 +750,14 @@ fn test_copy_in_bad_column_count() {
or_fail!(conn.execute("SELECT 1", []));
}
#[test]
fn test_batch_execute_copy_from_err() {
let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl));
or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT)", []));
match conn.batch_execute("COPY foo (id) FROM STDIN") {
Err(PgDbError(ref err)) if err.message[].contains("COPY") => {}
Err(err) => fail!("Unexptected error {}", err),
_ => fail!("Expected error"),
}
}