func FormatWithBind(buf *sqlparser.TrackedBuffer, node sqlparser.SQLNode) { switch node := node.(type) { case sqlparser.StrVal, sqlparser.NumVal: buf.WriteArg(fmt.Sprintf(":v%d", bindIndex)) bindIndex++ default: node.Format(buf) } }
// FormatImpossible is a callback function used by TrackedBuffer // to generate a modified version of the query where all selects // have impossible where clauses. It overrides a few node types // and passes the rest down to the default FormatNode. func FormatImpossible(buf *sqlparser.TrackedBuffer, node sqlparser.SQLNode) { switch node := node.(type) { case *sqlparser.Select: buf.Myprintf("select %v from %v where 1 != 1", node.SelectExprs, node.From) case *sqlparser.JoinTableExpr: if node.Join == sqlparser.AST_LEFT_JOIN || node.Join == sqlparser.AST_RIGHT_JOIN { // ON clause is requried buf.Myprintf("%v %s %v on 1 != 1", node.LeftExpr, node.Join, node.RightExpr) } else { buf.Myprintf("%v %s %v", node.LeftExpr, node.Join, node.RightExpr) } default: node.Format(buf) } }