odbc

package
v0.0.0-...-82fa9ee Latest Latest
Warning

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

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

Documentation

Overview

Package odbc provides a ODBC database driver.

Example:

package main

import (
	"github.com/silvasur/go-odbc/odbc"
)

func main() {
	conn, _ := odbc.Connect("DSN=dsn;UID=user;PWD=password")
	stmt, _ := conn.Prepare("select * from user where username = ?")
	stmt.Execute("admin")
	rows, _ := stmt.FetchAll()
	for i, row := range rows {
		println(i, row)
	}
	stmt.Close()
	conn.Close()
}

Index

Constants

View Source
const (
	BUFFER_SIZE     = 10 * 1024
	INFO_BUFFER_LEN = 256
)

Variables

View Source
var (
	Genv C.SQLHANDLE
)

Functions

func Connect

func Connect(dsn string, params ...interface{}) (conn *Connection, err *ODBCError)

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 (*Connection) AutoCommit

func (conn *Connection) AutoCommit(b bool) (err *ODBCError)

func (*Connection) BeginTransaction

func (conn *Connection) BeginTransaction() (err *ODBCError)

func (*Connection) ClientInfo

func (conn *Connection) ClientInfo() (string, string, string, *ODBCError)

func (*Connection) Close

func (conn *Connection) Close() *ODBCError

func (*Connection) Commit

func (conn *Connection) Commit() (err *ODBCError)

func (*Connection) ExecDirect

func (conn *Connection) ExecDirect(sql string) (stmt *Statement, err *ODBCError)

func (*Connection) Prepare

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

func (*Connection) Rollback

func (conn *Connection) Rollback() (err *ODBCError)

func (*Connection) ServerInfo

func (conn *Connection) ServerInfo() (string, string, string, *ODBCError)

type Field

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

type ODBCError

type ODBCError struct {
	SQLState     string
	NativeError  int
	ErrorMessage string
}

func FormatError

func FormatError(ht C.SQLSMALLINT, h C.SQLHANDLE) (err *ODBCError)

func (*ODBCError) Error

func (e *ODBCError) Error() string

func (*ODBCError) String

func (e *ODBCError) String() string

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{}) (ret float64)

func (*Row) GetInt

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

func (*Row) GetString

func (r *Row) GetString(a interface{}) (ret 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{}) *ODBCError

func (*Statement) Cancel

func (stmt *Statement) Cancel() *ODBCError

func (*Statement) Close

func (stmt *Statement) Close()

func (*Statement) Execute

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

func (*Statement) Execute2

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

func (*Statement) Fetch

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

func (*Statement) FetchAll

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

func (*Statement) FetchOne

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

func (*Statement) FetchOne2

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

func (*Statement) FieldMetadata

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

func (*Statement) GetField

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

func (*Statement) GetParamType

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

func (*Statement) HasRows

func (stmt *Statement) HasRows() bool

func (*Statement) NextResult

func (stmt *Statement) NextResult() bool

func (*Statement) NumFields

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

func (*Statement) NumParams

func (stmt *Statement) NumParams() int

func (*Statement) NumRows

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

func (*Statement) RowsAffected

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

Directories

Path Synopsis
Package driver provides a driver for database/sql.
Package driver provides a driver for database/sql.

Jump to

Keyboard shortcuts

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