I'm not talking about it being an interface, I'm talking about having a
different return type for "Exec" and "Query".

Specifically, oracle, sql server, pg natively have something like SELECT
ID_PERSON" ie. The result of these queries is a rowset.

It's just sqlite and mysql that have a magical 'get_last_inserted_id()'

Surely it'd be more consistent and logical to have a single sql.Query()
function that returns a rowset, and no exec() action.

I mean, yes, you can wrap the result, read the row and return a Result
object when you write a driver, but you're doing extra work here for no

How are you even supposed to run the query:


Using the sql library? Do we use sql.Query() for this?
No~ because you can't use sql.Query() for insert statements for some
database drivers (eg. https://github.com/go-sql-driver/mysql).

The issue I have is that by having two functions one which does 'some
queries' and one that does 'other queries' you're encouraging people to
write drivers are DONT WORK.

Specifically, drivers where the Query() function cannot be used to perform
an INSERT statement.

This seems like a bad design to me...

On Monday, April 8, 2013 7:59:06 AM UTC+8, Kyle Lemons wrote:

The reason it is an interface is that the authors understood that some
drivers have different semantics for how the e.g. last inserted ID are
retrieved. In the case of postgres, the LastInsertID function on the
result can "SELECT LASTVAL();" on demand. If the client doesn't need the
last ID, then there's no additional overhead. Similar for AffectedRows and
"SELECT SQL%ROWCOUNT". Of course, the semantics of how these work should
be documented in your driver package to avoid surprises :).

On Sun, Apr 7, 2013 at 7:29 AM, Dougx <douglas...@gmail.com <javascript:>>wrote:

Is there any particular reason the sql package distinguishes between a
query that returns a set of rows, and an 'Exec' that returns a 'Result'
type, which contains the insert id and affected rows?

A number of dbs (notably postgres and sql server) don't support the mysql
concept of 'last insert id' as a simple output.

I'm in the process of writing a wrapper that transparently wraps the sql
package and does away with 'exec' and 'result' entirely and converts
everything into a *Rows on return, specifically because of that, but I was
wondering if someone could drop in with the justification for this decision
in the api?

I realize it probably makes it easier to write some database drivers, but
it makes it basically impossible to implement the api for others....


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...@googlegroups.com <javascript:>.
For more options, visit https://groups.google.com/groups/opt_out.

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

Discussion Posts


Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 3 of 20 | next ›
Discussion Overview
groupgolang-nuts @
postedApr 7, '13 at 2:29p
activeApr 12, '13 at 7:19p



site design / logo © 2021 Grokbase