Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion crates/dataprof-db/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ impl ConnectionInfo {
},
password: url.password().map(|s| s.to_string()),
database: if url.path().len() > 1 {
Some(url.path().trim_start_matches('/').to_string())
Some(if url.scheme() == "sqlite" {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Fixes #839 will close the issue, but sqlite://rel.sqlite still fails with No database path specified (CodeRabbit's note). Either cover it here or switch to Part of #839.

url.path().to_string()
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the default config (load_credentials_from_env: true, which Python's analyze_database and the facade's .connection_string() use), the string is rebuilt by to_original_string(), which prepends / to database. That now gives sqlite:////C:/...: on Windows sqlx receives //C:/... (a UNC path) and fails with unable to open database file, where master opened the file. On Linux it works only because // resolves to /.

SQLite has no credentials to merge, so skipping the credential step for the sqlite scheme in apply_environment_configuration would avoid the round trip.

} else {
url.path().trim_start_matches('/').to_string()
})
} else {
None
},
Expand Down Expand Up @@ -233,6 +237,7 @@ mod tests {

assert_eq!(info.scheme, "sqlite");
assert_eq!(info.database_type(), "sqlite");
assert_eq!(info.database, Some("/path/to/db.sqlite".to_string()));
}

#[test]
Expand Down
18 changes: 18 additions & 0 deletions crates/dataprof-db/tests/column_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,21 @@ async fn the_order_is_the_same_on_every_run() {

connector.disconnect().await.unwrap();
}

#[tokio::test]
async fn sqlite_absolute_url_opens_existing_database() {
let (_dir, db_path) = fixture(1).await;

let path = db_path.replace('\\', "/");
let url = if cfg!(windows) {
format!("sqlite:///{}", path)
} else {
format!("sqlite://{}", path)
};
let mut connector = connect(&url).await;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

connect sets load_credentials_from_env: false, so this test skips the path users hit. Could it also go through create_connector with the default config?

let columns = connector.profile_query("SELECT * FROM t").await.unwrap();
assert_eq!(names(&columns), DECLARED_ORDER);

connector.disconnect().await.unwrap();
}
Loading