Skip to content

Commit 259fe11

Browse files
committed
Make read_rows a method on InnerConnection
1 parent 47b0c69 commit 259fe11

File tree

3 files changed

+48
-48
lines changed

3 files changed

+48
-48
lines changed

src/lib.rs

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,50 @@ impl InnerConnection {
665665
Ok((param_types, columns))
666666
}
667667

668+
fn read_rows(&mut self, buf: &mut VecDeque<Vec<Option<Vec<u8>>>>) -> Result<bool> {
669+
let more_rows;
670+
loop {
671+
match try!(self.read_message()) {
672+
EmptyQueryResponse | CommandComplete { .. } => {
673+
more_rows = false;
674+
break;
675+
}
676+
PortalSuspended => {
677+
more_rows = true;
678+
break;
679+
}
680+
DataRow { row } => buf.push_back(row),
681+
ErrorResponse { fields } => {
682+
try!(self.wait_for_ready());
683+
return DbError::new(fields);
684+
}
685+
CopyInResponse { .. } => {
686+
try!(self.write_messages(&[CopyFail {
687+
message: "COPY queries cannot be directly executed",
688+
},
689+
Sync]));
690+
}
691+
CopyOutResponse { .. } => {
692+
loop {
693+
match try!(self.read_message()) {
694+
ReadyForQuery { .. } => break,
695+
_ => {}
696+
}
697+
}
698+
return Err(Error::Io(std_io::Error::new(std_io::ErrorKind::InvalidInput,
699+
"COPY queries cannot be directly \
700+
executed")));
701+
}
702+
_ => {
703+
self.desynchronized = true;
704+
return Err(Error::Io(bad_response()));
705+
}
706+
}
707+
}
708+
try!(self.wait_for_ready());
709+
Ok(more_rows)
710+
}
711+
668712
fn make_stmt_name(&mut self) -> String {
669713
let stmt_name = format!("s{}", self.next_stmt_id);
670714
self.next_stmt_id += 1;
@@ -1358,50 +1402,6 @@ impl<'conn> Transaction<'conn> {
13581402
}
13591403
}
13601404

1361-
fn read_rows(conn: &mut InnerConnection, buf: &mut VecDeque<Vec<Option<Vec<u8>>>>) -> Result<bool> {
1362-
let more_rows;
1363-
loop {
1364-
match try!(conn.read_message()) {
1365-
EmptyQueryResponse | CommandComplete { .. } => {
1366-
more_rows = false;
1367-
break;
1368-
}
1369-
PortalSuspended => {
1370-
more_rows = true;
1371-
break;
1372-
}
1373-
DataRow { row } => buf.push_back(row),
1374-
ErrorResponse { fields } => {
1375-
try!(conn.wait_for_ready());
1376-
return DbError::new(fields);
1377-
}
1378-
CopyInResponse { .. } => {
1379-
try!(conn.write_messages(&[CopyFail {
1380-
message: "COPY queries cannot be directly executed",
1381-
},
1382-
Sync]));
1383-
}
1384-
CopyOutResponse { .. } => {
1385-
loop {
1386-
match try!(conn.read_message()) {
1387-
ReadyForQuery { .. } => break,
1388-
_ => {}
1389-
}
1390-
}
1391-
return Err(Error::Io(std_io::Error::new(std_io::ErrorKind::InvalidInput,
1392-
"COPY queries cannot be directly \
1393-
executed")));
1394-
}
1395-
_ => {
1396-
conn.desynchronized = true;
1397-
return Err(Error::Io(bad_response()));
1398-
}
1399-
}
1400-
}
1401-
try!(conn.wait_for_ready());
1402-
Ok(more_rows)
1403-
}
1404-
14051405
/// A trait allowing abstraction over connections and transactions
14061406
pub trait GenericConnection {
14071407
/// Like `Connection::execute`.

src/rows.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::fmt;
77
use std::ops::Deref;
88
use std::slice;
99

10-
use {Result, Transaction, read_rows, DbErrorNew, SessionInfoNew, RowsNew, LazyRowsNew,
10+
use {Result, Transaction, DbErrorNew, SessionInfoNew, RowsNew, LazyRowsNew,
1111
StatementInternals, WrongTypeNew};
1212
use types::{FromSql, SessionInfo, WrongType};
1313
use stmt::{Statement, Column};
@@ -345,7 +345,7 @@ impl<'trans, 'stmt> LazyRows<'trans, 'stmt> {
345345
max_rows: self.row_limit,
346346
},
347347
Sync]));
348-
read_rows(&mut conn, &mut self.data).map(|more_rows| self.more_rows = more_rows)
348+
conn.read_rows(&mut self.data).map(|more_rows| self.more_rows = more_rows)
349349
}
350350

351351
/// Returns a slice describing the columns of the `LazyRows`.

src/stmt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use message::BackendMessage::*;
1313
use message::WriteMessage;
1414
use util;
1515
use rows::{Rows, LazyRows};
16-
use {read_rows, bad_response, Connection, Transaction, StatementInternals, Result, RowsNew};
16+
use {bad_response, Connection, Transaction, StatementInternals, Result, RowsNew};
1717
use {InnerConnection, SessionInfoNew, LazyRowsNew, DbErrorNew, ColumnNew, StatementInfo};
1818

1919
/// A prepared statement.
@@ -129,7 +129,7 @@ impl<'conn> Statement<'conn> {
129129
try!(self.inner_execute(portal_name, row_limit, params));
130130

131131
let mut buf = VecDeque::new();
132-
let more_rows = try!(read_rows(&mut self.conn.conn.borrow_mut(), &mut buf));
132+
let more_rows = try!(self.conn.conn.borrow_mut().read_rows(&mut buf));
133133
Ok((buf, more_rows))
134134
}
135135

0 commit comments

Comments
 (0)