Skip to content

Query/QueryContext can return RowsAffected

Compare
Choose a tag to compare
@asifjalil asifjalil released this 06 Mar 00:11
· 20 commits to master since this release
71c1bde

Before calling database/sql.Exec/ExecContext and
database/sql.Query/QueryContext, one has to know the type of the query.
That is, if it is a statement that will produce a resultset, then use
Query/QueryContext. Otherwise, use Exec/ExecContext. Sometimes, a method
like JDBC's execute can be handy: A caller can use execute for all queries and use the
true/false to decide to check for resultset or update count. Go's
database/sql package currently does not provide such function.

This driver, for both sql.Exec/ExecContext and sql.Query/QueryContext
use the SQLExecute function from DB2 CLI. It then uses DB2 CLI's
SQLRowCount for sql.Result or SQLNumResultCols for sql.Rows.

This commit adds a hack that allows callers to use sql.Query/QueryContext for all
query type. When this driver finds that a query didn't produce a
resultset but there is a update count, it returns an error that has method RowsAffected(). Callers can check for that error and then use RowsAffected to get the update count.