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

[bug] ERROR about SQL with Keyword key #489

Closed
andyli029 opened this issue Sep 19, 2019 · 4 comments
Closed

[bug] ERROR about SQL with Keyword key #489

andyli029 opened this issue Sep 19, 2019 · 4 comments
Assignees
Labels
P0 High priority
Milestone

Comments

@andyli029
Copy link
Contributor

radon

CREATE TABLE `wp_wpeditor_settings1` (
  `key` varchar(50) NOT NULL,
  `value` text NOT NULL,
  PRIMARY KEY (`key`)
) SINGLE

下发backend

create table `wp_wpeditor_settings1` (
	key varchar(50) not null,
	value text not null,
	primary key (key)
);

MySQL

mysql> create table `wp_wpeditor_settings1` (
    ->     key varchar(50) not null,
    ->     value text not null,
    ->     primary key (key)
    -> );
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar(50) not null,
    value text not null,
    primary key (key)
)' at line 2

log

2019/09/19 17:02:23.475748 frm.go:39:    	 [INFO] 	frm.write.data[db:two, table:wp_wpeditor_settings1, shardType:SINGLE]
 2019/09/19 17:02:23.477557 execute.go:109:    	 [INFO] 	spanner.execute.ddl.query:create table wp_wpeditor_settings1 (
	`key` varchar(50) not null,
	`value` text not null,
	primary key (`key`)
) engine=InnoDB
 2019/09/19 17:02:23.479855 connection.go:206:    	 [ERROR] 	conn[127.0.0.1:3000].execute[create table `two`.`wp_wpeditor_settings1` (
	key varchar(50) not null,
	value text not null,
	primary key (key)
) engine=InnoDB].len[128].error:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar(50) not null,
	value text not null,
	primary key (key)
) engine=InnoDB' at line 2 (errno 1064) (sqlstate 42000)
 2019/09/19 17:02:23.479908 txn.go:433:    	 [ERROR] 	txn.execute.on[127.0.0.1:3000].query[create table `two`.`wp_wpeditor_settings1` (
	key varchar(50) not null,
	value text not null,
	primary key (key)
) engine=InnoDB].error:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar(50) not null,
	value text not null,
	primary key (key)
) engine=InnoDB' at line 2 (errno 1064) (sqlstate 42000)
 2019/09/19 17:02:23.480032 frm.go:53:    	 [WARNING] 	frm.remove.file[two].for.[db:wp_wpeditor_settings1, table:bin/radon-meta/two/wp_wpeditor_settings1.json]
 2019/09/19 17:02:23.480699 query.go:115:    	 [ERROR] 	proxy.DDL[CREATE TABLE `wp_wpeditor_settings1` (   `key` varchar(50) NOT NULL,   `value` text NOT NULL,   PRIMARY KEY (`key`) ) SINGLE].from.session[1].error:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar(50) not null,
	value text not null,
	primary key (key)
) engine=InnoDB' at line 2 (errno 1064) (sqlstate 42000)
 2019/09/19 17:02:23.480746 server.go:244:    	 [ERROR] 	server.handle.query.from.session[1].error:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar(50) not null,
	value text not null,
	primary key (key)
) engine=InnoDB' at line 2 (errno 1064) (sqlstate 42000).query[CREATE TABLE `wp_wpeditor_settings1` (   `key` varchar(50) NOT NULL,   `value` text NOT NULL,   PRIMARY KEY (`key`) ) SINGLE]

@hustjieke
Copy link
Contributor

ACK.

@andyli029 andyli029 added the P0 High priority label Sep 19, 2019
@andyli029 andyli029 added this to the v1.0.8 milestone Sep 19, 2019
@hustjieke
Copy link
Contributor

Queto ` is removed here:
https://github.com/radondb/radon/blob/master/src/planner/ddl_plan.go#L140

	if node.Table.Qualifier.IsEmpty() {
		segTable = fmt.Sprintf("`%s`.`%s`", database, orgSegTable)
		rawQuery = strings.Replace(p.RawQuery, "`", "", -1)  <<<<---------
		// \b: https://www.regular-expressions.info/wordboundaries.html
		re, _ = regexp.Compile(fmt.Sprintf(`\b(%s)\b`, table))
	} else {
		segTable = fmt.Sprintf("`%s`.`%s`", database, orgSegTable)
		newTable := fmt.Sprintf("%s.%s", database, table)
		rawQuery = strings.Replace(p.RawQuery, "`", "", -1)<<<<---------
		re, _ = regexp.Compile(fmt.Sprintf(`\b(%s)\b`, newTable))
	}

@BohuTANG
Copy link
Contributor

Ping @andyli029

@andyli029
Copy link
Contributor Author

ack

hustjieke added a commit to hustjieke/radon that referenced this issue Sep 24, 2019
[summary]
When scatter sql to backends, the column name should be with quote '`'
e.g.: create table db.t(`key` int primary key, `col` int);
For the ddl with rename table, we remove all quotes '`' to uniform
standars.
e.g.: alter table t1 rename t2.

[test case]
src/planner/ddl_plan_test.go

[patch codecov]
src/planner/ddl_plan.go 95.1%
coverage: 89.8% of statements
hustjieke added a commit to hustjieke/radon that referenced this issue Sep 24, 2019
[summary]
When scatter sql to backends, the column name should be with quote '`'
e.g.: create table db.t(`key` int primary key, `col` int);
For the ddl with rename table, we remove all quotes '`' to uniform
standars.
e.g.: alter table t1 rename t2.

