Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F15045723
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
View Options
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
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Nov 30, 10:23 AM (3 h, 24 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3830680
Attached To
rWF WriteFreely
Event Timeline
Log In to Comment