func (s *driverStmt) Exec(args []driver.Value) (driver.Result, error) {
	c := s.conn
	return driverExec(c.db, c.ctx, s.stmt, args)
}
Exec executes a query that doesn't return rows, such as an INSERT or UPDATE.
package ql
import (
	"bytes"
	"database/sql"
	"database/sql/driver"
	"errors"
	"fmt"
	"io"
	"math/big"
	"net/url"
	"os"
	"path/filepath"
	"strconv"
	"strings"
	"sync"
	"time"
)
var (
	_ driver.Conn    = (*driverConn)(nil)
	_ driver.Driver  = (*sqlDriver)(nil)
	_ driver.Execer  = (*driverConn)(nil)
	_ driver.Queryer = (*driverConn)(nil)
	_ driver.Result  = (*driverResult)(nil)
	_ driver.Rows    = (*driverRows)(nil)
	_ driver.Stmt    = (*driverStmt)(nil)
	_ driver.Tx      = (*driverConn)(nil)
	txBegin    = MustCompile("BEGIN TRANSACTION;")
	txCommit   = MustCompile("COMMIT;")
	txRollback = MustCompile("ROLLBACK;")
	errNoResult = errors.New("query statement does not produce a result set (no top level SELECT)")
)
type errList []error
func (e *errList) append(err error) {
	if err != nil {
		*e = append(*e, err)
	}
}
func (e errList) error() error {
	if len(e) == 0 {
		return nil
	}
	return e
}
func (e errList) Error() string {
	a := make([]string, len(e))
	for i, v := range e {
		a[i] = v.Error()
	}
	return strings.Join(a, "\n")
}
func params(args []driver.Value) []interface{} {
	r := make([]interface{}, len(args))
	for i, v := range args {
		r[i] = interface{}(v)
	}
	return r
}
var (
	fileDriver     = &sqlDriver{dbs: map[string]*driverDB{}}
	fileDriverOnce sync.Once
	memDriver      = &sqlDriver{isMem: true, dbs: map[string]*driverDB{}}
	memDriverOnce  sync.Once
)
func RegisterDriver() {
	fileDriverOnce.Do(func() { sql.Register("ql", fileDriver) })
}
func RegisterMemDriver() {
	memDriverOnce.Do(func() { sql.Register("ql-mem", memDriver) })
}
type driverDB struct {
	db       *DB
	name     string
	refcount int
}
func newDriverDB(db *DB, name string) *driverDB {
	return &driverDB{db: db, name: name, refcount: 1}
}
type sqlDriver struct {
	dbs   map[string]*driverDB
	isMem bool
	mu    sync.Mutex
}
func (d *sqlDriver) lock() func() {
	d.mu.Lock()
	return d.mu.Unlock
}
func (d *sqlDriver) Open(name string) (driver.Conn, error) {
	switch {
	case d == fileDriver:
		if !strings.Contains(name, "://") && !strings.HasPrefix(name, "file") {
			name = "file://" + name
		}
	case d == memDriver:
		if !strings.Contains(name, "://") && !strings.HasPrefix(name, "memory") {
			name = "memory://" + name
		}
	default:
		return nil, fmt.Errorf("open: unexpected/unsupported instance of driver.Driver: %p", d)
	}
	name = filepath.ToSlash(name)  
	uri, err := url.Parse(name)
	if err != nil {
		return nil, err
	}
	switch uri.Scheme {
	case "file":
	case "memory":
		d = memDriver
	default:
		return nil, fmt.Errorf("open: unexpected/unsupported scheme: %s", uri.Scheme)
	}
	name = filepath.Clean(filepath.Join(uri.Host, uri.Path))
	if d == fileDriver && (name == "" || name == "." || name == string(os.PathSeparator)) {
		return nil, fmt.Errorf("invalid DB name %q", name)
	}
	var headroom int64
	if a := uri.Query()["headroom"]; len(a) != 0 {
		if headroom, err = strconv.ParseInt(a[0], 10, 64); err != nil {
			return nil, err
		}
	}
	defer d.lock()()
	db := d.dbs[name]
	if db == nil {
		var err error
		var db0 *DB
		switch d.isMem {
		case true:
			db0, err = OpenMem()
		default:
			db0, err = OpenFile(name, &Options{CanCreate: true, Headroom: headroom})
		}
		if err != nil {
			return nil, err
		}
		db = newDriverDB(db0, name)
		d.dbs[name] = db
		return newDriverConn(d, db), nil
	}
	db.refcount++
	return newDriverConn(d, db), nil
}
type driverConn struct {
	ctx    *TCtx
	db     *driverDB
	driver *sqlDriver
	stop   map[*driverStmt]struct{}
	tnl    int
}
func newDriverConn(d *sqlDriver, ddb *driverDB) driver.Conn {
	r := &driverConn{
		db:     ddb,
		driver: d,
		stop:   map[*driverStmt]struct{}{},
	}
	return r
}
func (c *driverConn) Prepare(query string) (driver.Stmt, error) {
	list, err := Compile(query)
	if err != nil {
		return nil, err
	}
	s := &driverStmt{conn: c, stmt: list}
	c.stop[s] = struct{}{}
	return s, nil
}
func (c *driverConn) Close() error {
	var err errList
	for s := range c.stop {
		err.append(s.Close())
	}
	defer c.driver.lock()()
	dbs, name := c.driver.dbs, c.db.name
	v := dbs[name]
	v.refcount--
	if v.refcount == 0 {
		err.append(c.db.db.Close())
		delete(dbs, name)
	}
	return err.error()
}
func (c *driverConn) Begin() (driver.Tx, error) {
	if c.ctx == nil {
		c.ctx = NewRWCtx()
	}
	if _, _, err := c.db.db.Execute(c.ctx, txBegin); err != nil {
		return nil, err
	}
	c.tnl++
	return c, nil
}
func (c *driverConn) Commit() error {
	if c.tnl == 0 || c.ctx == nil {
		return errCommitNotInTransaction
	}
	if _, _, err := c.db.db.Execute(c.ctx, txCommit); err != nil {
		return err
	}
	c.tnl--
	if c.tnl == 0 {
		c.ctx = nil
	}
	return nil
}
func (c *driverConn) Rollback() error {
	if c.tnl == 0 || c.ctx == nil {
		return errRollbackNotInTransaction
	}
	if _, _, err := c.db.db.Execute(c.ctx, txRollback); err != nil {
		return err
	}
	c.tnl--
	if c.tnl == 0 {
		c.ctx = nil
	}
	return nil
}
func (c *driverConn) Exec(query string, args []driver.Value) (driver.Result, error) {
	list, err := Compile(query)
	if err != nil {
		return nil, err
	}
	return driverExec(c.db, c.ctx, list, args)
}
func driverExec(db *driverDB, ctx *TCtx, list List, args []driver.Value) (driver.Result, error) {
	if _, _, err := db.db.Execute(ctx, list, params(args)...); err != nil {
		return nil, err
	}
	if len(list.l) == 1 {
		switch list.l[0].(type) {
		case *createTableStmt, *dropTableStmt, *alterTableAddStmt,
			*alterTableDropColumnStmt, *truncateTableStmt:
			return driver.ResultNoRows, nil
		}
	}
	r := &driverResult{}
	if ctx != nil {
		r.lastInsertID, r.rowsAffected = ctx.LastInsertID, ctx.RowsAffected
	}
	return r, nil
}
func (c *driverConn) Query(query string, args []driver.Value) (driver.Rows, error) {
	list, err := Compile(query)
	if err != nil {
		return nil, err
	}
	return driverQuery(c.db, c.ctx, list, args)
}
func driverQuery(db *driverDB, ctx *TCtx, list List, args []driver.Value) (driver.Rows, error) {
	rss, _, err := db.db.Execute(ctx, list, params(args)...)
	if err != nil {
		return nil, err
	}
	switch n := len(rss); n {
	case 0:
		return nil, errNoResult
	default:
		return newDriverMultiRows(rss), nil
	}
}
type driverResult struct {
	lastInsertID int64
	rowsAffected int64
}
func (r *driverResult) LastInsertId() (int64, error) {  
	return r.lastInsertID, nil
}
func (r *driverResult) RowsAffected() (int64, error) {
	return r.rowsAffected, nil
}
type driverRows struct {
	rs   Recordset
	done chan int
	rows chan interface{}
}
func newdriverRows(rs Recordset) *driverRows {
	r := &driverRows{
		rs:   rs,
		done: make(chan int),
		rows: make(chan interface{}, 500),
	}
	go func() {
		err := io.EOF
		if e := r.rs.Do(false, func(data []interface{}) (bool, error) {
			select {
			case r.rows <- data:
				return true, nil
			case <-r.done:
				return false, nil
			}
		}); e != nil {
			err = e
		}
		select {
		case r.rows <- err:
		case <-r.done:
		}
	}()
	return r
}
func (r *driverRows) Columns() []string {
	f, _ := r.rs.Fields()
	return f
}
func (r *driverRows) Close() error {
	close(r.done)
	return nil
}
func (r *driverRows) Next(dest []driver.Value) error {
	select {
	case rx := <-r.rows:
		switch x := rx.(type) {
		case error:
			return x
		case []interface{}:
			if g, e := len(x), len(dest); g != e {
				return fmt.Errorf("field count mismatch: got %d, need %d", g, e)
			}
			for i, xi := range x {
				switch v := xi.(type) {
				case nil, int64, float64, bool, []byte, time.Time:
					dest[i] = v
				case complex64, complex128, *big.Int, *big.Rat, idealComplex:
					var buf bytes.Buffer
					fmt.Fprintf(&buf, "%v", v)
					dest[i] = buf.Bytes()
				case int8:
					dest[i] = int64(v)
				case int16:
					dest[i] = int64(v)
				case int32:
					dest[i] = int64(v)
				case int:
					dest[i] = int64(v)
				case uint8:
					dest[i] = int64(v)
				case uint16:
					dest[i] = int64(v)
				case uint32:
					dest[i] = int64(v)
				case uint64:
					dest[i] = int64(v)
				case uint:
					dest[i] = int64(v)
				case time.Duration:
					dest[i] = int64(v)
				case string:
					dest[i] = []byte(v)
				case idealInt:
					dest[i] = int64(v)
				case idealUint:
					dest[i] = int64(v)
				case idealFloat:
					dest[i] = float64(v)
				default:
					return fmt.Errorf("internal error 004")
				}
			}
			return nil
		default:
			return fmt.Errorf("internal error 005")
		}
	case <-r.done:
		return io.EOF
	}
}
type driverMultiRows struct {
	rs     []Recordset
	pos    int
	active *driverRows
}
func newDriverMultiRows(rs []Recordset) *driverMultiRows {
	return &driverMultiRows{
		rs:     rs,
		active: newdriverRows(rs[0]),
	}
}
func (r *driverMultiRows) Columns() []string {
	return r.active.Columns()
}
func (r *driverMultiRows) Close() error {
	return r.active.Close()
}
func (r *driverMultiRows) HasNextResultSet() bool {
	return r.pos+1 < len(r.rs)
}
func (r *driverMultiRows) NextResultSet() error {
	if r.HasNextResultSet() {
		r.active.Close()
		r.pos++
		r.active = newdriverRows(r.rs[r.pos])
		return nil
	}
	return io.EOF
}
func (r *driverMultiRows) Next(dest []driver.Value) error {
	return r.active.Next(dest)
}
type driverStmt struct {
	conn *driverConn
	stmt List
}
func (s *driverStmt) Close() error {
	delete(s.conn.stop, s)
	return nil
}
func (s *driverStmt) NumInput() int {
	if x := s.stmt; len(x.l) == 1 {
		return x.params
	}
	return -1
}