Skip to content

Conversation

@mvzink
Copy link
Contributor

@mvzink mvzink commented Jan 23, 2026

Parse MySQL-style [DEFAULT] CHARACTER SET and [DEFAULT] COLLATE options in CREATE DATABASE statements. This adds two new fields to CreateDatabase: default_charset and default_collation.

Supports the following syntax variants:

  • DEFAULT CHARACTER SET [=] charset_name
  • CHARACTER SET [=] charset_name
  • DEFAULT CHARSET [=] charset_name
  • CHARSET [=] charset_name
  • DEFAULT COLLATE [=] collation_name
  • COLLATE [=] collation_name

Parse MySQL-style [DEFAULT] CHARACTER SET and [DEFAULT] COLLATE options
in CREATE DATABASE statements. This adds two new fields to
CreateDatabase: default_charset and default_collation.

Supports the following syntax variants:
- DEFAULT CHARACTER SET [=] charset_name
- CHARACTER SET [=] charset_name  
- DEFAULT CHARSET [=] charset_name
- CHARSET [=] charset_name
- DEFAULT COLLATE [=] collation_name
- COLLATE [=] collation_name
pub storage_serialization_policy: Option<StorageSerializationPolicy>,
/// Optional comment attached to the database.
pub comment: Option<String>,
/// Optional default character set (MySQL).
Copy link
Contributor

Choose a reason for hiding this comment

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

can we include a link to the mysql documentation for the doc comments?

Comment on lines +5320 to +5323
self.expect_token(&Token::Eq).ok();
default_charset = Some(self.parse_identifier()?.value);
} else if self.parse_keyword(Keyword::COLLATE) {
self.expect_token(&Token::Eq).ok();
Copy link
Contributor

Choose a reason for hiding this comment

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

can we handle the errors in the calls to expect_token?

None
};

// Parse MySQL-style [DEFAULT] CHARACTER SET and [DEFAULT] COLLATE options
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we move the default_charset and default_collation closer here to the loop? (misread for a second wondering if the values were being previously set elsewhere before the loop)

// Parse MySQL-style [DEFAULT] CHARACTER SET and [DEFAULT] COLLATE options
loop {
let has_default = self.parse_keyword(Keyword::DEFAULT);
if self.parse_keywords(&[Keyword::CHARACTER, Keyword::SET])
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if self.parse_keywords(&[Keyword::CHARACTER, Keyword::SET])
if default_charset.is_none() && self.parse_keywords(&[Keyword::CHARACTER, Keyword::SET])

{
self.expect_token(&Token::Eq).ok();
default_charset = Some(self.parse_identifier()?.value);
} else if self.parse_keyword(Keyword::COLLATE) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
} else if self.parse_keyword(Keyword::COLLATE) {
} else if default_collation.is_none() && self.parse_keyword(Keyword::COLLATE) {

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.

2 participants