sqlany

package module
v0.0.0-...-04d21f1 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2015 License: BSD-2-Clause Imports: 9 Imported by: 0

README

sqlago - Go driver for Sybase SQL Anywhere

sqlago driver is a wrapper over SQL Anywhere C API

Installation

go get github.com/a-palchikov/sqlago

Examples of use:

    package main
    
    import (
        _ "github.com/a-palchikov/sqlago"
        "database/sql"
        "log"
    )
    
    func main() {
        db, err := sql.Open("sqlany", "uid=dba;pwd=sql;eng=myengine")
        if err != nil {
            log.Fatalf("Unable to connect to db: %s", err)
        }
        // Run basic query
        var name string
        err = db.QueryRow("select name from users").Scan(&name)
        if err != nil {
            log.Fatalf("Select failed: %s", err)
        }
        // Run query with multiple return rows
        rows, err = db.Query("select version, product, uid from products")
        if err != nil {
            log.Fatalf("Select failed: %s", err)
        }
        for rows.Next() {
            var version float64
            var product, uid string
            err = rows.Scan(&version, &product, &uid)
            if err != nil {
                log.Fatalf("Select failed: %s", err)
            }
            log.Printf("version: %0.2f, product: %s, uid: %s", version, product, name)
        }
    }
Using prepared statements:
    func preparedQuery(db *sql.DB) {
        st, err := db.Prepare("select langid from language where name = :name")
        if err != nil {
            log.Fatalln("Failed to prepare statement", err)
        }
        defer st.Close()    // explicit Close() required for statements obtained with Prepare()
        langs := []string{"english", "chinese"}
        var langid int
        for _, v := range langs {
            st.QueryRow(v).Scan(&langid)
            if err != nil {
                // non-fatal
                log.Printf("Failed to retrieve language id for '%s': %s", v, err)
            }
            log.Println("Language id", langid)
        }
    }

Connection string

Connection string format is the format ubiquitously accepted by SQLA toolset:

attr1=value1;attr2=value2...

See http://dcx.sybase.com/index.html#1201/en/dbadmin/how-introduction-connect.html for detailed reference.

Testing

An accompanying boostrap_test.cmd batch file assumes SQL Anywhere 11 installation - edit it with the path to your installation in case it differs.

Invoke the bootstrap batch to create an empty database, followed by go test.

Caveats:

  • The implementation assumes Windows and has been only tested on Windows 7 Pro 64bit

Documentation

Index

Constants

View Source
const (
	API_VERSION_1     = 1
	API_VERSION_2     = 2
	SACAPI_ERROR_SIZE = 256
)
View Source
const (
	// do not reorder
	A_INVALID_TYPE dataType = iota // invalid data type
	A_BINARY                       // Binary data: treated as is (no conversions performed)
	A_STRING                       // String data: character set conversion performed
	A_DOUBLE
	A_VAL64 // 64bit ints
	A_UVAL64
	A_VAL32 // 32bit ints
	A_UVAL32
	A_VAL16 // words
	A_UVAL16
	A_VAL8 // bytes
	A_UVAL8
)
View Source
const (
	DT_NOTYPE       = 0
	DT_DATE         = 384
	DT_TIME         = 388
	DT_TIMESTAMP    = 392
	DT_VARCHAR      = 448
	DT_FIXCHAR      = 452
	DT_LONGVARCHAR  = 456
	DT_STRING       = 460
	DT_DOUBLE       = 480
	DT_FLOAT        = 482
	DT_DECIMAL      = 484
	DT_INT          = 496
	DT_SMALLINT     = 500
	DT_BINARY       = 524
	DT_LONGBINARY   = 528
	DT_TINYINT      = 604
	DT_BIGINT       = 608
	DT_UNSINT       = 612
	DT_UNSSMALLINT  = 616
	DT_UNSBIGINT    = 620
	DT_BIT          = 624
	DT_LONGNVARCHAR = 640
)
View Source
const (
	// do not reorder
	DD_INVALID      dataDirection = iota // Invalid data direction
	DD_INPUT                             // Input only host vars
	DD_OUTPUT                            // Output only host vars
	DD_INPUT_OUTPUT                      // Host vars of both directions
)

Variables

View Source
var (
	ErrNotSupported = errors.New("sqla: not supported")
)

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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