{"record":{"id":"21424ee8cadfda90","repo":"kataras/iris","slug":"sqlx-bind-table-q-w","errorCode":null,"errorMessage":"sqlx: bind: table: %q: %w","messagePattern":"sqlx: bind: table: %q: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"x/sqlx/sqlx.go","lineNumber":135,"sourceCode":"\tif typ.Kind() != reflect.Ptr {\n\t\treturn fmt.Errorf(\"sqlx: bind: destination not a pointer\")\n\t}\n\n\ttyp = typ.Elem()\n\n\toriginalKind := typ.Kind()\n\tif typ.Kind() == reflect.Slice {\n\t\ttyp = typ.Elem()\n\t}\n\n\tr, ok := s.Rows[typ]\n\tif !ok {\n\t\treturn fmt.Errorf(\"sqlx: bind: unregistered type: %q\", typ.String())\n\t}\n\n\tcolumnTypes, err := src.ColumnTypes()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"sqlx: bind: table: %q: %w\", r.Name, err)\n\t}\n\n\tif expected, got := len(r.Columns), len(columnTypes); expected != got {\n\t\treturn fmt.Errorf(\"sqlx: bind: table: %q: unexpected number of result columns: %d: expected: %d\", r.Name, got, expected)\n\t}\n\n\tval := reflex.IndirectValue(reflect.ValueOf(dst))\n\tif s.AutoCloseRows {\n\t\tdefer src.Close()\n\t}\n\n\tswitch originalKind {\n\tcase reflect.Struct:\n\t\tif src.Next() {\n\t\t\tif err = r.bindSingle(typ, val, columnTypes, src); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t} else {","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/x/sqlx/sqlx.go#L117-L153","documentation":"Schema.Bind fetches column metadata from the open *sql.Rows via src.ColumnTypes(); a failure there is wrapped as \"sqlx: bind: table: <table>: %w\" keeping the underlying driver error. It wraps only real driver/rows errors during the column-type lookup phase of Bind.","triggerScenarios":"Calling Bind/Query with rows whose connection dropped before ColumnTypes() is called, rows already closed (AutoCloseRows false and manually closed), or a driver that cannot report column metadata.","commonSituations":"Context cancellation/timeouts killing the query mid-flight; reusing rows after close; flaky connections under load.","solutions":["Inspect the wrapped %w cause (use errors.Unwrap / errors.As) — fix the underlying driver error (network, closed rows, canceled context).","Ensure the context is not canceled and the connection is alive before Query/Bind.","Leave AutoCloseRows true (default) so rows are not closed before Bind reads ColumnTypes."],"exampleFix":"// before\nrows.Close()\nschema.Bind(&user, rows) // wraps driver error\n// after\nif err := schema.Bind(&user, rows); err != nil {\n    var derr *driver.Error\n    if errors.As(err, &derr) { /* handle root cause */ }\n}","handlingStrategy":"try-catch","validationCode":"func rowsUsable(ctx context.Context, rows *sql.Rows) error {\n\tif rows == nil { return sql.ErrConnDone }\n\tif err := ctx.Err(); err != nil { return err }\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"err := sqlx.Query(ctx, db, &user, q)\nif err != nil && strings.HasPrefix(err.Error(), \"sqlx: bind: table:\") {\n\tcause := errors.Unwrap(err)\n\tlog.Printf(\"bind failed for table, cause: %v\", cause)\n\t// retry query with fresh context if cause is transient (net error / canceled ctx)\n}","preventionTips":["Keep AutoCloseRows true; never close rows before Bind","Use per-request contexts with sane timeouts","Unwrap and classify the driver error before retrying","Add connection health checks (db.PingContext) before long queries"],"tags":["go","sql","sqlx","bind","driver-error"],"backgroundTag":"database-connection-error","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}