Page MenuHomeMusing Studio

No OneTemporary

diff --git a/db/query_wrap.go b/db/query_wrap.go
index 988e07c..5613d81 100644
--- a/db/query_wrap.go
+++ b/db/query_wrap.go
@@ -1,40 +1,35 @@
package db
import (
"fmt"
)
-/**
- * MySQL/SQLite use '?' as placeholders in prepared statments
- * while PostgreSQL use '$1', '$2' ... '$n' instead
- *
- * this function converts a prepared statement in MySQL/SQLite
- * format into PostgreSQL format
- */
+// PGQueryWrap converts a prepared statement from MySQL/SQLite format, which
+// uses ? placeholders, into PostgreSQL format, which uses $1, $2 ... $n.
func PGQueryWrap(q string) string {
output := ""
escaped := false
var escapeChar byte = 0
ctr := 0
for i := range len(q) {
if escaped {
if q[i] == escapeChar {
escaped = false
escapeChar = 0
}
} else if q[i] == '\'' || q[i] == '`' || q[i] == '"' {
escaped = true
escapeChar = q[i]
}
if q[i] == '?' && !escaped {
ctr += 1
output += fmt.Sprintf("$%d", ctr)
} else {
output += string(q[i])
}
}
return output
}

File Metadata

Mime Type
text/x-diff
Expires
Mon, Nov 30, 10:23 AM (3 h, 36 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3830680

Event Timeline