FAQ
Can someone explain me the reason for the last three lines of this example<http://golang.org/pkg/database/sql/#example_DB_Query>?
All errors are checked before, why should I (re-)check for errors again?
What else could go wrong?

Thanks!
Michael

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Jan Mercl at Aug 8, 2013 at 10:39 am

    On Thu, Aug 8, 2013 at 12:31 PM, wrote:
    Can someone explain me the reason for the last three lines of this example?
    All errors are checked before, why should I (re-)check for errors again?
    What else could go wrong?
    .Next returns only a bool and cannot report a possible error.
    Returning false can mean "no more rows b/c at end of a recird set" or
    "no more rows b/c some error".

    -j

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Michael Rauh77 at Aug 8, 2013 at 1:51 pm
    Thanks for your answer! Of course, you are right. But IMO this example
    doesn't make sense because if there is an error, the program exists. In
    other (error) cases there may be a "return" statement so the function
    exits. If an error occurs, the program never reaches the last three lines.
    Therefore I think they are redundant. But maybe I'm wrong...



    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Volker Dobler at Aug 8, 2013 at 2:16 pm
    Am Donnerstag, 8. August 2013 15:51:45 UTC+2 schrieb
    michael...@googlemail.com:
    Thanks for your answer! Of course, you are right. But IMO this example
    doesn't make sense because if there is an error, the program exists. In
    other (error) cases there may be a "return" statement so the function
    exits. If an error occurs, the program never reaches the last three lines.
    Therefore I think they are redundant. But maybe I'm wrong...

    First: This is an example, not industrial strength code.
    Second: As Jan explained: The for loop may terminate because Next yields
    false.
    This can be because of a new error which has not been handled by any code
    so far. But will be handled by the last three lines if this end to for was
    because
    of an error.

    V.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Christoph Hack at Aug 8, 2013 at 2:17 pm
    The first error value might report problems with the database (e.g. no
    connection) or errors in the statement (e.g. invalid sql syntax). The error
    value from Scan() will only report scanning errors, eg. scanning into a
    non-pointer value or scanning really large numbers into a uint8 (that might
    result in a loss of precision). The third error check indicates errors that
    occurred while traversing the rows, e.g an abrupt connection loss.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Michael Rauh77 at Aug 8, 2013 at 4:02 pm
    OK, thanks to all for your answers!

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Michael Rauh77 at Aug 8, 2013 at 4:12 pm
    Christoph, the abrupt connection loss really makes sense! Nice example!

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Kamil Kisiel at Aug 8, 2013 at 4:13 pm
    Just thought I'd add that this pattern is also used by bufio.Scanner

    On Thursday, August 8, 2013 3:31:12 AM UTC-7, michael...@googlemail.com
    wrote:
    Can someone explain me the reason for the last three lines of this example<http://golang.org/pkg/database/sql/#example_DB_Query>?
    All errors are checked before, why should I (re-)check for errors again?
    What else could go wrong?

    Thanks!
    Michael
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedAug 8, '13 at 10:31a
activeAug 8, '13 at 4:13p
posts8
users5
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase