odb

package module
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 13, 2022 License: BSD-2-Clause Imports: 17 Imported by: 0

README

Go Reference

Compiled for amd64.

License

Use of this source code is governed by a BSD-2-Clause license that can be found in the LICENSE file.

BSD-2-Clause License

Documentation

Index

Examples

Constants

View Source
const (
	Default_port = 2799

	// Queries with this prefix will be executed and not prepared
	// The prefix is removed
	Execute_prefix = `odbexecute`

	// Special odbtp query. Use in QueryContext().
	// https://docs.microsoft.com/en-us/sql/odbc/reference/develop-app/catalog-functions-in-odbc
	Sql_get_type_info = Execute_prefix + "||SQLGetTypeInfo"
	Sql_tables        = Execute_prefix + "||SQLTables|||"
	Sql_columns       = Execute_prefix + "||SQLColumns|||" // must append "<table>", and optional "|column"

)
View Source
const (
	Normal   Login = C.ODB_LOGIN_NORMAL
	Reserved       = C.ODB_LOGIN_RESERVED
	Single         = C.ODB_LOGIN_SINGLE
)
View Source
const (
	// Example in query: {{.id}} becomes sql.Named("id", <value>)
	Prepare_is_template bool_option = 1 << iota * -1 // ODB_ATTR are positive

	// Zero_scan will cause Stmt.Scan() to return go zero values in place of nil
	// for database null
	Zero_scan

	// http://odbtp.sourceforge.net/clilib.html#attributes
	Cache_procs     = C.ODB_ATTR_CACHEPROCS
	Mapchar2wchar   = C.ODB_ATTR_MAPCHARTOWCHAR
	Describe_params = C.ODB_ATTR_DESCRIBEPARAMS
	Unicodesql      = C.ODB_ATTR_UNICODESQL
	Right_trim_text = C.ODB_ATTR_RIGHTTRIMTEXT
)
View Source
const (
	Query_timeout int_option = C.ODB_ATTR_QUERYTIMEOUT
	Vardatasize              = C.ODB_ATTR_VARDATASIZE
)

Variables

View Source
var (
	// string or []byte input parameter to be set to database null
	Ns *string

	// int64 input parameter to be set to database null
	Ni *int64

	// float64 input parameter to be set to database null
	Nf *float64

	// bool input parameter to be set to database null
	Nb *bool

	// time.Time input parameter to be set to database null
	Nt *time.Time
)

Functions

func Bool_opt

func Bool_opt(opt bool_option, enable bool) option

func Debug

func Debug(w io.Writer) option

func Get_sql_type

func Get_sql_type(i int16) string

Used with Sql_get_type_info query DATA_TYPE column

func Int_opt

func Int_opt(opt int_option, i uint64) option

func Register

func Register(address string, login Login, odbc_dsn string, opt ...option) (driver_name string)

Returns the registered driver name to use in sql.Open(). The driver name pattern is odbtp_msaccess_1, odbtp_msaccess_2, odbtp_msaccess_...

Example
package main

import (
	"database/sql"
	"fmt"

	"github.com/aletheia7/odb"
)

func main() {
	// Returns the registered driver name to use in sql.Open(). The driver name pattern is
	// odbtp_msaccess_1, odbtp_msaccess_...
	driver_name := odb.Register(
		"<host_name>",
		odb.Normal,
		`DRIVER=Microsoft Access Driver (*.mdb);DBQ=c:/<file path to mdb>;ImplicitCommitSync=Yes`,
		odb.Int_opt(odb.Query_timeout, 20),
		odb.Bool_opt(odb.Unicodesql, true),
		odb.Bool_opt(odb.Describe_params, true),
		odb.Bool_opt(odb.Mapchar2wchar, true),
		odb.Bool_opt(odb.Prepare_is_template, true),
	)
	db, err := sql.Open(driver_name, ``)
	if err != nil {
		fmt.Print(err)
		return
	}
	defer db.Close()
}
Output:

Types

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

func (*Conn) Begin

func (o *Conn) Begin() (driver.Tx, error)

func (*Conn) BeginTx

func (o *Conn) BeginTx(ctx context.Context, opts driver.TxOptions) (tx driver.Tx, err error)

msaccess: sql.LevelReadCommitted or sql.LevelDefault (usually none)

func (*Conn) CheckNamedValue

func (o *Conn) CheckNamedValue(nv *driver.NamedValue) (err error)

func (*Conn) Close

func (o *Conn) Close() error

func (*Conn) Commit

func (o *Conn) Commit() (err error)

func (*Conn) Exec

func (o *Conn) Exec(args []driver.Value) (dr driver.Result, err error)

func (*Conn) ExecContext

func (o *Conn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (dr driver.Result, err error)

msaccess: Must add an Identity_table arg to call LastInsertId()

func (*Conn) Ping

func (o *Conn) Ping(ctx context.Context) (err error)

func (*Conn) Prepare

func (o *Conn) Prepare(query string) (ds driver.Stmt, err error)

func (*Conn) PrepareContext

func (o *Conn) PrepareContext(ctx context.Context, query string) (ds driver.Stmt, err error)

func (*Conn) Query

func (o *Conn) Query(args []driver.Value) (dr driver.Rows, err error)

func (*Conn) QueryContext

func (o *Conn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (dr driver.Rows, err error)

func (*Conn) ResetSession

func (o *Conn) ResetSession(ctx context.Context) (err error)

func (*Conn) Rollback

func (o *Conn) Rollback() (err error)

type Driver

type Driver struct {
	// contains filtered or unexported fields
}

func (*Driver) Open

func (o *Driver) Open(dsn string) (driver.Conn, error)

dsn is not used. Use Register()

type Err added in v0.2.1

type Err struct {
	I    int
	Text string
}

func (Err) Error added in v0.2.1

func (o Err) Error() string

func (Err) Unwrap added in v0.2.1

func (o Err) Unwrap() error

type Identity_table

type Identity_table string

Used with msaccess. See ExecContext()

type Login

type Login C.odbUSHORT

type Rows

type Rows struct {
	*Stmt
}

func (*Rows) Close

func (o *Rows) Close() error

type Stmt

type Stmt struct {
	// contains filtered or unexported fields
}

func (*Stmt) CheckNamedValue

func (o *Stmt) CheckNamedValue(nv *driver.NamedValue) (err error)

func (*Stmt) Close

func (o *Stmt) Close() error

func (*Stmt) Columns

func (o *Stmt) Columns() (s []string)

func (*Stmt) Exec

func (o *Stmt) Exec(args []driver.Value) (dr driver.Result, err error)

func (*Stmt) ExecContext

func (o *Stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (dr driver.Result, err error)

msaccess: Must add an Identity_table arg to call LastInsertId()

func (*Stmt) LastInsertId

func (o *Stmt) LastInsertId() (id int64, err error)

Only usefull with msaccess

func (*Stmt) Next

func (o *Stmt) Next(dest []driver.Value) (err error)

func (*Stmt) NumInput

func (o *Stmt) NumInput() int

func (*Stmt) Query

func (o *Stmt) Query(args []driver.Value) (dr driver.Rows, err error)

func (*Stmt) QueryContext

func (o *Stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (dr driver.Rows, err error)

func (*Stmt) RowsAffected

func (o *Stmt) RowsAffected() (i int64, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL