O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

The pointer to Rows coming from the Query method of the pointer to the DB struct provides the methods to read and extract the data from the result set. 

Note that first the Next method should be called to shift the cursor to the next result row. The Next method returns true if there is any other row, or false if not.

After the new row is fetched by Next, the Scan method could be called to extract the data into a variable. The number of variables must match the number of columns in SELECT, otherwise, the Scan method is not able to extract the data.

The important part of the code is that, after each Next method, the Err method should be called to find out if there was an error during the reading of the next row.

The preceding ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required