I am pretty new to rust.
I need to source a external SQL file from within rust; here is what I tried, Please refer to the Comment and line break and the error I have mentioned:
async fn test_db(
user_name: &str,
password: &str,
database: &str,
authorization_script_path: &str,
) -> std::result::Result<(), Box<dyn std::error::Error>> {
let connection_string = format!("mysql://{}:{}@localhost:3306", user_name,
password);
let connection_url: &str = &connection_string;
let pool = Pool::new(connection_url)?;
let mut connection = pool.get_conn()?;
let create_db_query = format!("CREATE DATABASE IF NOT EXISTS {}", database);
let result_create = connection.query_drop(create_db_query);
println!("{:?}", result_create.unwrap());
let use_db_query = format!("USE {}", database);
let _result_query = connection.query_drop(use_db_query);
-------------------------------------------------------------------------------------------
// here below I am trying to source a file using the `source` command
let authoriztion_source_script_query = format!("source {}", &authorization_script_path);
let _result_authorization_script = connection.query_drop(authoriztion_source_script_query);
-------------------------------------------------------------------------------------------
return Ok(());
}
I use the follwing the following command to run my program
cargo run -- -u root -p super_secret_password -d customera_authorization -A "C:\Users\<some_user_name>\Downloads\<Some_folder>\authorization.sql"
The -u
flag is to pass a username for the mysql server.
The -p
flag is to pass a password for the mysql server.
The -d
flag is to pass a name of a database to be created
The -A
flag is to pass a path to the external sql file to be sourced.
when I check for the new database, I found that the DB has been created with the proper name but the SQL file is not sourced
The error I am getting is as follows:
MySqlError { ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'source C:\Users\<some_user_name>\Downloads\<Some_folder>\authorization.sql' at line 1 } Success
Note: The External SQL file has CREATE TABLE ....
commands
I just want to source the external SQL file in one go.
Please guide me if possible for fixing this issue
Any help would be appreciated!!!
Thank you!