GithubHelp home page GithubHelp logo

sqlago's Introduction

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

sqlago's People

Contributors

a-palchikov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.