IssueRaiser

database/sql: missing escape functions

### What version of Go are you using (`go version`)? go version go1.7.4 linux/amd64 ### What operating system and processor architecture are you using (`go env`)? GOARCH="amd64" GOBIN="" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/home/nefthy/go-test/" GORACE="" GOROOT="/usr/lib/go" GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64" CC="x86_64-pc-linux-gnu-gcc" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/home/nefthy/go-test/tmp/go-build451484149=/tmp/go-build -gno-record-gcc-switches" CXX="x86_64-pc-linux-gnu-g++" CGO_ENABLED="1" ### What did you do? There are situations when strings need to be escaped in queries that can not be done with placeholders. An example the following queries cannot be expressed with ? placeholders: ```sql SELECT id, ? FROM table -- Must be escaped as an identifier SELECT id FROM ? -- Also identifier quoting SELECT id FROM table WHERE ? LIKE ? -- With either the first or second parameter being a column reference ``` Using Sprintf is no option, since the identifiers need to be properly quoted. The quoting and escaping is inherently vendor specific and may even depend on configuration on a per database/connection basis (hello there MySql...). ### What did you expect to see? The driver must export Quoting which are passed along by the database/sql Api. As far as I can tell the folling functions are needed - QuoteString: quotes and escapes a string so it can be used as a string literal (ex: mysql_

Posted by nefthy on Dec 30, 2016, 3:05 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.4,500 issues0 comments

github (Sysadmin)

database/sql: missing escape functions

nefthyDec 30, 2016, 3:05 PM

### What version of Go are you using (`go version`)? go version go1.7.4 linux/amd64 ### What operating system and processor architecture are you using (`go env`)? GOARCH="amd64" GOBIN="" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/home/nefthy/go-test/" GORACE="" GOROOT="/usr/lib/go" GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64" CC="x86_64-pc-linux-gnu-gcc" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/home/nefthy/go-test/tmp/go-build451484149=/tmp/go-build -gno-record-gcc-switches" CXX="x86_64-pc-linux-gnu-g++" CGO_ENABLED="1" ### What did you do? There are situations when strings need to be escaped in queries that can not be done with placeholders. An example the following queries cannot be expressed with ? placeholders: ```sql SELECT id, ? FROM table -- Must be escaped as an identifier SELECT id FROM ? -- Also identifier quoting SELECT id FROM table WHERE ? LIKE ? -- With either the first or second parameter being a column reference ``` Using Sprintf is no option, since the identifiers need to be properly quoted. The quoting and escaping is inherently vendor specific and may even depend on configuration on a per database/connection basis (hello there MySql...). ### What did you expect to see? The driver must export Quoting which are passed along by the database/sql Api. As far as I can tell the folling functions are needed - QuoteString: quotes and escapes a string so it can be used as a string literal (ex: mysql_

Comments (0)

No comments yet. Start the discussion.

Comment on this issue