package squirrel

import (
	
	
	
)
PlaceholderFormat is the interface that wraps the ReplacePlaceholders method. ReplacePlaceholders takes a SQL statement and replaces each question mark placeholder with a (possibly different) SQL placeholder.
type PlaceholderFormat interface {
	ReplacePlaceholders(sql string) (string, error)
}

type placeholderDebugger interface {
	debugPlaceholder() string
}

Question is a PlaceholderFormat instance that leaves placeholders as question marks.
Dollar is a PlaceholderFormat instance that replaces placeholders with dollar-prefixed positional placeholders (e.g. $1, $2, $3).
Colon is a PlaceholderFormat instance that replaces placeholders with colon-prefixed positional placeholders (e.g. :1, :2, :3).
AtP is a PlaceholderFormat instance that replaces placeholders with "@p"-prefixed positional placeholders (e.g. @p1, @p2, @p3).
	AtP = atpFormat{}
)

type questionFormat struct{}

func (questionFormat) ( string) (string, error) {
	return , nil
}

func (questionFormat) () string {
	return "?"
}

type dollarFormat struct{}

func (dollarFormat) ( string) (string, error) {
	return replacePositionalPlaceholders(, "$")
}

func (dollarFormat) () string {
	return "$"
}

type colonFormat struct{}

func (colonFormat) ( string) (string, error) {
	return replacePositionalPlaceholders(, ":")
}

func (colonFormat) () string {
	return ":"
}

type atpFormat struct{}

func (atpFormat) ( string) (string, error) {
	return replacePositionalPlaceholders(, "@p")
}

func (atpFormat) () string {
	return "@p"
}
Placeholders returns a string with count ? placeholders joined with commas.
func ( int) string {
	if  < 1 {
		return ""
	}

	return strings.Repeat(",?", )[1:]
}

func (,  string) (string, error) {
	 := &bytes.Buffer{}
	 := 0
	for {
		 := strings.Index(, "?")
		if  == -1 {
			break
		}

		if len([:]) > 1 && [:+2] == "??" { // escape ?? => ?
			.WriteString([:])
			.WriteString("?")
			if len([:]) == 1 {
				break
			}
			 = [+2:]
		} else {
			++
			.WriteString([:])
			fmt.Fprintf(, "%s%d", , )
			 = [+1:]
		}
	}

	.WriteString()
	return .String(), nil