Skip to content
This repository has been archived by the owner on May 10, 2020. It is now read-only.

Fix buffer empty when reading numeric types #102

Merged
merged 2 commits into from
Aug 14, 2019

Conversation

danylaporte
Copy link
Contributor

Fix invalid protocol token crash caused by the following request:

use futures::Future;
use futures_state_stream::StateStream;
use tiberius::{
    ty::{Guid, Numeric},
    SqlConnection,
};
use tokio::executor::current_thread;

fn main() {
    // 1: Same as in the example above
    let conn_str = "server=tcp:localhost\\SQL2017;database=master;integratedsecurity=sspi;trustservercertificate=true";
    let mut i = 0;

    let future = SqlConnection::connect(conn_str).and_then(|conn| {
        conn.simple_query(
            r#"
            with cte as (
	SELECT CAST(999999999.99 as DECIMAL(28, 12)) c
	UNION ALL
	SELECT  CAST(999999999.99 as DECIMAL(28, 12)) c FROM cte
)
SELECT TOP 50 * FROM cte
UNION ALL 
SELECT TOP 50 * FROM cte
UNION ALL 
SELECT TOP 50 * FROM cte
UNION ALL 
SELECT TOP 50 * FROM cte
UNION ALL 
SELECT TOP 50 * FROM cte
UNION ALL 
SELECT TOP 50 * FROM cte
UNION ALL 
SELECT TOP 50 * FROM cte
UNION ALL 
SELECT TOP 50 * FROM cte"#,
        )
        .for_each(|r| {
            let n = r.get::<_, Numeric>(0);
            println!("{}: {:?}: {}", i, n, n.scale());

            i += 1;
            Ok(())
        })
    });

    current_thread::block_on_all(future).unwrap();
}

@steffengy
Copy link
Owner

Thanks, that seems right.
Could you add this as test aswell?

@danylaporte
Copy link
Contributor Author

Test added! :)

@steffengy steffengy merged commit 88741b5 into steffengy:master Aug 14, 2019
agalakhov referenced this pull request in snapview/tiberius Oct 17, 2019
* Fix buffer empty when reading numeric types

* add test numeric on many records
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants