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

Can't disable prepared statements when connecting to a Starrock DB #3205

Open
presedo93 opened this issue Apr 18, 2024 · 7 comments
Open

Can't disable prepared statements when connecting to a Starrock DB #3205

presedo93 opened this issue Apr 18, 2024 · 7 comments
Labels

Comments

@presedo93
Copy link

Bug Description

I'm trying to use sqlx to connect to a StarrocksDB. Checking the docs/forums, it doesn't support prepared-cache but it mentions that most MySQL clients should be able to disable that feature. I set statement_cache_capacity to 0 as the docs mention but I still get this error when trying to connect:

Error: Database(MySqlDatabaseError { code: Some("HY000"), number: 1064, message: "Getting analyzing error. Detail message: Set statement only support constant expr.." })

Can it be that setting statement_cache_capacity to 0 does not disable the prepared-cache?

Thanks!

Minimal Reproduction

use sqlx::mysql::MySqlConnectOptions;
use sqlx::ConnectOptions;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let _pool = MySqlConnectOptions::new()
        .host("127.0.0.1")
        .username("root")
        .database("my_db")
        .port(9030)
        .statement_cache_capacity(0)
        .connect()
        .await?;

    Ok(())
}

Info

  • SQLx version: 0.7.4
  • SQLx features enabled: ["runtime-tokio", "mysql"]
  • Database server and version: StarrocksDB (MySQL)
  • Operating system: macOS
  • rustc --version: 1.77.2
@presedo93 presedo93 added the bug label Apr 18, 2024
@kiwilab-cn
Copy link

I meet the same issues, anyone could fix it?

@presedo93
Copy link
Author

I gave it several tries but couldn't make it work... only way I've found to connect to StarrocksDB on Rust is using the mysql crate...

@groobyming

This comment was marked as spam.

@groobyming
Copy link

I gave it several tries but couldn't make it work... only way I've found to connect to StarrocksDB on Rust is using the mysql crate...

@presedo93 I modified the source code to allow a simple query and solve the problem, but the code is ugly, It would be best if the official could support this switch feature.

@presedo93
Copy link
Author

so cool!! I couldn't resist and give a try to your fork with my StarRocks instance... and I can connect! When running queries, I'm getting errors on the Protocol. It seems to be expecting 0xfe (EOF_Packet) but finds 0x3. But, at least, now I'm able to connect hehe.

Do you think you could do a PR on the repo? I could help you to give it visibility and have that feature :)

Thanks for the effort!

@groobyming
Copy link

so cool!! I couldn't resist and give a try to your fork with my StarRocks instance... and I can connect! When running queries, I'm getting errors on the Protocol. It seems to be expecting 0xfe (EOF_Packet) but finds 0x3. But, at least, now I'm able to connect hehe.

Do you think you could do a PR on the repo? I could help you to give it visibility and have that feature :)

Thanks for the effort!

I will try to optimize the code first and then submit a PR

@groobyming
Copy link

groobyming commented Jun 11, 2024

so cool!! I couldn't resist and give a try to your fork with my StarRocks instance... and I can connect! When running queries, I'm getting errors on the Protocol. It seems to be expecting 0xfe (EOF_Packet) but finds 0x3. But, at least, now I'm able to connect hehe.
Do you think you could do a PR on the repo? I could help you to give it visibility and have that feature :)
Thanks for the effort!

I will try to optimize the code first and then submit a PR

@presedo93 Hi prededo93, the error: 'Error: Database(MySqlDatabaseError { code: Some("HY000"), number: 1064, message: "Getting analyzing error. Detail message: Set statement only support constant expr.." })"

is caused by StarRocks not supporting the following: "Set statement with Select statement". For example: "Set sql_mode=(SELECT CONCAT(@@sql_mode, ',PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION'))"

The problem code is as follows
https://github.com/launchbadge/sqlx/blob/main/sqlx-mysql/src/connection/executor.rs
image

You can modify the code as follows: dive into two statements.
image
But I'm not sure if Starrocks supports "Prepared Statement" because SQLx only supports prepared statements for execution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants