```go
func createTable(db *sql.DB, table string) {
sql := `
DROP TABLE IF EXISTS ` + table + `;
CREATE TABLE ` + table + `(
uid INT(10) NOT NULL AUTO_INCREMENT,
username VARCHAR(64) NULL DEFAULT NULL,
departname VARCHAR(64) NULL DEFAULT NULL,
created DATE NULL DEFAULT NULL,
PRIMARY KEY(uid)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;`
fmt.Println("\n" + sql + "\n")
smt, err := db.Prepare(sql)
checkErr(err)
smt.Exec()
}
```
这是我打印的调试信息:
DROP TABLE IF EXISTS tablea;
CREATE TABLE tablea(
uid INT(10) NOT NULL AUTO_INCREMENT,
username VARCHAR(64) NULL DEFAULT NULL,
departname VARCHAR(64) NULL DEFAULT NULL,
created DATE NULL DEFAULT NULL,
PRIMARY KEY(uid)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
panic: Error 1064: 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 'CREATE TABLE tablea(
uid INT(10) NOT NULL AUTO_INCREMENT,
username VARCHAR(64)' at line 22
这是为什么捏?
![raw.png](http://studygolang.qiniudn.com/150505/dfd1bc44648ef07cf98f8cf3589ad892.png)
![re.png](http://studygolang.qiniudn.com/150505/0fc1368d69a0d5a8917f099c7f9d236a.png)
发现一个新问题,打印出来的信息是有自动缩进的,直接贴到terminal里会报错,第一个图显示的是原始信息,第二个图我去缩进之后贴到terminal会正确执行
#6
更多评论