Skip to content

Commit

Permalink
Fix column name with parantheses handle in prepare batch (#1252)
Browse files Browse the repository at this point in the history
* Fix column name with parantheses handle in prepare batch

* fix test
  • Loading branch information
jkaflik committed Mar 25, 2024
1 parent d79a61c commit 03cb115
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion conn_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
)

var splitInsertRe = regexp.MustCompile(`(?i)\sVALUES\s*\(`)
var columnMatch = regexp.MustCompile(`.*\((?P<Columns>.+)\)$`)
var columnMatch = regexp.MustCompile(`INSERT INTO .+\s\((?P<Columns>.+)\)$`)

func (c *connect) prepareBatch(ctx context.Context, query string, opts driver.PrepareBatchOptions, release func(*connect, error), acquire func(context.Context) (*connect, error)) (driver.Batch, error) {
//defer func() {
Expand Down
31 changes: 31 additions & 0 deletions tests/issues/1247_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package issues

import (
"context"
"testing"

"github.com/ClickHouse/clickhouse-go/v2"
clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests"
"github.com/stretchr/testify/require"
)

func Test1247(t *testing.T) {
var (
conn, err = clickhouse_tests.GetConnection("issues", clickhouse.Settings{
"max_execution_time": 60,
"allow_experimental_object_type": true,
}, nil, &clickhouse.Compression{
Method: clickhouse.CompressionLZ4,
})
)
ctx := context.Background()
require.NoError(t, err)
const ddl = "CREATE TABLE test_1247 (`ColumnNameWithParentheses(something)` String) Engine MergeTree() ORDER BY tuple()"
require.NoError(t, conn.Exec(ctx, ddl))
defer func() {
conn.Exec(ctx, "DROP TABLE IF EXISTS test_1247")
}()

_, err = conn.PrepareBatch(context.Background(), "INSERT INTO test_1247 (`ColumnNameWithParentheses(something)`)")
require.NoError(t, err)
}

0 comments on commit 03cb115

Please sign in to comment.