You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1521 lines
44 KiB

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#375EAB">
<title>sql - The Go Programming Language</title>
<link type="text/css" rel="stylesheet" href="../../../lib/godoc/style.css">
<link rel="stylesheet" href="../../../lib/godoc/jquery.treeview.css">
<script type="text/javascript">window.initFuncs = [];</script>
</head>
<body>
<div id='lowframe' style="position: fixed; bottom: 0; left: 0; height: 0; width: 100%; border-top: thin solid grey; background-color: white; overflow: auto;">
...
</div><!-- #lowframe -->
<div id="topbar" class="wide"><div class="container">
<div class="top-heading" id="heading-wide"><a href="http://localhost:6060/">The Go Programming Language</a></div>
<div class="top-heading" id="heading-narrow"><a href="http://localhost:6060/">Go</a></div>
<a href="index.html#" id="menu-button"><span id="menu-button-arrow">&#9661;</span></a>
<form method="GET" action="http://localhost:6060/search">
<div id="menu">
<a href="http://localhost:6060/doc/">Documents</a>
<a href="http://localhost:6060/pkg/">Packages</a>
<a href="http://localhost:6060/project/">The Project</a>
<a href="http://localhost:6060/help/">Help</a>
<a href="http://localhost:6060/blog/">Blog</a>
<input type="text" id="search" name="q" class="inactive" value="Search" placeholder="Search">
</div>
</form>
</div></div>
<div id="page" class="wide">
<div class="container">
<h1>Package sql</h1>
<div id="nav"></div>
<!--
Copyright 2009 The Go Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
-->
<!--
Note: Static (i.e., not template-generated) href and id
attributes start with "pkg-" to make it impossible for
them to conflict with generated attributes (some of which
correspond to Go identifiers).
-->
<script type='text/javascript'>
document.ANALYSIS_DATA = null;
document.CALLGRAPH = null;
</script>
<div id="short-nav">
<dl>
<dd><code>import "database/sql"</code></dd>
</dl>
<dl>
<dd><a href="index.html#pkg-overview" class="overviewLink">Overview</a></dd>
<dd><a href="index.html#pkg-index" class="indexLink">Index</a></dd>
<dd><a href="index.html#pkg-examples" class="examplesLink">Examples</a></dd>
<dd><a href="index.html#pkg-subdirectories">Subdirectories</a></dd>
</dl>
</div>
<!-- The package's Name is printed as title by the top-level template -->
<div id="pkg-overview" class="toggleVisible">
<div class="collapsed">
<h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2>
</div>
<div class="expanded">
<h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2>
<p>
Package sql provides a generic interface around SQL (or SQL-like)
databases.
</p>
<p>
The sql package must be used in conjunction with a database driver.
See <a href="https://golang.org/s/sqldrivers">https://golang.org/s/sqldrivers</a> for a list of drivers.
</p>
<p>
For more usage examples, see the wiki page at
<a href="https://golang.org/s/sqlwiki">https://golang.org/s/sqlwiki</a>.
</p>
</div>
</div>
<div id="pkg-index" class="toggleVisible">
<div class="collapsed">
<h2 class="toggleButton" title="Click to show Index section">Index ▹</h2>
</div>
<div class="expanded">
<h2 class="toggleButton" title="Click to hide Index section">Index ▾</h2>
<!-- Table of contents for API; must be named manual-nav to turn off auto nav. -->
<div id="manual-nav">
<dl>
<dd><a href="index.html#pkg-variables">Variables</a></dd>
<dd><a href="index.html#Drivers">func Drivers() []string</a></dd>
<dd><a href="index.html#Register">func Register(name string, driver driver.Driver)</a></dd>
<dd><a href="index.html#DB">type DB</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Open">func Open(driverName, dataSourceName string) (*DB, error)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#DB.Begin">func (db *DB) Begin() (*Tx, error)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#DB.Close">func (db *DB) Close() error</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#DB.Driver">func (db *DB) Driver() driver.Driver</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#DB.Exec">func (db *DB) Exec(query string, args ...interface{}) (Result, error)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#DB.Ping">func (db *DB) Ping() error</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#DB.Prepare">func (db *DB) Prepare(query string) (*Stmt, error)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#DB.Query">func (db *DB) Query(query string, args ...interface{}) (*Rows, error)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#DB.QueryRow">func (db *DB) QueryRow(query string, args ...interface{}) *Row</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#DB.SetConnMaxLifetime">func (db *DB) SetConnMaxLifetime(d time.Duration)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#DB.SetMaxIdleConns">func (db *DB) SetMaxIdleConns(n int)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#DB.SetMaxOpenConns">func (db *DB) SetMaxOpenConns(n int)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#DB.Stats">func (db *DB) Stats() DBStats</a></dd>
<dd><a href="index.html#DBStats">type DBStats</a></dd>
<dd><a href="index.html#NullBool">type NullBool</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#NullBool.Scan">func (n *NullBool) Scan(value interface{}) error</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#NullBool.Value">func (n NullBool) Value() (driver.Value, error)</a></dd>
<dd><a href="index.html#NullFloat64">type NullFloat64</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#NullFloat64.Scan">func (n *NullFloat64) Scan(value interface{}) error</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#NullFloat64.Value">func (n NullFloat64) Value() (driver.Value, error)</a></dd>
<dd><a href="index.html#NullInt64">type NullInt64</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#NullInt64.Scan">func (n *NullInt64) Scan(value interface{}) error</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#NullInt64.Value">func (n NullInt64) Value() (driver.Value, error)</a></dd>
<dd><a href="index.html#NullString">type NullString</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#NullString.Scan">func (ns *NullString) Scan(value interface{}) error</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#NullString.Value">func (ns NullString) Value() (driver.Value, error)</a></dd>
<dd><a href="index.html#RawBytes">type RawBytes</a></dd>
<dd><a href="index.html#Result">type Result</a></dd>
<dd><a href="index.html#Row">type Row</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Row.Scan">func (r *Row) Scan(dest ...interface{}) error</a></dd>
<dd><a href="index.html#Rows">type Rows</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rows.Close">func (rs *Rows) Close() error</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rows.Columns">func (rs *Rows) Columns() ([]string, error)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rows.Err">func (rs *Rows) Err() error</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rows.Next">func (rs *Rows) Next() bool</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Rows.Scan">func (rs *Rows) Scan(dest ...interface{}) error</a></dd>
<dd><a href="index.html#Scanner">type Scanner</a></dd>
<dd><a href="index.html#Stmt">type Stmt</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Stmt.Close">func (s *Stmt) Close() error</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Stmt.Exec">func (s *Stmt) Exec(args ...interface{}) (Result, error)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Stmt.Query">func (s *Stmt) Query(args ...interface{}) (*Rows, error)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Stmt.QueryRow">func (s *Stmt) QueryRow(args ...interface{}) *Row</a></dd>
<dd><a href="index.html#Tx">type Tx</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Tx.Commit">func (tx *Tx) Commit() error</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Tx.Exec">func (tx *Tx) Exec(query string, args ...interface{}) (Result, error)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Tx.Prepare">func (tx *Tx) Prepare(query string) (*Stmt, error)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Tx.Query">func (tx *Tx) Query(query string, args ...interface{}) (*Rows, error)</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Tx.QueryRow">func (tx *Tx) QueryRow(query string, args ...interface{}) *Row</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Tx.Rollback">func (tx *Tx) Rollback() error</a></dd>
<dd>&nbsp; &nbsp; <a href="index.html#Tx.Stmt">func (tx *Tx) Stmt(stmt *Stmt) *Stmt</a></dd>
</dl>
</div><!-- #manual-nav -->
<div id="pkg-examples">
<h4>Examples</h4>
<dl>
<dd><a class="exampleLink" href="index.html#example_DB_Query">DB.Query</a></dd>
<dd><a class="exampleLink" href="index.html#example_DB_QueryRow">DB.QueryRow</a></dd>
</dl>
</div>
<h4>Package files</h4>
<p>
<span style="font-size:90%">
<a href="http://localhost:6060/src/database/sql/convert.go">convert.go</a>
<a href="http://localhost:6060/src/database/sql/sql.go">sql.go</a>
</span>
</p>
</div><!-- .expanded -->
</div><!-- #pkg-index -->
<div id="pkg-callgraph" class="toggle" style="display: none">
<div class="collapsed">
<h2 class="toggleButton" title="Click to show Internal Call Graph section">Internal call graph ▹</h2>
</div> <!-- .expanded -->
<div class="expanded">
<h2 class="toggleButton" title="Click to hide Internal Call Graph section">Internal call graph ▾</h2>
<p>
In the call graph viewer below, each node
is a function belonging to this package
and its children are the functions it
calls&mdash;perhaps dynamically.
</p>
<p>
The root nodes are the entry points of the
package: functions that may be called from
outside the package.
There may be non-exported or anonymous
functions among them if they are called
dynamically from another package.
</p>
<p>
Click a node to visit that function's source code.
From there you can visit its callers by
clicking its declaring <code>func</code>
token.
</p>
<p>
Functions may be omitted if they were
determined to be unreachable in the
particular programs or tests that were
analyzed.
</p>
<!-- Zero means show all package entry points. -->
<ul style="margin-left: 0.5in" id="callgraph-0" class="treeview"></ul>
</div>
</div> <!-- #pkg-callgraph -->
<h2 id="pkg-variables">Variables</h2>
<pre>var <span id="ErrNoRows">ErrNoRows</span> = <a href="../../errors/index.html">errors</a>.<a href="../../errors/index.html#New">New</a>(&#34;sql: no rows in result set&#34;)</pre>
<p>
ErrNoRows is returned by Scan when QueryRow doesn&#39;t return a
row. In such a case, QueryRow returns a placeholder *Row value that
defers this error until a Scan.
</p>
<pre>var <span id="ErrTxDone">ErrTxDone</span> = <a href="../../errors/index.html">errors</a>.<a href="../../errors/index.html#New">New</a>(&#34;sql: Transaction has already been committed or rolled back&#34;)</pre>
<h2 id="Drivers">func <a href="http://localhost:6060/src/database/sql/sql.go?s=1388:1411#L48">Drivers</a></h2>
<pre>func Drivers() []<a href="../../builtin/index.html#string">string</a></pre>
<p>
Drivers returns a sorted list of the names of the registered drivers.
</p>
<h2 id="Register">func <a href="http://localhost:6060/src/database/sql/sql.go?s=902:950#L28">Register</a></h2>
<pre>func Register(name <a href="../../builtin/index.html#string">string</a>, driver <a href="driver/index.html">driver</a>.<a href="driver/index.html#Driver">Driver</a>)</pre>
<p>
Register makes a database driver available by the provided name.
If Register is called twice with the same name or if driver is nil,
it panics.
</p>
<h2 id="DB">type <a href="http://localhost:6060/src/database/sql/sql.go?s=5829:6970#L214">DB</a></h2>
<pre>type DB struct {
<span class="comment">// contains filtered or unexported fields</span>
}</pre>
<p>
DB is a database handle representing a pool of zero or more
underlying connections. It&#39;s safe for concurrent use by multiple
goroutines.
</p>
<p>
The sql package creates and frees connections automatically; it
also maintains a free pool of idle connections. If the database has
a concept of per-connection state, such state can only be reliably
observed within a transaction. Once DB.Begin is called, the
returned Tx is bound to a single connection. Once Commit or
Rollback is called on the transaction, that transaction&#39;s
connection is returned to DB&#39;s idle connection pool. The pool size
can be controlled with SetMaxIdleConns.
</p>
<h3 id="Open">func <a href="http://localhost:6060/src/database/sql/sql.go?s=13549:13606#L470">Open</a></h3>
<pre>func Open(driverName, dataSourceName <a href="../../builtin/index.html#string">string</a>) (*<a href="index.html#DB">DB</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
<p>
Open opens a database specified by its database driver name and a
driver-specific data source name, usually consisting of at least a
database name and connection information.
</p>
<p>
Most users will open a database via a driver-specific connection
helper function that returns a *DB. No database drivers are included
in the Go standard library. See <a href="https://golang.org/s/sqldrivers">https://golang.org/s/sqldrivers</a> for
a list of third-party drivers.
</p>
<p>
Open may just validate its arguments without creating a connection
to the database. To verify that the data source name is valid, call
Ping.
</p>
<p>
The returned DB is safe for concurrent use by multiple goroutines
and maintains its own pool of idle connections. Thus, the Open
function should be called just once. It is rarely necessary to
close a DB.
</p>
<h3 id="DB.Begin">func (*DB) <a href="http://localhost:6060/src/database/sql/sql.go?s=30174:30208#L1138">Begin</a></h3>
<pre>func (db *<a href="index.html#DB">DB</a>) Begin() (*<a href="index.html#Tx">Tx</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
<p>
Begin starts a transaction. The isolation level is dependent on
the driver.
</p>
<h3 id="DB.Close">func (*DB) <a href="http://localhost:6060/src/database/sql/sql.go?s=14543:14570#L505">Close</a></h3>
<pre>func (db *<a href="index.html#DB">DB</a>) Close() <a href="../../builtin/index.html#error">error</a></pre>
<p>
Close closes the database, releasing any open resources.
</p>
<p>
It is rare to Close a DB, as the DB handle is meant to be
long-lived and shared between many goroutines.
</p>
<h3 id="DB.Driver">func (*DB) <a href="http://localhost:6060/src/database/sql/sql.go?s=30811:30847#L1173">Driver</a></h3>
<pre>func (db *<a href="index.html#DB">DB</a>) Driver() <a href="driver/index.html">driver</a>.<a href="driver/index.html#Driver">Driver</a></pre>
<p>
Driver returns the database&#39;s underlying driver.
</p>
<h3 id="DB.Exec">func (*DB) <a href="http://localhost:6060/src/database/sql/sql.go?s=26758:26827#L995">Exec</a></h3>
<pre>func (db *<a href="index.html#DB">DB</a>) Exec(query <a href="../../builtin/index.html#string">string</a>, args ...interface{}) (<a href="index.html#Result">Result</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
<p>
Exec executes a query without returning any rows.
The args are for any placeholder parameters in the query.
</p>
<h3 id="DB.Ping">func (*DB) <a href="http://localhost:6060/src/database/sql/sql.go?s=14098:14124#L489">Ping</a></h3>
<pre>func (db *<a href="index.html#DB">DB</a>) Ping() <a href="../../builtin/index.html#error">error</a></pre>
<p>
Ping verifies a connection to the database is still alive,
establishing a connection if necessary.
</p>
<h3 id="DB.Prepare">func (*DB) <a href="http://localhost:6060/src/database/sql/sql.go?s=25486:25536#L949">Prepare</a></h3>
<pre>func (db *<a href="index.html#DB">DB</a>) Prepare(query <a href="../../builtin/index.html#string">string</a>) (*<a href="index.html#Stmt">Stmt</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
<p>
Prepare creates a prepared statement for later queries or executions.
Multiple queries or executions may be run concurrently from the
returned statement.
The caller must call the statement&#39;s Close method
when the statement is no longer needed.
</p>
<h3 id="DB.Query">func (*DB) <a href="http://localhost:6060/src/database/sql/sql.go?s=27955:28024#L1047">Query</a></h3>
<pre>func (db *<a href="index.html#DB">DB</a>) Query(query <a href="../../builtin/index.html#string">string</a>, args ...interface{}) (*<a href="index.html#Rows">Rows</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
<p>
Query executes a query that returns rows, typically a SELECT.
The args are for any placeholder parameters in the query.
</p>
<div id="example_DB_Query" class="toggle">
<div class="collapsed">
<p class="exampleHeading toggleButton"><span class="text">Example</span></p>
</div>
<div class="expanded">
<p class="exampleHeading toggleButton"><span class="text">Example</span></p>
<p>Code:</p>
<pre class="code">
age := 27
rows, err := db.Query(&#34;SELECT name FROM users WHERE age=?&#34;, age)
if err != nil {
log.Fatal(err)
}
defer rows.Close()
for rows.Next() {
var name string
if err := rows.Scan(&amp;name); err != nil {
log.Fatal(err)
}
fmt.Printf(&#34;%s is %d\n&#34;, name, age)
}
if err := rows.Err(); err != nil {
log.Fatal(err)
}
</pre>
</div>
</div>
<h3 id="DB.QueryRow">func (*DB) <a href="http://localhost:6060/src/database/sql/sql.go?s=29950:30012#L1131">QueryRow</a></h3>
<pre>func (db *<a href="index.html#DB">DB</a>) QueryRow(query <a href="../../builtin/index.html#string">string</a>, args ...interface{}) *<a href="index.html#Row">Row</a></pre>
<p>
QueryRow executes a query that is expected to return at most one row.
QueryRow always returns a non-nil value. Errors are deferred until
Row&#39;s Scan method is called.
</p>
<div id="example_DB_QueryRow" class="toggle">
<div class="collapsed">
<p class="exampleHeading toggleButton"><span class="text">Example</span></p>
</div>
<div class="expanded">
<p class="exampleHeading toggleButton"><span class="text">Example</span></p>
<p>Code:</p>
<pre class="code">
id := 123
var username string
err := db.QueryRow(&#34;SELECT username FROM users WHERE id=?&#34;, id).Scan(&amp;username)
switch {
case err == sql.ErrNoRows:
log.Printf(&#34;No user with that ID.&#34;)
case err != nil:
log.Fatal(err)
default:
fmt.Printf(&#34;Username is %s\n&#34;, username)
}
</pre>
</div>
</div>
<h3 id="DB.SetConnMaxLifetime">func (*DB) <a href="http://localhost:6060/src/database/sql/sql.go?s=16957:17006#L608">SetConnMaxLifetime</a></h3>
<pre>func (db *<a href="index.html#DB">DB</a>) SetConnMaxLifetime(d <a href="../../time/index.html">time</a>.<a href="../../time/index.html#Duration">Duration</a>)</pre>
<p>
SetConnMaxLifetime sets the maximum amount of time a connection may be reused.
</p>
<p>
Expired connections may be closed lazily before reuse.
</p>
<p>
If d &lt;= 0, connections are reused forever.
</p>
<h3 id="DB.SetMaxIdleConns">func (*DB) <a href="http://localhost:6060/src/database/sql/sql.go?s=15641:15677#L557">SetMaxIdleConns</a></h3>
<pre>func (db *<a href="index.html#DB">DB</a>) SetMaxIdleConns(n <a href="../../builtin/index.html#int">int</a>)</pre>
<p>
SetMaxIdleConns sets the maximum number of connections in the idle
connection pool.
</p>
<p>
If MaxOpenConns is greater than 0 but less than the new MaxIdleConns
then the new MaxIdleConns will be reduced to match the MaxOpenConns limit
</p>
<p>
If n &lt;= 0, no idle connections are retained.
</p>
<h3 id="DB.SetMaxOpenConns">func (*DB) <a href="http://localhost:6060/src/database/sql/sql.go?s=16529:16565#L590">SetMaxOpenConns</a></h3>
<pre>func (db *<a href="index.html#DB">DB</a>) SetMaxOpenConns(n <a href="../../builtin/index.html#int">int</a>)</pre>
<p>
SetMaxOpenConns sets the maximum number of open connections to the database.
</p>
<p>
If MaxIdleConns is greater than 0 and the new MaxOpenConns is less than
MaxIdleConns, then MaxIdleConns will be reduced to match the new
MaxOpenConns limit
</p>
<p>
If n &lt;= 0, then there is no limit on the number of open connections.
The default is 0 (unlimited).
</p>
<h3 id="DB.Stats">func (*DB) <a href="http://localhost:6060/src/database/sql/sql.go?s=18606:18635#L688">Stats</a></h3>
<pre>func (db *<a href="index.html#DB">DB</a>) Stats() <a href="index.html#DBStats">DBStats</a></pre>
<p>
Stats returns database statistics.
</p>
<h2 id="DBStats">type <a href="http://localhost:6060/src/database/sql/sql.go?s=18451:18566#L682">DBStats</a></h2>
<pre>type DBStats struct {
<span class="comment">// OpenConnections is the number of open connections to the database.</span>
OpenConnections <a href="../../builtin/index.html#int">int</a>
}</pre>
<p>
DBStats contains database statistics.
</p>
<h2 id="NullBool">type <a href="http://localhost:6060/src/database/sql/sql.go?s=4055:4140#L155">NullBool</a></h2>
<pre>type NullBool struct {
Bool <a href="../../builtin/index.html#bool">bool</a>
Valid <a href="../../builtin/index.html#bool">bool</a> <span class="comment">// Valid is true if Bool is not NULL</span>
}</pre>
<p>
NullBool represents a bool that may be null.
NullBool implements the Scanner interface so
it can be used as a scan destination, similar to NullString.
</p>
<h3 id="NullBool.Scan">func (*NullBool) <a href="http://localhost:6060/src/database/sql/sql.go?s=4184:4232#L161">Scan</a></h3>
<pre>func (n *<a href="index.html#NullBool">NullBool</a>) Scan(value interface{}) <a href="../../builtin/index.html#error">error</a></pre>
<p>
Scan implements the Scanner interface.
</p>
<h3 id="NullBool.Value">func (NullBool) <a href="http://localhost:6060/src/database/sql/sql.go?s=4409:4456#L171">Value</a></h3>
<pre>func (n <a href="index.html#NullBool">NullBool</a>) Value() (<a href="driver/index.html">driver</a>.<a href="driver/index.html#Value">Value</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
<p>
Value implements the driver Valuer interface.
</p>
<h2 id="NullFloat64">type <a href="http://localhost:6060/src/database/sql/sql.go?s=3408:3506#L129">NullFloat64</a></h2>
<pre>type NullFloat64 struct {
Float64 <a href="../../builtin/index.html#float64">float64</a>
Valid <a href="../../builtin/index.html#bool">bool</a> <span class="comment">// Valid is true if Float64 is not NULL</span>
}</pre>
<p>
NullFloat64 represents a float64 that may be null.
NullFloat64 implements the Scanner interface so
it can be used as a scan destination, similar to NullString.
</p>
<h3 id="NullFloat64.Scan">func (*NullFloat64) <a href="http://localhost:6060/src/database/sql/sql.go?s=3550:3601#L135">Scan</a></h3>
<pre>func (n *<a href="index.html#NullFloat64">NullFloat64</a>) Scan(value interface{}) <a href="../../builtin/index.html#error">error</a></pre>
<p>
Scan implements the Scanner interface.
</p>
<h3 id="NullFloat64.Value">func (NullFloat64) <a href="http://localhost:6060/src/database/sql/sql.go?s=3780:3830#L145">Value</a></h3>
<pre>func (n <a href="index.html#NullFloat64">NullFloat64</a>) Value() (<a href="driver/index.html">driver</a>.<a href="driver/index.html#Value">Value</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
<p>
Value implements the driver Valuer interface.
</p>
<h2 id="NullInt64">type <a href="http://localhost:6060/src/database/sql/sql.go?s=2772:2860#L103">NullInt64</a></h2>
<pre>type NullInt64 struct {
Int64 <a href="../../builtin/index.html#int64">int64</a>
Valid <a href="../../builtin/index.html#bool">bool</a> <span class="comment">// Valid is true if Int64 is not NULL</span>
}</pre>
<p>
NullInt64 represents an int64 that may be null.
NullInt64 implements the Scanner interface so
it can be used as a scan destination, similar to NullString.
</p>
<h3 id="NullInt64.Scan">func (*NullInt64) <a href="http://localhost:6060/src/database/sql/sql.go?s=2904:2953#L109">Scan</a></h3>
<pre>func (n *<a href="index.html#NullInt64">NullInt64</a>) Scan(value interface{}) <a href="../../builtin/index.html#error">error</a></pre>
<p>
Scan implements the Scanner interface.
</p>
<h3 id="NullInt64.Value">func (NullInt64) <a href="http://localhost:6060/src/database/sql/sql.go?s=3128:3176#L119">Value</a></h3>
<pre>func (n <a href="index.html#NullInt64">NullInt64</a>) Value() (<a href="driver/index.html">driver</a>.<a href="driver/index.html#Value">Value</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
<p>
Value implements the driver Valuer interface.
</p>
<h2 id="NullString">type <a href="http://localhost:6060/src/database/sql/sql.go?s=2122:2215#L77">NullString</a></h2>
<pre>type NullString struct {
String <a href="../../builtin/index.html#string">string</a>
Valid <a href="../../builtin/index.html#bool">bool</a> <span class="comment">// Valid is true if String is not NULL</span>
}</pre>
<p>
NullString represents a string that may be null.
NullString implements the Scanner interface so
it can be used as a scan destination:
</p>
<pre>var s NullString
err := db.QueryRow(&#34;SELECT name FROM foo WHERE id=?&#34;, id).Scan(&amp;s)
...
if s.Valid {
// use s.String
} else {
// NULL value
}
</pre>
<h3 id="NullString.Scan">func (*NullString) <a href="http://localhost:6060/src/database/sql/sql.go?s=2259:2310#L83">Scan</a></h3>
<pre>func (ns *<a href="index.html#NullString">NullString</a>) Scan(value interface{}) <a href="../../builtin/index.html#error">error</a></pre>
<p>
Scan implements the Scanner interface.
</p>
<h3 id="NullString.Value">func (NullString) <a href="http://localhost:6060/src/database/sql/sql.go?s=2492:2542#L93">Value</a></h3>
<pre>func (ns <a href="index.html#NullString">NullString</a>) Value() (<a href="driver/index.html">driver</a>.<a href="driver/index.html#Value">Value</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
<p>
Value implements the driver Valuer interface.
</p>
<h2 id="RawBytes">type <a href="http://localhost:6060/src/database/sql/sql.go?s=1771:1791#L62">RawBytes</a></h2>
<pre>type RawBytes []<a href="../../builtin/index.html#byte">byte</a></pre>
<p>
RawBytes is a byte slice that holds a reference to memory owned by
the database itself. After a Scan into a RawBytes, the slice is only
valid until the next call to Next, Scan, or Close.
</p>
<h2 id="Result">type <a href="http://localhost:6060/src/database/sql/sql.go?s=50998:51504#L1924">Result</a></h2>
<pre>type Result interface {
<span class="comment">// LastInsertId returns the integer generated by the database</span>
<span class="comment">// in response to a command. Typically this will be from an</span>
<span class="comment">// &#34;auto increment&#34; column when inserting a new row. Not all</span>
<span class="comment">// databases support this feature, and the syntax of such</span>
<span class="comment">// statements varies.</span>
LastInsertId() (<a href="../../builtin/index.html#int64">int64</a>, <a href="../../builtin/index.html#error">error</a>)
<span class="comment">// RowsAffected returns the number of rows affected by an</span>
<span class="comment">// update, insert, or delete. Not every database or database</span>
<span class="comment">// driver may support this.</span>
RowsAffected() (<a href="../../builtin/index.html#int64">int64</a>, <a href="../../builtin/index.html#error">error</a>)
}</pre>
<p>
A Result summarizes an executed SQL command.
</p>
<h2 id="Row">type <a href="http://localhost:6060/src/database/sql/sql.go?s=49261:49378#L1869">Row</a></h2>
<pre>type Row struct {
<span class="comment">// contains filtered or unexported fields</span>
}</pre>
<p>
Row is the result of calling QueryRow to select a single row.
</p>
<h3 id="Row.Scan">func (*Row) <a href="http://localhost:6060/src/database/sql/sql.go?s=49664:49709#L1880">Scan</a></h3>
<pre>func (r *<a href="index.html#Row">Row</a>) Scan(dest ...interface{}) <a href="../../builtin/index.html#error">error</a></pre>
<p>
Scan copies the columns from the matched row into the values
pointed at by dest. See the documentation on Rows.Scan for details.
If more than one row matches the query,
Scan uses the first row and discards the rest. If no row matches
the query, Scan returns ErrNoRows.
</p>
<h2 id="Rows">type <a href="http://localhost:6060/src/database/sql/sql.go?s=44282:44598#L1723">Rows</a></h2>
<pre>type Rows struct {
<span class="comment">// contains filtered or unexported fields</span>
}</pre>
<p>
Rows is the result of a query. Its cursor starts before the first row
of the result set. Use Next to advance through the rows:
</p>
<pre>rows, err := db.Query(&#34;SELECT ...&#34;)
...
defer rows.Close()
for rows.Next() {
var id int
var name string
err = rows.Scan(&amp;id, &amp;name)
...
}
err = rows.Err() // get any error encountered during iteration
...
</pre>
<h3 id="Rows.Close">func (*Rows) <a href="http://localhost:6060/src/database/sql/sql.go?s=48946:48975#L1852">Close</a></h3>
<pre>func (rs *<a href="index.html#Rows">Rows</a>) Close() <a href="../../builtin/index.html#error">error</a></pre>
<p>
Close closes the Rows, preventing further enumeration. If Next returns
false, the Rows are closed automatically and it will suffice to check the
result of Err. Close is idempotent and does not affect the result of Err.
</p>
<h3 id="Rows.Columns">func (*Rows) <a href="http://localhost:6060/src/database/sql/sql.go?s=45584:45627#L1767">Columns</a></h3>
<pre>func (rs *<a href="index.html#Rows">Rows</a>) Columns() ([]<a href="../../builtin/index.html#string">string</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
<p>
Columns returns the column names.
Columns returns an error if the rows are closed, or if the rows
are from QueryRow and there was a deferred error.
</p>
<h3 id="Rows.Err">func (*Rows) <a href="http://localhost:6060/src/database/sql/sql.go?s=45332:45359#L1757">Err</a></h3>
<pre>func (rs *<a href="index.html#Rows">Rows</a>) Err() <a href="../../builtin/index.html#error">error</a></pre>
<p>
Err returns the error, if any, that was encountered during iteration.
Err may be called after an explicit or implicit Close.
</p>
<h3 id="Rows.Next">func (*Rows) <a href="http://localhost:6060/src/database/sql/sql.go?s=44935:44962#L1740">Next</a></h3>
<pre>func (rs *<a href="index.html#Rows">Rows</a>) Next() <a href="../../builtin/index.html#bool">bool</a></pre>
<p>
Next prepares the next result row for reading with the Scan method. It
returns true on success, or false if there is no next result row or an error
happened while preparing it. Err should be consulted to distinguish between
the two cases.
</p>
<p>
Every call to Scan, even the first one, must be preceded by a call to Next.
</p>
<h3 id="Rows.Scan">func (*Rows) <a href="http://localhost:6060/src/database/sql/sql.go?s=48150:48197#L1828">Scan</a></h3>
<pre>func (rs *<a href="index.html#Rows">Rows</a>) Scan(dest ...interface{}) <a href="../../builtin/index.html#error">error</a></pre>
<p>
Scan copies the columns in the current row into the values pointed
at by dest. The number of values in dest must be the same as the
number of columns in Rows.
</p>
<p>
Scan converts columns read from the database into the following
common Go types and special types provided by the sql package:
</p>
<pre>*string
*[]byte
*int, *int8, *int16, *int32, *int64
*uint, *uint8, *uint16, *uint32, *uint64
*bool
*float32, *float64
*interface{}
*RawBytes
any type implementing Scanner (see Scanner docs)
</pre>
<p>
In the most simple case, if the type of the value from the source
column is an integer, bool or string type T and dest is of type *T,
Scan simply assigns the value through the pointer.
</p>
<p>
Scan also converts between string and numeric types, as long as no
information would be lost. While Scan stringifies all numbers
scanned from numeric database columns into *string, scans into
numeric types are checked for overflow. For example, a float64 with
value 300 or a string with value &#34;300&#34; can scan into a uint16, but
not into a uint8, though float64(255) or &#34;255&#34; can scan into a
uint8. One exception is that scans of some float64 numbers to
strings may lose information when stringifying. In general, scan
floating point columns into *float64.
</p>
<p>
If a dest argument has type *[]byte, Scan saves in that argument a
copy of the corresponding data. The copy is owned by the caller and
can be modified and held indefinitely. The copy can be avoided by
using an argument of type *RawBytes instead; see the documentation
for RawBytes for restrictions on its use.
</p>
<p>
If an argument has type *interface{}, Scan copies the value
provided by the underlying driver without conversion. When scanning
from a source value of type []byte to *interface{}, a copy of the
slice is made and the caller owns the result.
</p>
<p>
Source values of type time.Time may be scanned into values of type
*time.Time, *interface{}, *string, or *[]byte. When converting to
the latter two, time.Format3339Nano is used.
</p>
<p>
Source values of type bool may be scanned into types *bool,
*interface{}, *string, *[]byte, or *RawBytes.
</p>
<p>
For scanning into *bool, the source may be true, false, 1, 0, or
string inputs parseable by strconv.ParseBool.
</p>
<h2 id="Scanner">type <a href="http://localhost:6060/src/database/sql/sql.go?s=4559:4942#L179">Scanner</a></h2>
<pre>type Scanner interface {
<span class="comment">// Scan assigns a value from a database driver.</span>
<span class="comment">//</span>
<span class="comment">// The src value will be of one of the following types:</span>
<span class="comment">//</span>
<span class="comment">// int64</span>
<span class="comment">// float64</span>
<span class="comment">// bool</span>
<span class="comment">// []byte</span>
<span class="comment">// string</span>
<span class="comment">// time.Time</span>
<span class="comment">// nil - for NULL values</span>
<span class="comment">//</span>
<span class="comment">// An error should be returned if the value can not be stored</span>
<span class="comment">// without loss of information.</span>
Scan(src interface{}) <a href="../../builtin/index.html#error">error</a>
}</pre>
<p>
Scanner is an interface used by Scan.
</p>
<h2 id="Stmt">type <a href="http://localhost:6060/src/database/sql/sql.go?s=36980:37778#L1418">Stmt</a></h2>
<pre>type Stmt struct {
<span class="comment">// contains filtered or unexported fields</span>
}</pre>
<p>
Stmt is a prepared statement.
A Stmt is safe for concurrent use by multiple goroutines.
</p>
<h3 id="Stmt.Close">func (*Stmt) <a href="http://localhost:6060/src/database/sql/sql.go?s=43295:43323#L1672">Close</a></h3>
<pre>func (s *<a href="index.html#Stmt">Stmt</a>) Close() <a href="../../builtin/index.html#error">error</a></pre>
<p>
Close closes the statement.
</p>
<h3 id="Stmt.Exec">func (*Stmt) <a href="http://localhost:6060/src/database/sql/sql.go?s=37908:37964#L1446">Exec</a></h3>
<pre>func (s *<a href="index.html#Stmt">Stmt</a>) Exec(args ...interface{}) (<a href="index.html#Result">Result</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
<p>
Exec executes a prepared statement with the given arguments and
returns a Result summarizing the effect of the statement.
</p>
<h3 id="Stmt.Query">func (*Stmt) <a href="http://localhost:6060/src/database/sql/sql.go?s=41189:41245#L1587">Query</a></h3>
<pre>func (s *<a href="index.html#Stmt">Stmt</a>) Query(args ...interface{}) (*<a href="index.html#Rows">Rows</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
<p>
Query executes a prepared query statement with the given arguments
and returns the query results as a *Rows.
</p>
<h3 id="Stmt.QueryRow">func (*Stmt) <a href="http://localhost:6060/src/database/sql/sql.go?s=43109:43158#L1663">QueryRow</a></h3>
<pre>func (s *<a href="index.html#Stmt">Stmt</a>) QueryRow(args ...interface{}) *<a href="index.html#Row">Row</a></pre>
<p>
QueryRow executes a prepared query statement with the given arguments.
If an error occurs during the execution of the statement, that error will
be returned by a call to Scan on the returned *Row, which is always non-nil.
If the query selects no rows, the *Row&#39;s Scan will return ErrNoRows.
Otherwise, the *Row&#39;s Scan scans the first selected row and discards
the rest.
</p>
<p>
Example usage:
</p>
<pre>var name string
err := nameByUseridStmt.QueryRow(id).Scan(&amp;name)
</pre>
<h2 id="Tx">type <a href="http://localhost:6060/src/database/sql/sql.go?s=31234:31711#L1187">Tx</a></h2>
<pre>type Tx struct {
<span class="comment">// contains filtered or unexported fields</span>
}</pre>
<p>
Tx is an in-progress database transaction.
</p>
<p>
A transaction must end with a call to Commit or Rollback.
</p>
<p>
After a call to Commit or Rollback, all operations on the
transaction fail with ErrTxDone.
</p>
<p>
The statements prepared for a transaction by calling
the transaction&#39;s Prepare or Stmt methods are closed
by the call to Commit or Rollback.
</p>
<h3 id="Tx.Commit">func (*Tx) <a href="http://localhost:6060/src/database/sql/sql.go?s=32289:32317#L1237">Commit</a></h3>
<pre>func (tx *<a href="index.html#Tx">Tx</a>) Commit() <a href="../../builtin/index.html#error">error</a></pre>
<p>
Commit commits the transaction.
</p>
<h3 id="Tx.Exec">func (*Tx) <a href="http://localhost:6060/src/database/sql/sql.go?s=35514:35583#L1359">Exec</a></h3>
<pre>func (tx *<a href="index.html#Tx">Tx</a>) Exec(query <a href="../../builtin/index.html#string">string</a>, args ...interface{}) (<a href="index.html#Result">Result</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
<p>
Exec executes a query that doesn&#39;t return rows.
For example: an INSERT and UPDATE.
</p>
<h3 id="Tx.Prepare">func (*Tx) <a href="http://localhost:6060/src/database/sql/sql.go?s=33035:33085#L1272">Prepare</a></h3>
<pre>func (tx *<a href="index.html#Tx">Tx</a>) Prepare(query <a href="../../builtin/index.html#string">string</a>) (*<a href="index.html#Stmt">Stmt</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
<p>
Prepare creates a prepared statement for use within a transaction.
</p>
<p>
The returned statement operates within the transaction and can no longer
be used once the transaction has been committed or rolled back.
</p>
<p>
To use an existing prepared statement on this transaction, see Tx.Stmt.
</p>
<h3 id="Tx.Query">func (*Tx) <a href="http://localhost:6060/src/database/sql/sql.go?s=36223:36292#L1393">Query</a></h3>
<pre>func (tx *<a href="index.html#Tx">Tx</a>) Query(query <a href="../../builtin/index.html#string">string</a>, args ...interface{}) (*<a href="index.html#Rows">Rows</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
<p>
Query executes a query that returns rows, typically a SELECT.
</p>
<h3 id="Tx.QueryRow">func (*Tx) <a href="http://localhost:6060/src/database/sql/sql.go?s=36622:36684#L1405">QueryRow</a></h3>
<pre>func (tx *<a href="index.html#Tx">Tx</a>) QueryRow(query <a href="../../builtin/index.html#string">string</a>, args ...interface{}) *<a href="index.html#Row">Row</a></pre>
<p>
QueryRow executes a query that is expected to return at most one row.
QueryRow always returns a non-nil value. Errors are deferred until
Row&#39;s Scan method is called.
</p>
<h3 id="Tx.Rollback">func (*Tx) <a href="http://localhost:6060/src/database/sql/sql.go?s=32531:32561#L1252">Rollback</a></h3>
<pre>func (tx *<a href="index.html#Tx">Tx</a>) Rollback() <a href="../../builtin/index.html#error">error</a></pre>
<p>
Rollback aborts the transaction.
</p>
<h3 id="Tx.Stmt">func (*Tx) <a href="http://localhost:6060/src/database/sql/sql.go?s=34663:34699#L1325">Stmt</a></h3>
<pre>func (tx *<a href="index.html#Tx">Tx</a>) Stmt(stmt *<a href="index.html#Stmt">Stmt</a>) *<a href="index.html#Stmt">Stmt</a></pre>
<p>
Stmt returns a transaction-specific prepared statement from
an existing statement.
</p>
<p>
Example:
</p>
<pre>updateMoney, err := db.Prepare(&#34;UPDATE balance SET money=money+? WHERE id=?&#34;)
...
tx, err := db.Begin()
...
res, err := tx.Stmt(updateMoney).Exec(123.45, 98293203)
</pre>
<p>
The returned statement operates within the transaction and can no longer
be used once the transaction has been committed or rolled back.
</p>
<h2 id="pkg-subdirectories">Subdirectories</h2>
<div class="pkg-dir">
<table>
<tr>
<th class="pkg-name">Name</th>
<th class="pkg-synopsis">Synopsis</th>
</tr>
<tr>
<td colspan="2"><a href="../index.html">..</a></td>
</tr>
<tr>
<td class="pkg-name" style="padding-left: 0px;">
<a href="driver/index.html">driver</a>
</td>
<td class="pkg-synopsis">
Package driver defines interfaces to be implemented by database drivers as used by package sql.
</td>
</tr>
</table>
</div>
<div id="footer">
Build version go1.6.<br>
Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
the content of this page is licensed under the
Creative Commons Attribution 3.0 License,
and code is licensed under a <a href="http://localhost:6060/LICENSE">BSD license</a>.<br>
<a href="http://localhost:6060/doc/tos.html">Terms of Service</a> |
<a href="http://www.google.com/intl/en/policies/privacy/">Privacy Policy</a>
</div>
</div><!-- .container -->
</div><!-- #page -->
<!-- TODO(adonovan): load these from <head> using "defer" attribute? -->
<script type="text/javascript" src="../../../lib/godoc/jquery.js"></script>
<script type="text/javascript" src="../../../lib/godoc/jquery.treeview.js"></script>
<script type="text/javascript" src="../../../lib/godoc/jquery.treeview.edit.js"></script>
<script type="text/javascript" src="../../../lib/godoc/godocs.js"></script>
</body>
</html>