use tdsql::{Client, Command, Config};
#[tokio::main]
async fn main() -> tdsql::Result<()> {
let mut client = Client::connect(
&Config::new()
.host("localhost")
.database("master")
.auth("sa", "YourStrong!Passw0rd")
.trust_cert(),
)
.await?;
let cmd = Command::query("SELECT @id AS id, @status AS status")
.param("id", 1001)
.param("status", "PAID");
let ds = client.query_dataset(&cmd).await?;
println!(
"id={} status={}",
ds[0][0].get::<i32, _>("id"),
ds[0][0].get::<String, _>("status")
);
client
.batch(
"IF OBJECT_ID('dbo.sp_tdsql_demo', 'P') IS NOT NULL \
DROP PROCEDURE dbo.sp_tdsql_demo",
)
.await?;
client
.batch(
"CREATE PROCEDURE dbo.sp_tdsql_demo @x INT AS BEGIN \
SELECT @x AS given; SELECT @x * 2 AS doubled; END",
)
.await?;
let cmd = Command::stored_procedure("dbo.sp_tdsql_demo").param("x", 21);
let ds = client.query_dataset(&cmd).await?;
println!("result sets: {}", ds.len());
println!(" given: {}", ds[0][0].get::<i32, _>("given"));
println!(" doubled: {}", ds[1][0].get::<i32, _>("doubled"));
client.batch("DROP PROCEDURE dbo.sp_tdsql_demo").await?;
client.close().await
}