[test case]
src/planner/ddl_plan_test.go

[patch codecov]
src/planner/ddl_plan.go 95.1%
coverage: 89.8% of statements
hustjieke added a commit to hustjieke/radon that referenced this issue Sep 24, 2019
[summary]
When scatter sql to backends, the column name should be with quote '`'
e.g.: create table db.t(`key` int primary key, `col` int);
For the ddl with rename table, we remove all quotes '`' to uniform
standars.
e.g.: alter table t1 rename t2.

[test case]
src/planner/ddl_plan_test.go

[patch codecov]
src/planner/ddl_plan.go 95.1%
coverage: 89.8% of statements
hustjieke added a commit to hustjieke/radon that referenced this issue Sep 25, 2019
…db#489

[summary]
When scatter sql to backends, the column name should be with quote '`'
e.g.: create table db.t(`key` int primary key, `col` int);
For the ddl with rename table, we remove all quotes '`' to uniform
standars.
e.g.: alter table t1 rename t2.

[test case]
src/planner/ddl_plan_test.go

[patch codecov]
src/planner/ddl_plan.go 95.1%
coverage: 89.8% of statements
hustjieke added a commit to hustjieke/radon that referenced this issue Nov 22, 2019
…db#489

[summary]
When scatter sql to backends, the column name should be with quote '`'
e.g.: create table db.t(`key` int primary key, `col` int);
For the ddl with rename table, we remove all quotes '`' to uniform
standars.
e.g.: alter table t1 rename t2.

[test case]
src/planner/ddl_plan_test.go

[patch codecov]
src/planner/ddl_plan.go 95.1%
coverage: 89.8% of statements
hustjieke added a commit to hustjieke/radon that referenced this issue Dec 5, 2019
…db#489

[summary]
When scatter sql to backends, the column name should be with quote '`'
e.g.: create table db.t(`key` int primary key, `col` int);
For the ddl with rename table, we remove all quotes '`' to uniform
standars.
e.g.: alter table t1 rename t2.

[test case]
src/planner/ddl_plan_test.go
src/planner/ddl_test.go
src/executor/ddl_executor_test.go

[patch codecov]
src/planner/ddl_plan.go 95.1%
coverage: 89.8% of statements
@andyli029 andyli029 modified the milestones: v1.0.8, v1.0.9 Dec 6, 2019
hustjieke added a commit to hustjieke/radon that referenced this issue Dec 30, 2019
…db#489

[summary]
When scatter sql to backends, the column name should be with quote '`'
e.g.: create table db.t(`key` int primary key, `col` int);
For the ddl with rename table, we remove all quotes '`' to uniform
standars.
e.g.: alter table t1 rename t2.

[test case]
src/planner/ddl_plan_test.go
src/planner/ddl_test.go
src/executor/ddl_executor_test.go

[patch codecov]
src/planner/ddl_plan.go 95.1%
coverage: 89.8% of statements
hustjieke added a commit to hustjieke/radon that referenced this issue Dec 31, 2019
…db#489

[summary]
When scatter sql to backends, the column name should be with quote '`'
e.g.: create table db.t(`key` int primary key, `col` int);
For the ddl with rename table, we remove all quotes '`' to uniform
standars.
e.g.: alter table t1 rename t2.

[test case]
src/planner/ddl_plan_test.go
src/planner/ddl_test.go
src/executor/ddl_executor_test.go

[patch codecov]
src/planner/ddl_plan.go 95.1%
coverage: 89.8% of statements
hustjieke added a commit to hustjieke/radon that referenced this issue Jan 2, 2020
…db#489

[summary]
When scatter sql to backends, the column name should be with quote '`'
e.g.: create table db.t(`key` int primary key, `col` int);
For the ddl with rename table, we remove all quotes '`' to uniform
standars.
e.g.: alter table t1 rename t2.

[test case]
src/planner/ddl_plan_test.go
src/planner/ddl_test.go
src/executor/ddl_executor_test.go

[patch codecov]
src/planner/ddl_plan.go 95.1%
coverage: 89.8% of statements
hustjieke added a commit to hustjieke/radon that referenced this issue Jan 5, 2020
…db#489

[summary]
When scatter sql to backends, the column name should be with quote '`'
e.g.: create table db.t(`key` int primary key, `col` int);
For the ddl with rename table, we remove all quotes '`' to uniform
standards.
e.g.: alter table t1 rename t2.

[test case]
src/planner/ddl_plan_test.go
src/planner/ddl_test.go
src/executor/ddl_executor_test.go

[patch codecov]
src/planner/ddl_plan.go 95.1%
coverage: 89.8% of statements
BohuTANG pushed a commit that referenced this issue Jan 7, 2020
[summary]
When scatter sql to backends, the column name should be with quote '`'
e.g.: create table db.t(`key` int primary key, `col` int);
For the ddl with rename table, we remove all quotes '`' to uniform
standards.
e.g.: alter table t1 rename t2.

[test case]
src/planner/ddl_plan_test.go
src/planner/ddl_test.go
src/executor/ddl_executor_test.go

[patch codecov]
src/planner/ddl_plan.go 95.1%
coverage: 89.8% of statements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P0 High priority
Projects
None yet
Development

No branches or pull requests

3 participants