godbc

package module
v0.0.0-...-e3ee821 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2015 License: BSD-2-Clause Imports: 7 Imported by: 0

README

ODBC database driver for Go

Install:

go get github.com/creack/godbc

Example:

package main

import (
	"log"

	"github.com/creack/godbc"
)

func main() {
	conn, err := godbc.Connect("DSN=dsn;UID=user;PWD=password")
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close()

	stmt, err := conn.Prepare("SELECT * FROM user WHERE username = ?")
	if err != nil {
		log.Fatal(err)
	}
	defer stmt.Close()

	if err := stmt.Execute("admin"); err != nil {
		log.Fatal(err)
	}

	rows, err := stmt.FetchAll()
	if err != nil {
		log.Fatal(err)
	}
	for i, row := range rows {
		println(i, row)
	}
}

Tested on:

  • SQL Server 2005 and Windows 7
  • SQL Server 2005 and Ubuntu 10.4 (UnixODBC+FreeTDS)
  • Oracle 10g and Windows 7
  • Vertica 6.2 (UnixODBC)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Genv C.SQLHANDLE
)

Functions

func FormatError

func FormatError(ht C.SQLSMALLINT, h C.SQLHANDLE) error

func StringToUTF16

func StringToUTF16(s string) []uint16

StringToUTF16 returns the UTF-16 encoding of the UTF-8 string s, with a terminating NUL added.

func StringToUTF16Ptr

func StringToUTF16Ptr(s string) *uint16

StringToUTF16Ptr returns pointer to the UTF-16 encoding of the UTF-8 string s, with a terminating NUL added.

func Success

func Success(ret C.SQLRETURN) bool

func UTF16ToString

func UTF16ToString(s []uint16) string

UTF16ToString returns the UTF-8 encoding of the UTF-16 sequence s, with a terminating NUL removed.

Types

type Connection

type Connection struct {
	Dbc C.SQLHANDLE
	// contains filtered or unexported fields
}

func Connect

func Connect(dsn string, params ...interface{}) (*Connection, error)

func (*Connection) AutoCommit

func (conn *Connection) AutoCommit(b bool) error

func (*Connection) BeginTransaction

func (conn *Connection) BeginTransaction() error

func (*Connection) ClientInfo

func (conn *Connection) ClientInfo() (driverName string, odbcVersion string, driverVersion string, err error)

ClientInfo fetch info regarding the client's driver.

func (*Connection) Close

func (conn *Connection) Close() error

func (*Connection) Commit

func (conn *Connection) Commit() error

func (*Connection) ExecDirect

func (conn *Connection) ExecDirect(sql string) (*Statement, error)

func (*Connection) Prepare

func (conn *Connection) Prepare(sql string, params ...interface{}) (*Statement, error)

func (*Connection) Rollback

func (conn *Connection) Rollback() error

func (*Connection) ServerInfo

func (conn *Connection) ServerInfo() (dbName, dbVersion, serverName string, err error)

ServerInfo fetch info regarding the underlying database server

type Error

type Error struct {
	SQLState     string
	NativeError  int
	ErrorMessage string
}

func (*Error) Error

func (e *Error) Error() string

func (*Error) String

func (e *Error) String() string

type Field

type Field struct {
	Name          string
	Type          int
	Size          int
	DecimalDigits int
	Nullable      int
}

type Row

type Row struct {
	Data []interface{}
}

func (*Row) Get

func (r *Row) Get(a interface{}) interface{}

Get (Columnindex) TODO: Get(ColumnName)

func (*Row) GetFloat

func (r *Row) GetFloat(a interface{}) float64

func (*Row) GetInt

func (r *Row) GetInt(a interface{}) (ret int64)

func (*Row) GetString

func (r *Row) GetString(a interface{}) string

func (*Row) Length

func (r *Row) Length() int

type Statement

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

func (*Statement) BindParam

func (stmt *Statement) BindParam(index int, param interface{}) error

func (*Statement) Cancel

func (stmt *Statement) Cancel() error

func (*Statement) Close

func (stmt *Statement) Close()

func (*Statement) Execute

func (stmt *Statement) Execute(params ...interface{}) error

func (*Statement) Execute2

func (stmt *Statement) Execute2(params []driver.Value) error

func (*Statement) Fetch

func (stmt *Statement) Fetch() (bool, error)

func (*Statement) FetchAll

func (stmt *Statement) FetchAll() (rows []*Row, err error)

func (*Statement) FetchOne

func (stmt *Statement) FetchOne() (*Row, error)

func (*Statement) FetchOne2

func (stmt *Statement) FetchOne2(row []driver.Value) (eof bool, err error)

func (*Statement) FieldMetadata

func (stmt *Statement) FieldMetadata(col int) (*Field, error)

func (*Statement) GetField

func (stmt *Statement) GetField(fieldIndex int) (v interface{}, ftype int, flen int, err error)

GetField .

func (*Statement) GetParamType

func (stmt *Statement) GetParamType(index int) (int, int, int, int, error)

func (*Statement) HasRows

func (stmt *Statement) HasRows() bool

func (*Statement) NextResult

func (stmt *Statement) NextResult() bool

func (*Statement) NumFields

func (stmt *Statement) NumFields() (int, error)

func (*Statement) NumParams

func (stmt *Statement) NumParams() int

func (*Statement) NumRows

func (stmt *Statement) NumRows() (int, error)

func (*Statement) RowsAffected

func (stmt *Statement) RowsAffected() (int, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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