diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2026-04-17 15:29:47 +0200 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2026-04-17 15:29:47 +0200 |
| commit | 793ba92c9f743d1755913bcb836b07973d4ca4bc (patch) | |
| tree | cdfcad6e89da933302f3d0505400855fc2ca4fd6 /internal/mock/mock.go | |
| parent | 52f44287216b47149da9eb3f038408447f0e5981 (diff) | |
| download | go-oblast-793ba92c9f743d1755913bcb836b07973d4ca4bc.tar.gz | |
basic test coverage for Insert, Update, Delete
Diffstat (limited to 'internal/mock/mock.go')
| -rw-r--r-- | internal/mock/mock.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/internal/mock/mock.go b/internal/mock/mock.go index ecbb03e..6265166 100644 --- a/internal/mock/mock.go +++ b/internal/mock/mock.go @@ -158,7 +158,17 @@ func (s *statement) Close() error { // NumInput implements the [driver.Stmt] interface. func (s *statement) NumInput() int { - return strings.Count(s.query, "?") // NOTE: extremely crude, but does the job for us + // option 1: when using SQLite dialect, count `?` + count := strings.Count(s.query, "?") + if count > 0 { + return count + } + + // option 2: when using PostgreSQL dialect, find `$1`, `$2`, etc. + for strings.Contains(s.query, fmt.Sprintf("$%d", count+1)) { + count++ + } + return count } // Exec implements the [driver.Stmt] interface. |
