FAQ
You'll notice your code uses Exec() and not Query() for the CREATE TABLE
statement.
On Friday, April 12, 2013 4:59:38 AM UTC+8, gwenn...@gmail.com wrote:

Hello,
I've tried your scenario with three different implementations:
http://play.golang.org/p/5BZhPN3XTO
All the sqlite3 drivers seem to work perfectly!
A fortiori, all the statements used are sql-92 compliant (except may be
the create statement), thanks to the database/sql layer.
And I don't see why any rdbms with a jdbc implementation of
Statement#getGeneratedKeys() cannot support go implementation of
Result#LastInsertId
Regards.
On Wednesday, April 10, 2013 2:31:24 AM UTC+2, Dougx wrote:

Which one is yours?

I just downloaded each of the drivers and ran the local-sql-direct
equivalent of something like:

create table blah with autogen primary key
insert 2 records into blah
select records from blah
verify they have different ids
update both records
select records from blah
verify they have the same value
delete both records from blah
select records from blah
verify no records were found

... using only query, and never exec.

I didn't formally create a test suite or anything, I just downloaded the
drivers and edited their local tests.

The sqlite drivers failed on the insert, saying the table didn't exist;
the other drivers failed in various ways.

I didn't look into it, but based on the drivers not erroring I suppose it
was because they weren't committing changes after the CREATE TABLE
statement for some reason.

I really don't care particularly anymore though; I've abandoned any
attempt at using the sql interface for now.

~
Doug.
On Monday, April 8, 2013 7:39:50 PM UTC+8, Maxim Khitrov wrote:

What is the actual test that you're running and what is failing? My
SQLite library is happy to execute any valid query via Query() or
Exec(). I can't imagine why any driver would be inspecting the actual
sql string. What happens if you use the direct interface (sqlite3)
instead of the database/sql driver?
On Mon, Apr 8, 2013 at 4:27 AM, Dougx wrote:
hm.

from:
http://code.google.com/p/go-wiki/source/browse/SQLDrivers.wiki?repo=wiki
[ fails ] * *MySQL*: https://github.com/ziutek/mymysql `[*]`

[ fails ] * *MySQL*: https://github.com/Go-SQL-Driver/MySQL/ `[*]`

[ fails ] * *Postgres* (pure Go): https://github.com/bmizerany/pq`[*]`

[ fails ] * *SQLite*: https://github.com/mattn/go-sqlite3 `[*]`
[ fails ] * *SQLite*: http://code.google.com/p/go-sqlite/

I sort of gave up after that.

*shrug* I can see the problem, obviously, if you support INSERT in the query
statement, then you have to introspect over the sql content itself to see if
the statement is an INSERT or not, and select the id, contruct a fake rowset
to return, and return that instead.

...but the alternative is you have a Query() function that can only accept a
subset of sql, which is clearly broken.

Just saying; it looks like *no one* has got this right.

~
Doug.
On Monday, April 8, 2013 3:27:56 PM UTC+8, Kyle Lemons wrote:
On Sun, Apr 7, 2013 at 7:10 PM, Dougx wrote:

Indeed. However, from the documentation:

// Exec executes a query that doesn't return rows, such
// as an INSERT or UPDATE.
Exec(args []Value) (Result, error)

// Exec executes a query that may return rows, such as a
// SELECT.
Query(args []Value) (Rows, error)

see:
http://golang.org/pkg/database/sql/driver/

You can see how this might encourage people to make bad assumptions


(eg. Query will never perform an INSERT).

The documentation *should* state: Both query() and exec() MUST
accept and
execute any valid sql statement.
We're not in the business of writing legal contracts or RFCs here,
and I
think such a statement has no benefit being inserted there. If you
take a
look at the sql/driver documentation, there are much more in-depth
explanations about how a driver is expected to work and what
interfaces it's
expected to and can optionally implement. There may be buggy drivers
out
there, and I encourage you to bring such issues to their attention,
usually
via a bug report with a short reproducing example. There is a
database/sql
"integration test" which would also be a great place to look to see
what a
"golden implementation" is expected to do, and into which such tests
should
be added if it does not have such a test already.
~
Doug.
On Monday, April 8, 2013 9:52:56 AM UTC+8, Maxim Khitrov wrote:

On Sun, Apr 7, 2013 at 9:04 PM, Dougx <douglas...@gmail.com>
wrote:
How are you even supposed to run the query:

INSERT INTO PERSON (NAME) VALUES ('JACK') RETURNING ID_PERSON,
CREATION_TIME

Using the sql library? Do we use sql.Query() for this?
No~ because you can't use sql.Query() for insert statements for
some
I'm not familiar with this driver, but that doesn't sound like a
correct implementation. You should be able to run the same
statements
with Query() and Exec(). The only difference is the return value.
The
driver can also do some optimizations, such as releasing resources
early if it knows that the returned rows (if any) aren't needed. I
would expect your INSERT statement to work just fine with Query().
--
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.

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...@googlegroups.com.
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

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 18 of 20 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedApr 7, '13 at 2:29p
activeApr 12, '13 at 7:19p
posts20
users5
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase