func GenerateEqualOuterQuery(sel *sqlparser.Select, tableInfo *schema.MysqlTable) *sqlparser.ParsedQuery { buf := sqlparser.NewTrackedBuffer(nil) fmt.Fprintf(buf, "select ") writeColumnList(buf, tableInfo.Columns) buf.Myprintf(" from %v where ", sel.From) generatePKWhere(buf, tableInfo.Indexes[0]) return buf.ParsedQuery() }
func GenerateFieldQuery(statement sqlparser.Statement) *sqlparser.ParsedQuery { buf := sqlparser.NewTrackedBuffer(FormatImpossible) buf.Myprintf("%v", statement) if buf.HasBindVars() { return nil } return buf.ParsedQuery() }
func GenerateInOuterQuery(sel *sqlparser.Select, tableInfo *schema.MysqlTable) *sqlparser.ParsedQuery { buf := sqlparser.NewTrackedBuffer(nil) fmt.Fprintf(buf, "select ") writeColumnList(buf, tableInfo.Columns) // We assume there is one and only one PK column. // A '*' argument name means all variables of the list. buf.Myprintf(" from %v where %s in (%a)", sel.From, tableInfo.Indexes[0].Columns[0], "*") return buf.ParsedQuery() }
func GenerateInsertOuterQuery(ins *sqlparser.Insert) *sqlparser.ParsedQuery { buf := sqlparser.NewTrackedBuffer(nil) buf.Myprintf("insert %vinto %v%v values %a%v", ins.Comments, ins.Table, ins.Columns, "_rowValues", ins.OnDup, ) return buf.ParsedQuery() }
func GenerateSelectLimitQuery(selStmt sqlparser.SelectStatement) *sqlparser.ParsedQuery { buf := sqlparser.NewTrackedBuffer(nil) sel, ok := selStmt.(*sqlparser.Select) if ok { limit := sel.Limit if limit == nil { sel.Limit = execLimit defer func() { sel.Limit = nil }() } } buf.Myprintf("%v", selStmt) return buf.ParsedQuery() }
func GenerateSubquery(columns []string, table *sqlparser.AliasedTableExpr, where *sqlparser.Where, order sqlparser.OrderBy, limit *sqlparser.Limit, for_update bool) *sqlparser.ParsedQuery { buf := sqlparser.NewTrackedBuffer(nil) if limit == nil { limit = execLimit } fmt.Fprintf(buf, "select ") i := 0 for i = 0; i < len(columns)-1; i++ { fmt.Fprintf(buf, "%s, ", columns[i]) } fmt.Fprintf(buf, "%s", columns[i]) buf.Myprintf(" from %v%v%v%v", table, where, order, limit) if for_update { buf.Myprintf(sqlparser.AST_FOR_UPDATE) } return buf.ParsedQuery() }
func GenerateUpdateOuterQuery(upd *sqlparser.Update, pkIndex *schema.Index) *sqlparser.ParsedQuery { buf := sqlparser.NewTrackedBuffer(nil) buf.Myprintf("update %v%v set %v where ", upd.Comments, upd.Table, upd.Exprs) generatePKWhere(buf, pkIndex) return buf.ParsedQuery() }
func GenerateFullQuery(statement sqlparser.Statement) *sqlparser.ParsedQuery { buf := sqlparser.NewTrackedBuffer(nil) statement.Format(buf) return buf.ParsedQuery() }
func GenerateDeleteOuterQuery(del *sqlparser.Delete, pkIndex *schema.Index) *sqlparser.ParsedQuery { buf := sqlparser.NewTrackedBuffer(nil) buf.Myprintf("delete %vfrom %v where ", del.Comments, del.Table) generatePKWhere(buf, pkIndex) return buf.ParsedQuery() }