]> Cypherpunks repositories - gostls13.git/commit
database/sql: allow using a single connection from the database
authorDaniel Theophanes <kardianos@gmail.com>
Thu, 13 Apr 2017 23:04:40 +0000 (16:04 -0700)
committerDaniel Theophanes <kardianos@gmail.com>
Mon, 24 Apr 2017 17:03:05 +0000 (17:03 +0000)
commitd234f9a75413fdae7643e4be9471b4aeccf02478
treefc47ce249f3ba3dc2ec6efc985bc40ff3daa894a
parent42c5f3993b0c2e45b6665ee6011b8a0e347aa0c3
database/sql: allow using a single connection from the database

Databases have the following concepts: Statement, Batch, and Session.

A statement is often a single line like:
SELECT Amount from Account where ID = 50;

A batch is one or more statements submitted together for the query
to process. It may be a DELETE, INSERT, two UPDATES and a SELECT in
a single query text.

A session is usually represented by a single database connection.
This often is an issue when dealing with scopes in databases.
Temporary tables and variables can have batch, session, or global
scope depending on the syntax, database, and use.

Furthermore, some databases (sybase and derivatives in perticular)
that prevent certain statements from being in the same batch
and may necessitate being in the same session.

By allowing users to extract a Conn from the database they can manage
session on their own without hacking around it by making connection
pools of single connections (a real workaround presented in issue).
It is tempting to just use a transaction, but this isn't always
desirable or an option if running an interactive session or
alter script set that itself starts transactions.

Fixes #18081

Change-Id: I9bdf0796632c48d4bcaef3624c629641984ffaf2
Reviewed-on: https://go-review.googlesource.com/40694
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/database/sql/sql.go
src/database/sql/sql_test.go