使用go-xorm/xorm发送查询更新插入等sql,kingshard不认分表,提示表不存在
franklwel1990 opened this issue · 1 comments
代码示例
results, err := db.Exec("insert into task_record
(jobName,keyId,createdTime) VALUES(?,?,?)","UserNewIncJob","DXJ90S7v4CUb8c0FOh10",1595602706)
fmt.Println(results, err,"----------------------失败")
执行结果
[xorm] [info] [SQL] insert into task_record (jobName,keyId,createdTime) VALUES(?,?,?) []interface {}{"UserNewIncJob", "DXJ90S7v4CUb8c0FOh10", 1595602706}
Error 1105: prepare error ERROR 1146 (42S02): Table 'report.task_record' doesn't exist ----------------------失败
sys.log日志报错
- ERROR - conn.go:[308] - [ClientConn] "Run" "prepare error ERROR 1146 (42S02): Table 'report.task_record' doesn't exist" "" conn_id=10167
数据表
task_record_0000
task_record_0001
备注:
1.命令行直连kingshard执行没有问题
2.该写法执行也没有问题 results, err = db.Exec("insert into task_record
(jobName,keyId,createdTime) VALUES("UserNewIncJob","DXJ90S7v4CUb8c0FOh11",1595602707)")
但凡sql涉及到带条件的VALUES(?,?,?) 都不能识别分表
准确的应该说:kingshard分表不支持预处理语句,我命令行直连kingshard操作预处理语句都报表不存在。
这是一个大多数的类MySQL proxy中间件的通病,未集成预处理语句功能,因而不支持预处理语句。而kingshard虽说只能在非分表下支持了预处理语句功能,但所需功能离真正的MySQL proxy又近了一步(为此点个赞);若要在分表下用,现只能采用具体把值拼接成完整字符串才行,如:results, err := db.Exec("insert into task_record (jobName,keyId,createdTime) VALUES(\””+"UserNewIncJob"+"\",\""+"DXJ90S7v4CUb8c0FOh10"+"\"," + "1595602706")