MCPcopy Create free account
hub / github.com/mattn/go-sqlite3 / TestFunctionArgStringContainingZero

Function TestFunctionArgStringContainingZero

sqlite3_test.go:1551–1585  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1549}
1550
1551func TestFunctionArgStringContainingZero(t *testing.T) {
1552 sql.Register("sqlite3_FunctionArgZero", &SQLiteDriver{
1553 ConnectHook: func(conn *SQLiteConn) error {
1554 // arglen reports how many bytes of the text argument reached the
1555 // Go side; echo returns the string result verbatim.
1556 if err := conn.RegisterFunc("arglen", func(s string) int64 { return int64(len(s)) }, true); err != nil {
1557 return err
1558 }
1559 return conn.RegisterFunc("echo", func(s string) string { return s }, true)
1560 },
1561 })
1562 db, err := sql.Open("sqlite3_FunctionArgZero", ":memory:")
1563 if err != nil {
1564 t.Fatal("Failed to open database:", err)
1565 }
1566 defer db.Close()
1567
1568 const text = "foo\x00bar"
1569
1570 var n int64
1571 if err := db.QueryRow("SELECT arglen(?)", text).Scan(&n); err != nil {
1572 t.Fatal("Failed to call db.QueryRow:", err)
1573 }
1574 if n != int64(len(text)) {
1575 t.Errorf("text argument truncated at embedded NUL: got len %d, want %d", n, len(text))
1576 }
1577
1578 var got string
1579 if err := db.QueryRow("SELECT echo(?)", text).Scan(&got); err != nil {
1580 t.Fatal("Failed to call db.QueryRow:", err)
1581 }
1582 if got != text {
1583 t.Errorf("text result truncated at embedded NUL: got %q (len %d), want %q (len %d)", got, len(got), text, len(text))
1584 }
1585}
1586
1587type sumAggregator int64
1588

Callers

nothing calls this directly

Calls 4

OpenMethod · 0.65
CloseMethod · 0.65
RegisterFuncMethod · 0.45
ScanMethod · 0.45

Tested by

no test coverage detected