`
gaojingsong
  • 浏览: 1210745 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

Mycat源码解读--错误之【op table not in schema】

阅读更多

1、[Err] 1064 - op table not in schema----INDEX

备注:这种错误一般是表名字获取失败报的错误,

具体位置是: RouterUtil类中的routeToDDLNode方法报的




/**

* 修复DDL路由

*

* @return RouteResultset

* @author aStoneGod

*/

    public static RouteResultset routeToDDLNode(RouteResultset rrs, int sqlType, 

                String stmt,SchemaConfig schema) throws SQLSyntaxErrorException {

stmt = getFixedSql(stmt);

String tablename = "";

final String upStmt = stmt.toUpperCase();

if(upStmt.startsWith("CREATE")){

  if (upStmt.contains("CREATE INDEX ")){//如果create Index之间的空格不匹配也会报错

tablename = RouterUtil.getTableName(stmt, RouterUtil.getCreateIndexPos(upStmt, 0));

  }else {//Create View/Table/CREATE SYNONYM统一执行此处代码

                           //(创建表, 索引, 视图, 同义词, 过程, 函数, 数据库链接等)

                           //create user username identified by password;

tablename = RouterUtil.getTableName(stmt, RouterUtil.getCreateTablePos(upStmt, 0));

}

}else if(upStmt.startsWith("DROP")){

if (upStmt.contains("DROP INDEX ")){

tablename = RouterUtil.getTableName(stmt, RouterUtil.getDropIndexPos(upStmt, 0));

}else {

tablename = RouterUtil.getTableName(stmt, RouterUtil.getDropTablePos(upStmt, 0));

}

}else if(upStmt.startsWith("ALTER")){

tablename = RouterUtil.getTableName(stmt, RouterUtil.getAlterTablePos(upStmt, 0));

}else if (upStmt.startsWith("TRUNCATE")){

tablename = RouterUtil.getTableName(stmt, RouterUtil.getTruncateTablePos(upStmt, 0));

}

tablename = tablename.toUpperCase();

 

if (schema.getTables().containsKey(tablename)){

//此处省略部分代码

return rrs;

}else if(schema.getDataNode()!=null){//默认节点ddl

RouteResultsetNode[] nodes = new RouteResultsetNode[1];

nodes[0] = new RouteResultsetNode(schema.getDataNode(), sqlType, stmt);

nodes[0].setSource(rrs);

rrs.setNodes(nodes);

return rrs;

}

//both tablename and defaultnode null

LOGGER.error("table not in schema----"+tablename);

throw new SQLSyntaxErrorException("op table not in schema----"+tablename);

}



 空格恰到好处就OK



 

  • 大小: 81 KB
  • 大小: 109.6 KB
  • 大小: 40.2 KB
0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics