Issues with Date datatype in bulk insert when trying to insert a record in a target table with the same schema
I'm migrating a table from one database to another using Tiberius. The schemas of the source and target tables are almost identical, with the only difference being that the source table has an IDENTITY column (ID), while the target table has an INT column.
I have a date conversion function that converts a tiberius::time::time::Date to a tiberius::time::Date. The conversion seems to work fine, as I don't encounter any errors when pushing the data into the TokenRow. However, when I execute the following line:
let res = req.finalize().await?;
info!("######## TOTAL: {}", res.total());
I get the following error:
[2025-01-23T18:37:45Z ERROR tiberius::tds::stream::token] Invalid column type from bcp client for colid 18. code=4816
If I remove the Date column from the source table, the error does not occur.
Here is the relevant code for the date conversion:
...
tiberius::ColumnType::Daten => {
let val = row.get::<tiberius::time::time::Date, _>(index);
match val {
Some(originaldate) => {
info!("oooooooooooooo date before: {}", originaldate);
let newdate = convert_date(originaldate);
info!("oooooooooooooo date converted: {:?}", newdate);
ColumnData::Date(Some(newdate))
}
None => ColumnData::Date(None), // Handle NULL values
}
}
...
And the date conversion function:
fn convert_date(olddate: tiberius::time::time::Date) -> tiberius::time::Date {
// Create a NaiveDate for January 1, year 1
let epoch = NaiveDate::from_ymd_opt(1, 1, 1).expect("Invalid epoch date");
let date = NaiveDate::from_ymd_opt(
olddate.year(),
olddate.month() as u32,
olddate.day() as u32,
).expect("Invalid date");
let days_since_epoch = date.signed_duration_since(epoch).num_days() as u32;
tiberius::time::Date::new(days_since_epoch)
}
Questions:
- What could be causing the Invalid column type from bcp client for colid 18 error?
- Is there an issue with the date conversion logic that might be causing this error?
- Are there any known issues with Tiberius and BCP client compatibility for date columns?
Any help or insights would be greatly appreciated!
@hugomf I think I have the same problem - https://github.com/prisma/tiberius/pull/346
Maybe you can try with - https://github.com/setenum/tiberius/tree/fix/bulk-date-token-error
@hugomf I think I have the same problem - #346
Maybe you can try with - https://github.com/setenum/tiberius/tree/fix/bulk-date-token-error
wow!!! that was fast response, I will take a look thank you!
Having the same issue, appears Date type doesn't convert properly. Any chance of getting some more eyes on ? Be nice to get a fix in
Error im getting:
message: "Invalid column type from bcp client for colid 2."
I can confirm that I have this issue too. I get
Invalid column type from bcp client for colid x
when the date is not in the final column, and the following error when it is
Token error: 'While reading current row from host, a premature end-of-message was encountered--an incoming data stream was interrupted when the server expected to see more data. The host program may have terminated. Ensure that you are using a supported client application programming interface (API).' on server xxxxxxxxx executing on line 1 (code: 4804, state: 1, class: 17)
I have a similar issue that I can't bulk insert a SMALLDATETIME column with similar error.