Skip to content

Commit

Permalink
BatchInsert parentheses issue fix (#1327)
Browse files Browse the repository at this point in the history
* BatchInsert parentheses issue #1326

* BatchInsert backticks issue tests #1329
  • Loading branch information
ramzes642 authored Jun 20, 2024
1 parent de6b568 commit 3391e46
Show file tree
Hide file tree
Showing 2 changed files with 22 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 (
"github.com/ClickHouse/clickhouse-go/v2/lib/proto"
)

var insertMatch = regexp.MustCompile(`(?i)(INSERT\s+INTO\s+\S+(?:\s*\([^()]*(?:\([^()]*\)[^()]*)*\))?)(?:\s*VALUES)?`)
var insertMatch = regexp.MustCompile(`(?i)(INSERT\s+INTO\s+[^( ]+(?:\s*\([^()]*(?:\([^()]*\)[^()]*)*\))?)(?:\s*VALUES)?`)
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) {
Expand Down
21 changes: 21 additions & 0 deletions tests/issues/1280_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package issues

import (
"context"
"fmt"
"testing"

"github.com/ClickHouse/clickhouse-go/v2"
Expand All @@ -17,9 +18,11 @@ func Test1280(t *testing.T) {
}, nil, &clickhouse.Compression{
Method: clickhouse.CompressionLZ4,
})
env, errEnv = clickhouse_tests.GetTestEnvironment(testSet)
)
ctx := context.Background()
require.NoError(t, err)
require.NoError(t, errEnv)

ddl := "CREATE TABLE values (`id` Int32, `values` Int32) Engine = Memory"
require.NoError(t, conn.Exec(ctx, ddl))
Expand All @@ -37,6 +40,15 @@ func Test1280(t *testing.T) {
{
input: "INSERT INTO values (`values`) values",
},
{
input: "INSERT INTO values(values)",
},
{
input: "INSERT INTO `values`(values)",
},
{
input: fmt.Sprintf("INSERT INTO `%s`.`values`(values)", env.Database),
},
}

for i, tc := range testCases1 {
Expand Down Expand Up @@ -76,6 +88,15 @@ func Test1280(t *testing.T) {
values
(id,values) values (1,2)`,
},
{
input: `INSERT INTO values(id, values) values (1,2)`,
},
{
input: fmt.Sprintf("INSERT INTO `%s`.`values`(id, values)", env.Database),
},
{
input: fmt.Sprintf("INSERT INTO `%s`.`values`", env.Database),
},
}

for i, tc := range testCases2 {
Expand Down

0 comments on commit 3391e46

Please sign in to comment.