知识卡片
结果集要关闭并检查遍历错误
查询得到Rows后逐行Next与Scan读取,遍历结束还应检查Err,区分读完和中途失败,并及时Close以释放关联资源。执行写入与读取结果集是不同接口职责;参数占位把值与查询结构分离。原稿重放查询未明确排序,真正依赖序号恢复时必须显式保证事件顺序。
典型次序:查询成功后defer rows.Close(),在for rows.Next()中rows.Scan(...),最后检查rows.Err()。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Building a Cloud Native Service · 查看原书依据
rows.Next lets us iterate over the rows; it returns false if there are no more rows or if there’s an error. rows.Scan copies the columns in the current row into the values we pointed at in the call. We send our e to the output channel. Err returns the error, if any, that may have
参考来源
- 位置:《Cloud Native Go》第05章《Building a Cloud Native Service》(来源项目book-sources;源文件:extracted/Cloud Native Go (Matthew A. Titmus)/_epub-src/OEBPS/ch05.xhtml)
- 结论依据:查询得到Rows后逐行Next与Scan读取,遍历结束还应检查Err,区分读完和中途失败,并及时Close以释放关联资源。原文相应定义、示例或限制为此结论提供依据;补充纠错与版本边界在正文就近标明。
- 原始内容:rows.Next lets us iterate over the rows; it returns false if there are no more rows or if there’s an error. rows.Scan copies the columns in the current row into the values we pointed at in the call. We send our e to the output channel. Err returns the error, if any, that may have