Lightweight & Compitable wrapper of database/sql
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

39 lines
1.4 KiB

package core
import (
"testing"
"github.com/stretchr/testify/assert"
)
type quoterOnly struct {
Dialect
}
func (q *quoterOnly) Quote(item string) string {
return "[" + item + "]"
}
func TestQuoteFilter_Do(t *testing.T) {
f := QuoteFilter{}
sql := "SELECT `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA` = ? AND `TABLE_NAME` = ? AND `COLUMN_NAME` = ?"
res := f.Do(sql, new(quoterOnly), nil)
assert.EqualValues(t,
"SELECT [COLUMN_NAME] FROM [INFORMATION_SCHEMA].[COLUMNS] WHERE [TABLE_SCHEMA] = ? AND [TABLE_NAME] = ? AND [COLUMN_NAME] = ?",
res,
)
}
func TestSeqFilter(t *testing.T) {
var kases = map[string]string{
"SELECT * FROM TABLE1 WHERE a=? AND b=?": "SELECT * FROM TABLE1 WHERE a=$1 AND b=$2",
"SELECT 1, '???', '2006-01-02 15:04:05' FROM TABLE1 WHERE a=? AND b=?": "SELECT 1, '???', '2006-01-02 15:04:05' FROM TABLE1 WHERE a=$1 AND b=$2",
"select '1''?' from issue": "select '1''?' from issue",
"select '1\\??' from issue": "select '1\\??' from issue",
"select '1\\\\',? from issue": "select '1\\\\',$1 from issue",
"select '1\\''?',? from issue": "select '1\\''?',$1 from issue",
}
for sql, result := range kases {
assert.EqualValues(t, result, convertQuestionMark(sql, "$", 1))
}
}