Skip to content

Commit 7c508dc

Browse files
committed
Fix NewConnection
1 parent 7072640 commit 7c508dc

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

chdb-purego/chdb.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,18 @@ func NewConnection(argc int, argv []string) (ChdbConn, error) {
172172
new_argv = argv
173173
}
174174

175+
// Remove ":memory:" if it is the only argument
176+
if len(new_argv) == 2 && (new_argv[1] == ":memory:" || new_argv[1] == "file::memory:") {
177+
new_argv = new_argv[:1]
178+
}
179+
175180
// Convert string slice to C-style char pointers in one step
176181
c_argv := make([]*byte, len(new_argv))
177182
for i, str := range new_argv {
178-
c_argv[i] = (*byte)(unsafe.Pointer(unsafe.StringData(str)))
183+
// Convert string to []byte and append null terminator
184+
bytes := append([]byte(str), 0)
185+
// Use &bytes[0] to get pointer to first byte
186+
c_argv[i] = &bytes[0]
179187
}
180188

181189
// debug print new_argv

0 commit comments

Comments
 (0)