Closed twowind closed 6 days ago
Added tests, my fix also helps with your issue
Added tests, my fix also helps with your issue
Thank you for the quick fix! It works fine with the ClickHouse API
interface, but it still doesn't work with database/sql
.
conn := clickhouse.OpenDB(options);
_, err := conn.Prepare(tc.input); // err != nil
@twowind
Could you verify on a latest version? Here is a code snippet that I wrote to reproduce your issue. It uses a helper function to initiate database/sql
connection:
package issues
import (
"fmt"
"testing"
clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests"
"github.com/stretchr/testify/require"
)
func Test1329(t *testing.T) {
testEnv, err := clickhouse_tests.GetTestEnvironment("issues")
require.NoError(t, err)
conn, err := clickhouse_tests.TestDatabaseSQLClientWithDefaultSettings(testEnv)
require.NoError(t, err)
_, err = conn.Exec(`CREATE TABLE test_1329 (Col String) Engine Memory()`)
require.NoError(t, err)
t.Cleanup(func() {
_, _ = conn.Exec("DROP TABLE test_1329")
})
scope, err := conn.Begin()
batch, err := scope.Prepare(fmt.Sprintf("INSERT INTO `%s`.`test_1329`", testEnv.Database))
require.NoError(t, err)
_, err = batch.Exec(
"str",
)
require.NoError(t, err)
require.NoError(t, scope.Commit())
}
@jkaflik
I'm sorry, my previous description might have been a bit unclear. The latest library has fixed the Prepare
for non-http protocols, but there are still issues with http protocol.
Below is my test code:
env, err := clickhouse_tests.GetTestEnvironment("issues")
require.NoError(t, err)
options := &clickhouse.Options{
Addr: []string{fmt.Sprintf("%s:%d", env.Host, env.HttpPort)},
Auth: clickhouse.Auth{
Database: env.Database,
Username: env.Username,
Password: env.Password,
},
Protocol: clickhouse.HTTP,
}
conn := clickhouse.OpenDB(options)
require.NoError(t, conn.Ping())
d := "CREATE DATABASE db ENGINE = Memory"
_, err = conn.Exec(d)
require.NoError(t, err)
ddl := "CREATE TABLE IF NOT EXISTS `db`.`t` (`test1` String) Engine = Memory"
_, err = conn.Exec(ddl)
require.NoError(t, err)
_, err = conn.Prepare("INSERT INTO `db`.`t`")
require.NoError(t, err)
Observed
When the insert statement contains a database name or a table name wrapped in ``, the table name is not recognized correctly.
Code example
Error log
Details
Environment
clickhouse-go
version: 2.25.0database/sql
compatible driverCREATE TABLE
statements for tables involved: CREATE TABLE IF NOT EXISTS `db`.`t` (`test1` String) Engine = Memory