Skip to content

Commit

Permalink
Merge pull request #1 from nakagami/master
Browse files Browse the repository at this point in the history
update tu upstream version
  • Loading branch information
ajoses authored Mar 7, 2019
2 parents 466c214 + 24d3cc1 commit edec3c8
Show file tree
Hide file tree
Showing 23 changed files with 1,620 additions and 368 deletions.
14 changes: 10 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ Installation

$ go get github.com/cznic/mathutil
$ go get github.com/kardianos/osext
$ go get github.com/nyarla/go-crypt
$ go get github.com/shopspring/decimal
$ go get github.com/nakagami/firebirdsql
$ go get gitlab.com/nyarla/go-crypt


Example
Expand Down Expand Up @@ -71,6 +72,11 @@ Optional

param1, param2... are

- role: Role name.
- auth_plugin_name: Authentication plugin name for FB3. Srp or Legacy_Auth are available. Default is Srp.
- wire_crypt: Enable wire data encryption or not. It is for FB3 server. Default is true.
.. 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,
tzname, Time Zone name, For Firebird 4.0+
wire_crypt,Enable wire data encryption or not.,true,For Firebird 3.0+
2 changes: 1 addition & 1 deletion attic/errmsgs.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Software distributed under the License is distributed on an\n\
\"AS IS\" basis, WITHOUT WARRANTY OF ANY KIND, either express\n\
or implied. See the License for the specific language governing\n\
rights and limitations under the License.\n\n\
*****************************************************************************/\n");
*****************************************************************************/\n\n");
fprintf(fp, "package firebirdsql\n\nvar errmsgs = map[int]string{\n");
for (i = 0; messages[i].code_text; i++) {
fprintf(fp, "\t%ld: \"%s\\n\",\n", messages[i].code_number, messages[i].code_text);
Expand Down
74 changes: 51 additions & 23 deletions connection.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*******************************************************************************
The MIT License (MIT)
Copyright (c) 2013-2016 Hajime Nakagami
Copyright (c) 2013-2019 Hajime Nakagami
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand All @@ -24,22 +24,23 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package firebirdsql

import (
"context"
"database/sql/driver"
"math/big"

"context"
)

type firebirdsqlConn struct {
wp *wireProtocol
tx *firebirdsqlTx
addr string
dbName string
user string
password string
isAutocommit bool
clientPublic *big.Int
clientSecret *big.Int
wp *wireProtocol
tx *firebirdsqlTx
addr string
dbName string
user string
password string
columnNameToLower bool
isAutocommit bool
clientPublic *big.Int
clientSecret *big.Int
transactionSet map[*firebirdsqlTx]struct{}
}

func (fc *firebirdsqlConn) begin(isolationLevel int) (driver.Tx, error) {
Expand All @@ -53,6 +54,10 @@ func (fc *firebirdsqlConn) Begin() (driver.Tx, error) {
}

func (fc *firebirdsqlConn) Close() (err error) {
for tx, _ := range fc.transactionSet {
tx.Rollback()
}

fc.wp.opDetach()
_, _, _, err = fc.wp.opResponse()
fc.wp.conn.Close()
Expand All @@ -68,16 +73,25 @@ func (fc *firebirdsqlConn) Prepare(query string) (driver.Stmt, error) {
}

func (fc *firebirdsqlConn) exec(ctx context.Context, query string, args []driver.Value) (result driver.Result, err error) {

if fc.tx.needBegin {
err = fc.tx.begin()
if err != nil {
return
}
}

stmt, err := fc.prepare(ctx, query)
if err != nil {
return
}

result, err = stmt.(*firebirdsqlStmt).exec(ctx, args)
if err != nil {
return
}
if fc.isAutocommit && fc.tx.isAutocommit {
fc.tx.Commit()
fc.tx.commitRetainging()
}
stmt.Close()
return
Expand All @@ -101,69 +115,83 @@ func (fc *firebirdsqlConn) Query(query string, args []driver.Value) (rows driver
}

func newFirebirdsqlConn(dsn string) (fc *firebirdsqlConn, err error) {
addr, dbName, user, password, role, authPluginName, wireCrypt, err := parseDSN(dsn)
wp, err := newWireProtocol(addr)
addr, dbName, user, password, options, err := parseDSN(dsn)

wp, err := newWireProtocol(addr, options["timezone"])
if err != nil {
return
}

column_name_to_lower := convertToBool(options["column_name_to_lower"], false)

clientPublic, clientSecret := getClientSeed()

wp.opConnect(dbName, user, password, authPluginName, wireCrypt, clientPublic)
err = wp.opAccept(user, password, authPluginName, wireCrypt, clientPublic, clientSecret)
wp.opConnect(dbName, user, password, options, clientPublic)
err = wp._parse_connect_response(user, password, options, clientPublic, clientSecret)
if err != nil {
return
}
wp.opAttach(dbName, user, password, role)
wp.opAttach(dbName, user, password, options["role"])
wp.dbHandle, _, _, err = wp.opResponse()
if err != nil {
return
}

fc = new(firebirdsqlConn)
fc.transactionSet = make(map[*firebirdsqlTx]struct{})
fc.wp = wp
fc.addr = addr
fc.dbName = dbName
fc.user = user
fc.password = password
fc.columnNameToLower = column_name_to_lower
fc.isAutocommit = true
fc.tx, err = newFirebirdsqlTx(fc, ISOLATION_LEVEL_READ_COMMITED, fc.isAutocommit)
fc.clientPublic = clientPublic
fc.clientSecret = clientSecret

fc.loadTimeZoneId()

return fc, err
}

func createFirebirdsqlConn(dsn string) (fc *firebirdsqlConn, err error) {
// Create Database
addr, dbName, user, password, role, authPluginName, wireCrypt, err := parseDSN(dsn)
wp, err := newWireProtocol(addr)
addr, dbName, user, password, options, err := parseDSN(dsn)

wp, err := newWireProtocol(addr, options["timezone"])
if err != nil {
return
}
column_name_to_lower := convertToBool(options["column_name_to_lower"], false)

clientPublic, clientSecret := getClientSeed()

wp.opConnect(dbName, user, password, authPluginName, wireCrypt, clientPublic)
err = wp.opAccept(user, password, authPluginName, wireCrypt, clientPublic, clientSecret)
wp.opConnect(dbName, user, password, options, clientPublic)
err = wp._parse_connect_response(user, password, options, clientPublic, clientSecret)
if err != nil {
return
}
wp.opCreate(dbName, user, password, role)
wp.opCreate(dbName, user, password, options["role"])
wp.dbHandle, _, _, err = wp.opResponse()
if err != nil {
return
}

fc = new(firebirdsqlConn)
fc.transactionSet = make(map[*firebirdsqlTx]struct{})
fc.wp = wp
fc.addr = addr
fc.dbName = dbName
fc.user = user
fc.password = password
fc.columnNameToLower = column_name_to_lower
fc.isAutocommit = true
fc.tx, err = newFirebirdsqlTx(fc, ISOLATION_LEVEL_READ_COMMITED, fc.isAutocommit)
fc.clientPublic = clientPublic
fc.clientSecret = clientSecret

fc.loadTimeZoneId()

return fc, err
}
9 changes: 8 additions & 1 deletion consts.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*******************************************************************************
The MIT License (MIT)
Copyright (c) 2013-2016 Hajime Nakagami
Copyright (c) 2013-2019 Hajime Nakagami
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down Expand Up @@ -217,6 +217,13 @@ const (
isc_dpb_process_name = 74
isc_dpb_utf8_filename = 77
isc_dpb_specific_auth_data = 84
isc_dpb_auth_plugin_list = 85
isc_dpb_auth_plugin_name = 86
isc_dpb_config = 87
isc_dpb_nolinger = 88
isc_dpb_reset_icu = 89
isc_dpb_map_attach = 90
isc_dpb_session_time_zone = 91

// backup
isc_spb_bkp_file = 5
Expand Down
Loading

0 comments on commit edec3c8

Please sign in to comment.