{"record":{"id":"c7061580f2b894a3","repo":"benbjohnson/litestream","slug":"get-table-info-w","errorCode":null,"errorMessage":"get table info: %w","messagePattern":"get table info: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/litestream-test/shrink.go","lineNumber":191,"sourceCode":"\tcountQuery := fmt.Sprintf(\"SELECT COUNT(*) FROM %s\", table)\n\tif err := db.QueryRow(countQuery).Scan(&totalRows); err != nil {\n\t\treturn 0, fmt.Errorf(\"count rows: %w\", err)\n\t}\n\n\tif totalRows == 0 {\n\t\treturn 0, nil\n\t}\n\n\trowsToDelete := int(float64(totalRows) * (c.DeletePercentage / 100))\n\tif rowsToDelete == 0 {\n\t\treturn 0, nil\n\t}\n\n\tvar hasID bool\n\tcolumnQuery := fmt.Sprintf(\"PRAGMA table_info(%s)\", table)\n\trows, err := db.Query(columnQuery)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"get table info: %w\", err)\n\t}\n\tdefer rows.Close()\n\n\tfor rows.Next() {\n\t\tvar cid int\n\t\tvar name, dtype string\n\t\tvar notnull, pk int\n\t\tvar dflt sql.NullString\n\t\tif err := rows.Scan(&cid, &name, &dtype, &notnull, &dflt, &pk); err != nil {\n\t\t\tcontinue\n\t\t}\n\t\tif name == \"id\" || pk == 1 {\n\t\t\thasID = true\n\t\t\tbreak\n\t\t}\n\t}\n\n\tvar deleteQuery string","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream-test/shrink.go#L173-L209","documentation":"This error wraps a failure of the `PRAGMA table_info(<table>)` query that `deleteFromTable` uses to discover whether the table has an `id` column. It means SQLite rejected the PRAGMA — typically because the table does not exist or the table name breaks the PRAGMA syntax (PRAGMA arguments cannot be parameterized, so the name is interpolated raw).","triggerScenarios":"Table name absent from the database; table name containing quotes/parentheses/spaces that break `PRAGMA table_info(name)`; database locked so the query fails; driver-level error opening rows (`db.Query`) on a corrupted DB.","commonSituations":"Passing hyphenated or space-containing table names to `litestream-test shrink`; typo in `--table` flag; shrink running against a freshly created (empty) database file where no tables exist yet.","solutions":["Confirm the exact table name exists via `sqlite3 <db> '.schema <table>'`","Avoid special characters in table names, or wrap the name in double quotes in the PRAGMA","Close competing connections that may hold locks on the database","Inspect the wrapped driver error (`%w`) for the precise SQLite error code"],"exampleFix":"// before\ncolumnQuery := fmt.Sprintf(\"PRAGMA table_info(%s)\", table)\n// after\ncolumnQuery := fmt.Sprintf(\"PRAGMA table_info(%q)\", table)","handlingStrategy":"validation","validationCode":"var exists int\ndb.QueryRow(\"SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name=?\", table).Scan(&exists)\nif exists == 0 { return fmt.Errorf(\"table %q not found\", table) }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use simple identifier-safe table names","Verify schema with .schema before running PRAGMA-based tooling","Read wrapped driver errors for exact SQLite code"],"tags":["sqlite","pragma","database","test-tooling"],"backgroundTag":"database-query-failed","analyzedSha":"4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3","analyzedAt":"2026-09-06T18:29:25.564Z","contentChangedAt":"2026-09-06T18:29:25.564Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}