FIXME: this should be able to be tolerant of escaped ?'s in queries without losing much speed, and should be to avoid confusion. Rebind a query from the default bindtype (QUESTION) to the target bindtype.
(bindType int, query string)
| 58 | |
| 59 | // Rebind a query from the default bindtype (QUESTION) to the target bindtype. |
| 60 | func Rebind(bindType int, query string) string { |
| 61 | switch bindType { |
| 62 | case QUESTION, UNKNOWN: |
| 63 | return query |
| 64 | } |
| 65 | |
| 66 | // Add space enough for 10 params before we have to allocate |
| 67 | rqb := make([]byte, 0, len(query)+10) |
| 68 | |
| 69 | var i, j int |
| 70 | |
| 71 | for i = strings.Index(query, "?"); i != -1; i = strings.Index(query, "?") { |
| 72 | rqb = append(rqb, query[:i]...) |
| 73 | |
| 74 | switch bindType { |
| 75 | case DOLLAR: |
| 76 | rqb = append(rqb, '$') |
| 77 | case NAMED: |
| 78 | rqb = append(rqb, ':', 'a', 'r', 'g') |
| 79 | case AT: |
| 80 | rqb = append(rqb, '@', 'p') |
| 81 | } |
| 82 | |
| 83 | j++ |
| 84 | rqb = strconv.AppendInt(rqb, int64(j), 10) |
| 85 | |
| 86 | query = query[i+1:] |
| 87 | } |
| 88 | |
| 89 | return string(append(rqb, query...)) |
| 90 | } |
| 91 | |
| 92 | // Experimental implementation of Rebind which uses a bytes.Buffer. The code is |
| 93 | // much simpler and should be more resistant to odd unicode, but it is twice as |
no outgoing calls