Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bulk_insert does not support Money MS SQL data type #358

Open
KuroiKenjin opened this issue Oct 1, 2024 · 0 comments
Open

bulk_insert does not support Money MS SQL data type #358

KuroiKenjin opened this issue Oct 1, 2024 · 0 comments

Comments

@KuroiKenjin
Copy link

I was trying out the bulk insert, but ran into an issue with inserting into an MS SQL table with a money type. I didn't see any support for it in ColumnType.

The error:

thread 'main' panicked at src/main.rs:26:25:
called `Result::unwrap()` on an `Err` value: BulkInput("invalid data type, expecting Some(FixedLen(Money)) but found F64(Some(3.5))")
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: process didn't exit successfully: `target\debug\bulk-test.exe` (exit code: 101)

Table:

create table dbo.Bulk2 (
	ID	int			not null		identity(1,1),
	SVal	varchar(50)		not null,
	Cash	money			not null
)

Code:

use tiberius::{Client, Config, IntoRow};
use tokio::net::TcpStream;

use tokio_util::compat::TokioAsyncWriteCompatExt;

#[tokio::main]
async fn main() {
    let config = Config::from_ado_string("integrated security=SSPI;data source=zora;initial catalog=DevDB;TrustServerCertificate=true;").unwrap();
    let tcp =  TcpStream::connect(config.get_addr()).await.unwrap();
    tcp.set_nodelay(true).unwrap();

    let mut client = Client::connect(config, tcp.compat_write()).await.unwrap();
    let mut blr = client.bulk_insert("dbo.Bulk2").await.unwrap();

    let mut row = ("Funky", 3.50).into_row();
    blr.send(row).await.unwrap();

    row = ("Monkey", 7.00).into_row();
    blr.send(row).await.unwrap();

    row = ("Spanky", 10.50).into_row();
    blr.send(row).await.unwrap();


    row = ("Manky", 14.00).into_row();
    blr.send(row).await.unwrap();

    let res = blr.finalize().await.unwrap();
    println!("{}", res.total());

    client.close().await.unwrap();
     
}

I also tried this code:

use tiberius::{Client, ColumnData, Config,  TokenRow};
use tokio::net::TcpStream;

use tokio_util::compat::TokioAsyncWriteCompatExt;
use std::borrow::Cow;


#[tokio::main]
async fn main() {
    let config = Config::from_ado_string("integrated security=SSPI;data source=zora;initial catalog=DevDB;TrustServerCertificate=true;").unwrap();
    let tcp =  TcpStream::connect(config.get_addr()).await.unwrap();
    tcp.set_nodelay(true).unwrap();

    let mut client = Client::connect(config, tcp.compat_write()).await.unwrap();
    let mut blr = client.bulk_insert("dbo.Bulk2").await.unwrap();

    let mut row = TokenRow::new();
    row.push(ColumnData::String(Some(Cow::from("Funky"))));
    row.push (ColumnData::F64(Some(3.50)));
    blr.send(row.clone()).await.unwrap();

    row.clear();
    row.push(ColumnData::String(Some(Cow::from("Monkey"))));
    row.push (ColumnData::F64(Some(7.00)));
    blr.send(row.clone()).await.unwrap();

    row.clear();
    row.push(ColumnData::String(Some(Cow::from("Spanky"))));
    row.push (ColumnData::F64(Some(10.50)));
    blr.send(row.clone()).await.unwrap();

    row.clear();
    row.push(ColumnData::String(Some(Cow::from("Manky"))));
    row.push (ColumnData::F64(Some(14.00)));

    blr.send(row).await.unwrap();

    let res = blr.finalize().await.unwrap();
    println!("{}", res.total());

    client.close().await.unwrap();
     
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant