Skip to content

Conversation

@moulid-adan
Copy link
Contributor

@moulid-adan moulid-adan commented Sep 15, 2025

  • database name field
  • add attach if no exist for database string.
  • attach db file, in mem, and motherduck

@moulid-adan moulid-adan changed the title adding a database field adding a database field INFRA-606 Sep 15, 2025
return &ConfigError{"Path is empty"}
}
// if db has no quotes add them
if !((strings.HasPrefix(db, "'") && strings.HasSuffix(db, "'")) || (strings.HasPrefix(db, "\"") && strings.HasSuffix(db, "\""))) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think this condition should be removed.
The db path should always be escaped for single quotes. right now a user input like '/some/pa'th.ddb' will not escape the inner ' and yield an invalid attach query.
But i don't even think the outer quotes should be treated specially, as in i don't think the user should try to quote their paths at all.

Copy link
Contributor Author

@moulid-adan moulid-adan Sep 18, 2025

Choose a reason for hiding this comment

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

motherduck database can not, I will keep quoting if a prefix with md: has no quotes.

logger=plugin.motherduck-duckdb-datasource t=2025-09-18T16:11:23.520295756Z level=info msg="ATTACH IF NOT EXISTS md:sample_data;"

logger=plugin.motherduck-duckdb-datasource t=2025-09-18T16:11:23.521975964Z level=error msg="error querying the database: Parser Error: syntax error at or near "md""

Comment on lines 91 to 99
if strings.TrimSpace(config.Path) != "" {
db := strings.TrimSpace(config.Path)
// if db has no quotes add them
if !strings.HasPrefix(db, "'") && !strings.HasSuffix(db, "'") && strings.HasPrefix(db, "md:") {
db = "'" + db + "'"
}
bootQueries = append(bootQueries, "ATTACH IF NOT EXISTS "+db+";")
backend.Logger.Info("ATTACH IF NOT EXISTS " + db + ";")
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should only be run if the db path is md:...

Copy link
Collaborator

Choose a reason for hiding this comment

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

when the db path is 'md:sample_data',
then duckdb.NewConnector(path, func(execer driver.ExecerContext) error { will receive path = "'md:sample_data'";

Copy link
Collaborator

Choose a reason for hiding this comment

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

let's keep strings.ReplaceAll(db, "'", "''")

@moulid-adan moulid-adan merged commit 4c27ecd into main Sep 25, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants