firebirdsql

package module
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2021 License: MIT Imports: 39 Imported by: 0

README

======================================
firebirdsql (Go firebird sql driver)
======================================

Firebird RDBMS https://firebirdsql.org SQL driver for Go

Requirements
-------------

* Firebird 2.5 or higher
* Golang 1.15 or higher

Example
-------------

::

   package main

   import (
       "fmt"
       "database/sql"
       _ "github.com/nakagami/firebirdsql"
   )

   func main() {
       var n int
       conn, _ := sql.Open("firebirdsql", "user:password@servername/foo/bar.fdb")
       defer conn.Close()
       conn.QueryRow("SELECT Count(*) FROM rdb$relations").Scan(&n)
       fmt.Println("Relations count=", n)

   }


See also driver_test.go

::

   package main

      import (
       "fmt"
       "github.com/nakagami/firebirdsql"
   )

   func main() {
       dsn := "user:password@servername/foo/bar.fdb"
       events := []string{"my_event", "order_created"}
       fbEvent, _ := firebirdsql.NewFBEvent(dsn)
       defer fbEvent.Close()
       sbr, _ := fbEvent.Subscribe(events, func(event firebirdsql.Event) { //or use SubscribeChan
           fmt.Printf("event: %s, count: %d, id: %d, remote id:%d \n", event.Name, event.Count, event.ID, event.RemoteID)
       })
       defer sbr.Unsubscribe()
       go func() {
               fbEvent.PostEvent(events[0])
               fbEvent.PostEvent(events[1])
       }()
       <- make(chan struct{}) //wait
   }

See also _example

Connection string
--------------------------

::

   user:password@servername[:port_number]/database_name_or_file[?params1=value1[&param2=value2]...]


General
=========

- user: login user
- password: login password
- servername: Firebird server's host name or IP address.
- port_number: Port number. default value is 3050.
- database_name_or_file: Database path (or alias name).

Optional
=========

param1, param2... are

.. csv-table::
   :header: Name,Description,Default,Note

   auth_plugin_name,Authentication plugin name.,Srp,Srp256/Srp/Legacy_Auth are available.
   column_name_to_lower,Force column name to lower,false,For "github.com/jmoiron/sqlx"
   role,Role name,
   timezone, Time Zone name,, For Firebird 4.0+
   wire_crypt,Enable wire data encryption or not.,true,For Firebird 3.0+
   charset, Firebird Charecter Set,

Documentation

Overview

Package firebird provides database/sql driver for Firebird RDBMS.

Index

Constants

View Source
const (
	ISC_TIME_SECONDS_PRECISION = 10000

	// Protocol Version
	PROTOCOL_VERSION13 = 13

	CNCT_user              = 1
	CNCT_passwd            = 2
	CNCT_host              = 4
	CNCT_group             = 5
	CNCT_user_verification = 6
	CNCT_specific_data     = 7
	CNCT_plugin_name       = 8
	CNCT_login             = 9
	CNCT_plugin_list       = 10
	CNCT_client_crypt      = 11
)
View Source
const (
	ISOLATION_LEVEL_READ_COMMITED_LEGACY = iota
	ISOLATION_LEVEL_READ_COMMITED
	ISOLATION_LEVEL_REPEATABLE_READ
	ISOLATION_LEVEL_SERIALIZABLE
	ISOLATION_LEVEL_READ_COMMITED_RO
)
View Source
const (
	SRP_KEY_SIZE      = 128
	SRP_SALT_SIZE     = 32
	DEBUG_PRIVATE_KEY = "60975527035CF2AD1989806F0407210BC81EDC04E2762A56AFD529DDDA2D4393"
	DEBUG_SRP         = false
)
View Source
const (
	PLUGIN_LIST       = "Srp256,Srp,Legacy_Auth"
	BUFFER_LEN        = 1024
	MAX_CHAR_LENGTH   = 32767
	BLOB_SEGMENT_SIZE = 32000
)
View Source
const (
	SQL_TYPE_TEXT         = 452
	SQL_TYPE_VARYING      = 448
	SQL_TYPE_SHORT        = 500
	SQL_TYPE_LONG         = 496
	SQL_TYPE_FLOAT        = 482
	SQL_TYPE_DOUBLE       = 480
	SQL_TYPE_D_FLOAT      = 530
	SQL_TYPE_TIMESTAMP    = 510
	SQL_TYPE_BLOB         = 520
	SQL_TYPE_ARRAY        = 540
	SQL_TYPE_QUAD         = 550
	SQL_TYPE_TIME         = 560
	SQL_TYPE_DATE         = 570
	SQL_TYPE_INT64        = 580
	SQL_TYPE_INT128       = 32752
	SQL_TYPE_TIMESTAMP_TZ = 32754
	SQL_TYPE_TIME_TZ      = 32756
	SQL_TYPE_DEC_FIXED    = 32758
	SQL_TYPE_DEC64        = 32760
	SQL_TYPE_DEC128       = 32762
	SQL_TYPE_BOOLEAN      = 32764
	SQL_TYPE_NULL         = 32766
)
View Source
const (
	EPB_version1 = 1
)

Event

Variables

View Source
var (
	ErrAlreadySubscribe = errors.New("already subscribe")
	ErrFbEventClosed    = errors.New("fbevent already closed")
)

Errors

View Source
var (
	ErrEventAlreadyRunning = errors.New("events are already running")
	ErrEventNeed           = errors.New("at least one event is needed")
	ErrWrongLengthEvent    = errors.New("length name events are longer than 255")
	ErrEventBufferLarge    = errors.New("whole events buffer is bigger than 65535")
)
View Source
var ErrDsnUserUnknown = errors.New("User unknown")
View Source
var ErrOpSqlResponse = errors.New("Error op_sql_response")

Functions

func NewErrOpResonse

func NewErrOpResonse(opRCode int32) error

Error interface implementation

Types

type ErrOpResponse

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

ErrOpResponse operation request error

func (*ErrOpResponse) Error

func (e *ErrOpResponse) Error() string

type Event

type Event struct {
	Name     string
	Count    int
	ID       int32
	RemoteID int32
}

Event stores event data: the amount since the last time the event was received and id

type EventHandler

type EventHandler func(e Event)

EventHandler callback function type

type FbEvent

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

FbEvent allows you to subscribe to events, also stores subscribers. It is possible to send events to the database.

func NewFBEvent

func NewFBEvent(dsns string) (*FbEvent, error)

NewFBEvent returns FbEvent for event subscription

func (*FbEvent) Close

func (e *FbEvent) Close() error

Close closes FbEvent and all subscribers

func (*FbEvent) Count

func (e *FbEvent) Count() int

Count returns the number of subscribers

func (*FbEvent) IsClosed

func (e *FbEvent) IsClosed() bool

IsClosed returns a close flag

func (*FbEvent) PostEvent

func (e *FbEvent) PostEvent(name string) error

PostEvent posts an event to the database

func (*FbEvent) Subscribe

func (e *FbEvent) Subscribe(events []string, cb EventHandler) (*Subscription, error)

Subscribe subscribe to events using the callback function

func (*FbEvent) SubscribeChan

func (e *FbEvent) SubscribeChan(events []string, chEvent chan Event) (*Subscription, error)

SubscribeChan subscribe to events using the channel

func (*FbEvent) Subscribers

func (e *FbEvent) Subscribers() []*Subscription

Subscribers returns slice of all subscribers

type Subscription

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

func (*Subscription) Close

func (s *Subscription) Close() error

func (*Subscription) IsClose

func (s *Subscription) IsClose() bool

func (*Subscription) NotifyClose

func (s *Subscription) NotifyClose(receiver chan error)

func (*Subscription) Unsubscribe

func (s *Subscription) Unsubscribe() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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