stmt

package
v1.6.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 31, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromContext

func FromContext(ctx context.Context, query string) (*sql.Stmt, bool)

FromContext retrieves a SQL statement from the context chain that matches the given query. It performs a recursive search through the context chain until it finds a matching statement or reaches the end of the chain.

Note: It prevents infinite recursion by checking for self-referential contexts.

func Query

func Query(s *sql.Stmt) string

Query extracts the SQL query string from a *sql.Stmt using unsafe pointer arithmetic.

How it works: 1. sql.Stmt struct memory layout (only relevant fields):

  • First field (*DB): 8 bytes (on 64-bit systems)

  • Second field (query string): 16 bytes <- we want this

2. To get the query string, we:

a. Start at the beginning of the struct (sql.Stmt)
b. Skip the first field (8 bytes) to reach query string
c. Read the string value

Note: This implementation relies on the internal structure of sql.Stmt and may break if the struct layout changes in future Go versions.

func WithContext

func WithContext(ctx context.Context, stmt *sql.Stmt) context.Context

WithContext creates a new context containing the provided SQL statement. It maintains a chain of contexts, allowing for statement reuse and lookup.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL