Skip to content

Commit 70b4910

Browse files
committed
Add a bit to quick_query
1 parent a0df39b commit 70b4910

1 file changed

Lines changed: 22 additions & 14 deletions

File tree

lib.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ use std::io::net;
8282
use std::io::net::ip::{Port, SocketAddr};
8383
use std::io::net::tcp::TcpStream;
8484
use std::task;
85+
use std::str;
8586

8687
use self::error::{PostgresDbError,
8788
PostgresConnectError,
@@ -539,6 +540,25 @@ impl InnerPostgresConnection {
539540
_ => unreachable!()
540541
}
541542
}
543+
544+
fn quick_query(&mut self, query: &str) -> ~[~[Option<~str>]] {
545+
self.write_messages([Query { query: query }]);
546+
547+
let mut result = ~[];
548+
loop {
549+
match self.read_message() {
550+
ReadyForQuery { .. } => break,
551+
DataRow { row } =>
552+
result.push(row.move_iter().map(|opt|
553+
opt.map(|b| str::from_utf8_owned(b))).collect()),
554+
ErrorResponse { fields } =>
555+
fail!("Error: {}",
556+
PostgresDbError::new(fields).to_str()),
557+
_ => {}
558+
}
559+
}
560+
result
561+
}
542562
}
543563

544564
/// A connection to a Postgres database.
@@ -669,20 +689,8 @@ impl PostgresConnection {
669689
self.conn.with(|conn| conn.cancel_data)
670690
}
671691

672-
fn quick_query(&self, query: &str) {
673-
self.conn.with_mut(|conn| {
674-
conn.write_messages([Query { query: query }]);
675-
676-
loop {
677-
match conn.read_message() {
678-
ReadyForQuery { .. } => break,
679-
ErrorResponse { fields } =>
680-
fail!("Error: {}",
681-
PostgresDbError::new(fields).to_str()),
682-
_ => {}
683-
}
684-
}
685-
})
692+
fn quick_query(&self, query: &str) -> ~[~[Option<~str>]] {
693+
self.conn.with_mut(|conn| conn.quick_query(query))
686694
}
687695

688696
fn wait_for_ready(&self) {

0 commit comments

Comments
 (0)