Skip to content

Commit

Permalink
fix: create database with quoted db name in all dialect
Browse files Browse the repository at this point in the history
  • Loading branch information
taozhi8833998 committed May 27, 2024
1 parent a8ea6b9 commit b2f4281
Show file tree
Hide file tree
Showing 16 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion pegjs/athena.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ create_db_stmt
= a:KW_CREATE __
k:(KW_DATABASE / KW_SCHEME) __
ife:if_not_exists_stmt? __
t:ident_name __
t:ident_without_kw_type __
c:create_db_definition? {
return {
tableList: Array.from(tableList),
Expand Down
2 changes: 1 addition & 1 deletion pegjs/bigquery.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ create_db_stmt
= a:KW_CREATE __
k:(KW_DATABASE / KW_SCHEMA) __
ife:if_not_exists_stmt? __
t:ident_name __
t:ident_without_kw_type __
c:create_db_definition? {
return {
tableList: Array.from(tableList),
Expand Down
2 changes: 1 addition & 1 deletion pegjs/db2.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ create_db_stmt
= a:KW_CREATE __
k:(KW_DATABASE / KW_SCHEME) __
ife:if_not_exists_stmt? __
t:ident_name __
t:ident_without_kw_type __
c:create_db_definition? {
return {
tableList: Array.from(tableList),
Expand Down
2 changes: 1 addition & 1 deletion pegjs/flinksql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ create_db_stmt
= a:KW_CREATE __
k:(KW_DATABASE / KW_SCHEME) __
ife:if_not_exists_stmt? __
t:ident_name __
t:ident_without_kw_type __
c:create_db_definition? {
return {
tableList: Array.from(tableList),
Expand Down
2 changes: 1 addition & 1 deletion pegjs/hive.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ create_db_stmt
= a:KW_CREATE __
k:(KW_DATABASE / KW_SCHEME) __
ife:if_not_exists_stmt? __
t:ident_name __
t:ident_without_kw_type __
c:create_db_definition? {
return {
tableList: Array.from(tableList),
Expand Down
2 changes: 1 addition & 1 deletion pegjs/mariadb.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ create_db_stmt
= a:KW_CREATE __
k:(KW_DATABASE / KW_SCHEMA) __
ife:if_not_exists_stmt? __
t:ident_name __
t:ident_without_kw_type __
c:create_db_definition? {
return {
tableList: Array.from(tableList),
Expand Down
2 changes: 1 addition & 1 deletion pegjs/mysql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ create_db_stmt
= a:KW_CREATE __
k:(KW_DATABASE / KW_SCHEMA) __
ife:if_not_exists_stmt? __
t:ident_name __
t:ident_without_kw_type __
c:create_db_definition? {
return {
tableList: Array.from(tableList),
Expand Down
4 changes: 2 additions & 2 deletions pegjs/noql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -359,14 +359,14 @@ create_db_stmt
= a:KW_CREATE __
k:(KW_DATABASE / KW_SCHEMA) __
ife:if_not_exists_stmt? __
t:ident_name __
t:ident_without_kw_type __
c:create_db_definition? {
/*
export type create_db_stmt = {
type: 'create',
keyword: 'database' | 'schema',
if_not_exists?: 'if not exists',
database: string,
database: ident_without_kw_type,
create_definitions?: create_db_definition
}
=> AstStatement<create_db_stmt>
Expand Down
4 changes: 2 additions & 2 deletions pegjs/postgresql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -372,14 +372,14 @@ create_db_stmt
= a:KW_CREATE __
k:(KW_DATABASE / KW_SCHEMA) __
ife:if_not_exists_stmt? __
t:ident_name __
t:ident_without_kw_type __
c:create_db_definition? {
/*
export type create_db_stmt_t = {
type: 'create',
keyword: 'database' | 'schema',
if_not_exists?: 'if not exists',
database: string,
database: ident_without_kw_type,
create_definitions?: create_db_definition
}
=> AstStatement<create_db_stmt_t>
Expand Down
4 changes: 2 additions & 2 deletions pegjs/redshift.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -369,14 +369,14 @@ create_db_stmt
= a:KW_CREATE __
k:(KW_DATABASE / KW_SCHEMA) __
ife:if_not_exists_stmt? __
t:ident_name __
t:ident_without_kw_type __
c:create_db_definition? {
/*
export type create_db_stmt = {
type: 'create',
keyword: 'database' | 'schema',
if_not_exists?: 'if not exists',
database: string,
database: ident_without_kw_type,
create_definitions?: create_db_definition
}
=> AstStatement<create_db_stmt>
Expand Down
4 changes: 2 additions & 2 deletions pegjs/snowflake.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,14 @@ create_db_stmt
= a:KW_CREATE __
k:(KW_DATABASE / KW_SCHEMA) __
ife:if_not_exists_stmt? __
t:ident_name __
t:ident_without_kw_type __
c:create_db_definition? {
/*
export type create_db_stmt = {
type: 'create',
keyword: 'database' | 'schema',
if_not_exists?: 'if not exists',
database: string,
database: ident_without_kw_type,
create_definitions?: create_db_definition
}
=> AstStatement<create_db_stmt>
Expand Down
2 changes: 1 addition & 1 deletion pegjs/sqlite.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ create_db_stmt
= a:KW_CREATE __
k:(KW_DATABASE / KW_SCHEME) __
ife:if_not_exists_stmt? __
t:ident_name __
t:ident_without_kw_type __
c:create_db_definition? {
return {
tableList: Array.from(tableList),
Expand Down
2 changes: 1 addition & 1 deletion pegjs/transactsql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ create_db_stmt
= a:KW_CREATE __
k:(KW_DATABASE / KW_SCHEME) __
ife:if_not_exists_stmt? __
t:ident_name __
t:ident_without_kw_type __
c:create_db_definition? {
return {
tableList: Array.from(tableList),
Expand Down
4 changes: 2 additions & 2 deletions pegjs/trino.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -380,14 +380,14 @@ create_db_stmt
= a:KW_CREATE __
k:(KW_DATABASE / KW_SCHEMA) __
ife:if_not_exists_stmt? __
t:ident_name __
t:ident_without_kw_type __
c:create_db_definition? {
/*
export type create_db_stmt = {
type: 'create',
keyword: 'database' | 'schema',
if_not_exists?: 'if not exists',
database: string,
database: ident_without_kw_type,
create_definitions?: create_db_definition
}
=> AstStatement<create_db_stmt>
Expand Down
2 changes: 1 addition & 1 deletion src/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ function createDatabaseToSQL(stmt) {
toUpper(type),
toUpper(keyword),
toUpper(ifNotExists),
columnIdentifierToSql(database),
literalToSQL(database),
]
if (createDefinition) sql.push(createDefinition.map(tableOptionToSQL).join(' '))
return sql.filter(hasVal).join(' ')
Expand Down
8 changes: 4 additions & 4 deletions test/create.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,10 +590,10 @@ describe('create', () => {

describe('create database', () => {
it('should support create database', () => {
expect(getParsedSql('CREATE DATABASE abc')).to.equal('CREATE DATABASE `abc`')
expect(getParsedSql('CREATE DATABASE IF NOT EXISTS abc')).to.equal('CREATE DATABASE IF NOT EXISTS `abc`')
expect(getParsedSql('CREATE DATABASE IF NOT EXISTS abc default CHARACTER SET utf8mb4')).to.equal('CREATE DATABASE IF NOT EXISTS `abc` DEFAULT CHARACTER SET utf8mb4')
expect(getParsedSql('CREATE DATABASE IF NOT EXISTS abc CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci')).to.equal('CREATE DATABASE IF NOT EXISTS `abc` CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci')
expect(getParsedSql('CREATE DATABASE abc')).to.equal('CREATE DATABASE abc')
expect(getParsedSql('CREATE DATABASE IF NOT EXISTS `abc`')).to.equal('CREATE DATABASE IF NOT EXISTS `abc`')
expect(getParsedSql('CREATE DATABASE IF NOT EXISTS abc default CHARACTER SET utf8mb4')).to.equal('CREATE DATABASE IF NOT EXISTS abc DEFAULT CHARACTER SET utf8mb4')
expect(getParsedSql('CREATE DATABASE IF NOT EXISTS `abc` CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci')).to.equal('CREATE DATABASE IF NOT EXISTS `abc` CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci')
})
})

Expand Down

0 comments on commit b2f4281

Please sign in to comment.