godb2

package module
v0.0.0-...-2887cfa Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

README

go-db2 - Pure Go DB2 Driver

A pure Go database driver for IBM DB2 that implements the database/sql interface without any CGO dependencies.

Features

  • ✅ Pure Go implementation (no CGO required)
  • ✅ Implements database/sql/driver interface
  • ✅ DRDA protocol support for DB2
  • ✅ Connection pooling support
  • ✅ Context support for cancellation
  • ✅ Prepared statements
  • ✅ Transactions
  • ✅ Named parameters

Installation

go get github.com/obaydullahmhs/go-db2

Usage

package main

import (
    "database/sql"
    _ "github.com/obaydullahmhs/go-db2"
)

func main() {
    db, err := sql.Open("db2", "hostname=localhost;port=50000;database=SAMPLE;uid=db2inst1;pwd=password")
    if err != nil {
        panic(err)
    }
    defer db.Close()

    // Use db...
}

Connection String Format

hostname=<host>;port=<port>;database=<dbname>;uid=<username>;pwd=<password>[;options...]
Available Options
  • hostname - Database server hostname (required)
  • port - Database server port (default: 50000)
  • database - Database name (required)
  • uid - Username (required)
  • pwd - Password (required)
  • timeout - Connection timeout in seconds (default: 30)
  • ssl - Enable SSL (true/false, default: false)

Architecture

This driver implements the DRDA (Distributed Relational Database Architecture) protocol used by DB2 for client-server communication. The implementation is organized as follows:

  • driver.go - Driver registration and main entry point
  • connection.go - Connection management
  • statement.go - Prepared statement implementation
  • rows.go - Result set handling
  • transaction.go - Transaction support
  • protocol/ - DRDA protocol implementation
  • types/ - DB2 data type conversions

Status

🚧 Work in Progress - This is a foundational implementation.

Credits

This driver is inspired by and converted from go_ibm_db but implemented as a pure Go driver without CGO dependencies.

Documentation

Overview

Package godb2 implements a pure Go database/sql driver for IBM DB2. This driver uses the DRDA protocol to communicate with DB2 servers without requiring any CGO dependencies.

Index

Constants

View Source
const (
	// Version is the current version of the go-db2 driver
	Version = "0.1.0"

	// DriverName is the name used to register the driver
	DriverName = "db2"

	// ProtocolVersion is the DRDA protocol version supported
	ProtocolVersion = "DRDA Version 5"
)

Variables

This section is empty.

Functions

func FormatDSN

func FormatDSN(hostname, database, username, password string, port int) string

FormatDSN creates a DSN string from individual components.

func GetVersion

func GetVersion() map[string]string

GetVersion returns the driver version information

func ParseDSN

func ParseDSN(dsn string) (hostname, database, username, password string, port int, err error)

ParseDSN is a public wrapper around parseDSN for external use.

func ValidateDSN

func ValidateDSN(dsn string) error

ValidateDSN validates a connection string and returns helpful error messages.

Types

type Config

type Config struct {
	Hostname string
	Port     int
	Database string
	Username string
	Password string
	Timeout  time.Duration
	SSL      bool
}

Config holds the configuration for a DB2 connection.

type Driver

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

Driver implements the database/sql/driver.Driver interface.

func (*Driver) Open

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

Open returns a new connection to the database. The dsn is a connection string in the format: hostname=localhost;port=50000;database=SAMPLE;uid=db2inst1;pwd=password

type Error

type Error struct {
	SQLCode    int32
	SQLState   string
	Message    string
	ServerName string
}

Error represents a DB2 error.

func NewError

func NewError(sqlCode int32, sqlState, message string) *Error

NewError creates a new DB2 error.

func (*Error) Error

func (e *Error) Error() string

Error returns the error message.

Directories

Path Synopsis
examples
advanced command
basic command
demo command
Package protocol implements the DRDA (Distributed Relational Database Architecture) protocol for communicating with IBM DB2 servers.
Package protocol implements the DRDA (Distributed Relational Database Architecture) protocol for communicating with IBM DB2 servers.
Package types provides DB2 data type conversions between Go and DB2 types.
Package types provides DB2 data type conversions between Go and DB2 types.

Jump to

Keyboard shortcuts

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