This repository has been archived by the owner on May 10, 2020. It is now read-only.
forked from prisma/tiberius
-
Notifications
You must be signed in to change notification settings - Fork 2
Add BigChar support and iterator for columns #73
Open
Licenser
wants to merge
1
commit into
steffengy:master
Choose a base branch
from
Licenser:fixes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
//! Query results and resultsets | ||
use std::marker::PhantomData; | ||
use futures::{Async, Future, Poll, Sink, Stream}; | ||
use futures::sync::oneshot; | ||
use futures::{Async, Future, Poll, Sink, Stream}; | ||
use futures_state_stream::{StateStream, StreamEvent}; | ||
use tokens::{DoneStatus, TdsResponseToken, TokenRow}; | ||
use types::FromColumnData; | ||
use {BoxableIo, SqlConnection, StmtResult, Error, Result}; | ||
use std::marker::PhantomData; | ||
use std::{iter, slice}; | ||
use tokens::{DoneStatus, MetaDataColumn, TdsResponseToken, TokenRow}; | ||
use types::{ColumnData, FromColumnData}; | ||
use {BoxableIo, Error, Result, SqlConnection, StmtResult}; | ||
|
||
/// A query result consists of multiple query streams (amount of executed queries = amount of results) | ||
#[must_use = "streams do nothing unless polled"] | ||
|
@@ -94,9 +95,9 @@ impl<I: BoxableIo, R: StmtResult<I>> StateStream for ResultSetStream<I, R> { | |
let conn = self.conn.take().unwrap(); | ||
let (sender, receiver) = oneshot::channel(); | ||
self.receiver = Some(receiver); | ||
return Ok(Async::Ready( | ||
StreamEvent::Next(R::from_connection(conn, sender)), | ||
)); | ||
return Ok(Async::Ready(StreamEvent::Next(R::from_connection( | ||
conn, sender, | ||
)))); | ||
} | ||
} | ||
let conn = self.conn.take().unwrap(); | ||
|
@@ -107,17 +108,16 @@ impl<I: BoxableIo, R: StmtResult<I>> StateStream for ResultSetStream<I, R> { | |
/// A stream of [`Rows`](struct.QueryRow.html) returned for the current resultset | ||
#[must_use = "streams do nothing unless polled"] | ||
pub struct QueryStream<I: BoxableIo> { | ||
inner: ResultInner<I> | ||
inner: ResultInner<I>, | ||
} | ||
|
||
struct ResultInner<I: BoxableIo> ( | ||
Option<(SqlConnection<I>, oneshot::Sender<SqlConnection<I>>)>, | ||
); | ||
struct ResultInner<I: BoxableIo>(Option<(SqlConnection<I>, oneshot::Sender<SqlConnection<I>>)>); | ||
|
||
impl<I: BoxableIo> ResultInner<I> { | ||
fn send_back(&mut self) -> Result<bool> { | ||
if let Some((conn, ret_conn)) = self.0.take() { | ||
ret_conn.send(conn) | ||
ret_conn | ||
.send(conn) | ||
.map_err(|_| Error::Canceled) | ||
.map(|_| true) | ||
} else { | ||
|
@@ -168,7 +168,10 @@ impl<'a, I: BoxableIo> Stream for QueryStream<I> { | |
impl<'a, I: BoxableIo> StmtResult<I> for QueryStream<I> { | ||
type Result = QueryStream<I>; | ||
|
||
fn from_connection(conn: SqlConnection<I>, ret_conn: oneshot::Sender<SqlConnection<I>>) -> QueryStream<I> { | ||
fn from_connection( | ||
conn: SqlConnection<I>, | ||
ret_conn: oneshot::Sender<SqlConnection<I>>, | ||
) -> QueryStream<I> { | ||
QueryStream { | ||
inner: ResultInner(Some((conn, ret_conn))), | ||
} | ||
|
@@ -203,9 +206,9 @@ impl<I: BoxableIo> Future for ExecFuture<I> { | |
self.single_token = false; | ||
false | ||
} | ||
TdsResponseToken::Done(ref done) | | ||
TdsResponseToken::DoneInProc(ref done) | | ||
TdsResponseToken::DoneProc(ref done) => { | ||
TdsResponseToken::Done(ref done) | ||
| TdsResponseToken::DoneInProc(ref done) | ||
| TdsResponseToken::DoneProc(ref done) => { | ||
let final_token = match token { | ||
TdsResponseToken::Done(_) | TdsResponseToken::DoneProc(_) => true, | ||
_ => false, | ||
|
@@ -216,7 +219,8 @@ impl<I: BoxableIo> Future for ExecFuture<I> { | |
} | ||
// if this is the final done token, we need to reinject it for result set stream to handle it | ||
// (as in querying, if self.single_token it already was reinjected and would result in an infinite cycle) | ||
let reinject = !done.status.contains(DoneStatus::MORE) && !self.single_token | ||
let reinject = !done.status.contains(DoneStatus::MORE) | ||
&& !self.single_token | ||
&& final_token; | ||
if !reinject { | ||
break; | ||
|
@@ -252,7 +256,7 @@ impl<I: BoxableIo> StmtResult<I> for ExecFuture<I> { | |
|
||
/// A row in one resultset of a query | ||
#[derive(Debug)] | ||
pub struct QueryRow(TokenRow); | ||
pub struct QueryRow(pub TokenRow); | ||
|
||
/// Anything that can be used as an index to get a specific row. | ||
/// | ||
|
@@ -286,10 +290,7 @@ impl QueryRow { | |
} | ||
|
||
/// Attempt to get a column's value for a given column index | ||
pub fn try_get<'a, I: QueryIdx, R: FromColumnData<'a>>( | ||
&'a self, | ||
idx: I, | ||
) -> Result<Option<R>> { | ||
pub fn try_get<'a, I: QueryIdx, R: FromColumnData<'a>>(&'a self, idx: I) -> Result<Option<R>> { | ||
let idx = match idx.to_idx(self) { | ||
Some(x) => x, | ||
None => return Ok(None), | ||
|
@@ -298,6 +299,11 @@ impl QueryRow { | |
let col_data = &self.0.columns[idx]; | ||
R::from_column_data(col_data).map(Some) | ||
} | ||
pub fn iter( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This exposes MetaDataColumn, which is an implementation specific representation. |
||
&self, | ||
) -> iter::Zip<slice::Iter<'_, MetaDataColumn>, slice::Iter<'_, ColumnData<'_>>> { | ||
self.0.meta.columns.iter().zip(self.0.columns.iter()) | ||
} | ||
|
||
/// Retrieve a column's value for a given column index | ||
/// | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks BC and also I'd like this not exposed since it's protocol internals.
(e.g. in new TDS versions row might change)