forked from sijms/go-ora
-
Notifications
You must be signed in to change notification settings - Fork 0
/
connection.go
770 lines (737 loc) · 20.4 KB
/
connection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
package go_ora
import (
"context"
"database/sql"
"database/sql/driver"
"errors"
"fmt"
"os"
"os/user"
"strconv"
"strings"
"github.com/sijms/go-ora/advanced_nego"
"github.com/sijms/go-ora/converters"
"github.com/sijms/go-ora/network"
"github.com/sijms/go-ora/trace"
)
type ConnectionState int
const (
Closed ConnectionState = 0
Opened ConnectionState = 1
)
type LogonMode int
const (
NoNewPass LogonMode = 0x1
//WithNewPass LogonMode = 0x2
SysDba LogonMode = 0x20 // no verify response from server
SysOper LogonMode = 0x40 // no verify response from server
UserAndPass LogonMode = 0x100
//PROXY LogonMode = 0x400
)
type NLSData struct {
Calender string
Comp string
Language string
LengthSemantics string
NCharConvExcep string
NCharConvImp string
DateLang string
Sort string
Currency string
DateFormat string
TimeFormat string
IsoCurrency string
NumericChars string
DualCurrency string
UnionCurrency string
Timestamp string
TimestampTZ string
TTimezoneFormat string
NTimezoneFormat string
Territory string
Charset string
}
type Connection struct {
State ConnectionState
LogonMode LogonMode
autoCommit bool
conStr *ConnectionString
connOption *network.ConnectionOption
session *network.Session
tcpNego *TCPNego
dataNego *DataTypeNego
authObject *AuthObject
SessionProperties map[string]string
dBVersion *DBVersion
sessionID int
serialID int
transactionID []byte
strConv *converters.StringConverter
NLSData NLSData
}
type oracleDriver struct {
}
func init() {
sql.Register("oracle", &oracleDriver{})
}
func (drv *oracleDriver) Open(name string) (driver.Conn, error) {
conn, err := NewConnection(name)
if err != nil {
return nil, err
}
return conn, conn.Open()
}
func (conn *Connection) GetNLS() (*NLSData, error) {
// we read from nls_session_parameters ONCE
cmdText := `
DECLARE
err_code VARCHAR2(2000);
err_msg VARCHAR2(2000);
BEGIN
SELECT
MAX(CASE WHEN PARAMETER='NLS_CALENDAR' THEN VALUE END) AS NLS_CALENDAR,
MAX(CASE WHEN PARAMETER='NLS_COMP' THEN VALUE END) AS NLS_COMP,
MAX(CASE WHEN PARAMETER='NLS_LENGTH_SEMANTICS' THEN VALUE END) AS NLS_LENGTH_SEMANTICS,
MAX(CASE WHEN PARAMETER='NLS_NCHAR_CONV_EXCP' THEN VALUE END) AS NLS_NCHAR_CONV_EXCP,
MAX(CASE WHEN PARAMETER='NLS_DATE_LANGUAGE' THEN VALUE END) AS NLS_DATE_LANGUAGE,
MAX(CASE WHEN PARAMETER='NLS_SORT' THEN VALUE END) AS NLS_SORT,
MAX(CASE WHEN PARAMETER='NLS_CURRENCY' THEN VALUE END) AS NLS_CURRENCY,
MAX(CASE WHEN PARAMETER='NLS_DATE_FORMAT' THEN VALUE END) AS NLS_DATE_FORMAT,
MAX(CASE WHEN PARAMETER='NLS_ISO_CURRENCY' THEN VALUE END) AS NLS_ISO_CURRENCY,
MAX(CASE WHEN PARAMETER='NLS_NUMERIC_CHARACTERS' THEN VALUE END) AS NLS_NUMERIC_CHARACTERS,
MAX(CASE WHEN PARAMETER='NLS_DUAL_CURRENCY' THEN VALUE END) AS NLS_DUAL_CURRENCY,
MAX(CASE WHEN PARAMETER='NLS_TIMESTAMP_FORMAT' THEN VALUE END) AS NLS_TIMESTAMP_FORMAT,
MAX(CASE WHEN PARAMETER='NLS_TIMESTAMP_TZ_FORMAT' THEN VALUE END) AS NLS_TIMESTAMP_TZ_FORMAT,
'0' AS p_err_code,
'0' AS p_err_msg
into :p_nls_calendar, :p_nls_comp, :p_nls_length_semantics, :p_nls_nchar_conv_excep,
:p_nls_date_lang, :p_nls_sort, :p_nls_currency, :p_nls_date_format, :p_nls_iso_currency,
:p_nls_numeric_chars, :p_nls_dual_currency, :p_nls_timestamp, :p_nls_timestamp_tz,
:p_err_code, :p_err_msg
FROM
nls_session_parameters
;
END;`
stmt := NewStmt(cmdText, conn)
stmt.AddParam("p_nls_calendar", "", 40, Output)
stmt.AddParam("p_nls_comp", "", 40, Output)
stmt.AddParam("p_nls_length_semantics", "", 40, Output)
stmt.AddParam("p_nls_nchar_conv_excep", "", 40, Output)
stmt.AddParam("p_nls_date_lang", "", 40, Output)
stmt.AddParam("p_nls_sort", "", 40, Output)
stmt.AddParam("p_nls_currency", "", 40, Output)
stmt.AddParam("p_nls_date_format", "", 40, Output)
stmt.AddParam("p_nls_iso_currency", "", 40, Output)
stmt.AddParam("p_nls_numeric_chars", "", 40, Output)
stmt.AddParam("p_nls_dual_currency", "", 40, Output)
stmt.AddParam("p_nls_timestamp", "", 48, Output)
stmt.AddParam("p_nls_timestamp_tz", "", 56, Output)
stmt.AddParam("p_err_code", "", 2000, Output)
stmt.AddParam("p_err_msg", "", 2000, Output)
defer stmt.Close()
//fmt.Println(stmt.Pars)
_, err := stmt.Exec(nil)
if err != nil {
return nil, err
}
if len(stmt.Pars) >= 10 {
conn.NLSData.Calender = conn.strConv.Decode(stmt.Pars[0].BValue)
conn.NLSData.Comp = conn.strConv.Decode(stmt.Pars[1].BValue)
conn.NLSData.LengthSemantics = conn.strConv.Decode(stmt.Pars[2].BValue)
conn.NLSData.NCharConvExcep = conn.strConv.Decode(stmt.Pars[3].BValue)
conn.NLSData.DateLang = conn.strConv.Decode(stmt.Pars[4].BValue)
conn.NLSData.Sort = conn.strConv.Decode(stmt.Pars[5].BValue)
conn.NLSData.Currency = conn.strConv.Decode(stmt.Pars[6].BValue)
conn.NLSData.DateFormat = conn.strConv.Decode(stmt.Pars[7].BValue)
conn.NLSData.IsoCurrency = conn.strConv.Decode(stmt.Pars[8].BValue)
conn.NLSData.NumericChars = conn.strConv.Decode(stmt.Pars[9].BValue)
conn.NLSData.DualCurrency = conn.strConv.Decode(stmt.Pars[10].BValue)
conn.NLSData.Timestamp = conn.strConv.Decode(stmt.Pars[11].BValue)
conn.NLSData.TimestampTZ = conn.strConv.Decode(stmt.Pars[12].BValue)
}
/*
for _, par := range stmt.Pars {
if par.Name == "p_nls_calendar" {
conn.NLSData.Calender = conn.strConv.Decode(par.BValue)
} else if par.Name == "p_nls_comp" {
conn.NLSData.Comp = conn.strConv.Decode(par.BValue)
} else if par.Name == "p_nls_length_semantics" {
conn.NLSData.LengthSemantics = conn.strConv.Decode(par.BValue)
} else if par.Name == "p_nls_nchar_conv_excep" {
conn.NLSData.NCharConvExcep = conn.strConv.Decode(par.BValue)
} else if par.Name == "p_nls_date_lang" {
conn.NLSData.DateLang = conn.strConv.Decode(par.BValue)
} else if par.Name == "p_nls_sort" {
conn.NLSData.Sort = conn.strConv.Decode(par.BValue)
} else if par.Name == "p_nls_currency" {
conn.NLSData.Currency = conn.strConv.Decode(par.BValue)
} else if par.Name == "p_nls_date_format" {
conn.NLSData.DateFormat = conn.strConv.Decode(par.BValue)
} else if par.Name == "p_nls_iso_currency" {
conn.NLSData.IsoCurrency = conn.strConv.Decode(par.BValue)
} else if par.Name == "p_nls_numeric_chars" {
conn.NLSData.NumericChars = conn.strConv.Decode(par.BValue)
} else if par.Name == "p_nls_dual_currency" {
conn.NLSData.DualCurrency = conn.strConv.Decode(par.BValue)
} else if par.Name == "p_nls_timestamp" {
conn.NLSData.Timestamp = conn.strConv.Decode(par.BValue)
} else if par.Name == "p_nls_timestamp_tz" {
conn.NLSData.TimestampTZ = conn.strConv.Decode(par.BValue)
}
}
*/
return &conn.NLSData, nil
}
func (conn *Connection) Prepare(query string) (driver.Stmt, error) {
conn.connOption.Tracer.Print("Prepare\n", query)
return NewStmt(query, conn), nil
}
func (conn *Connection) Ping(_ context.Context) error {
conn.connOption.Tracer.Print("Ping")
conn.session.ResetBuffer()
return (&simpleObject{
connection: conn,
operationID: 0x93,
data: nil,
}).write().read()
}
//func (conn *Connection) Logoff() error {
// conn.connOption.Tracer.Print("Logoff")
// session := conn.session
// session.ResetBuffer()
// session.PutBytes(0x11, 0x87, 0, 0, 0, 0x2, 0x1, 0x11, 0x1, 0, 0, 0, 0x1, 0, 0, 0, 0, 0, 0x1, 0, 0, 0, 0, 0,
// 3, 9, 0)
// err := session.Write()
// if err != nil {
// return err
// }
// loop := true
// for loop {
// msg, err := session.GetByte()
// if err != nil {
// return err
// }
// switch msg {
// case 4:
// session.Summary, err = network.NewSummary(session)
// if err != nil {
// return err
// }
// loop = false
// case 9:
// if session.HasEOSCapability {
// if session.Summary == nil {
// session.Summary = new(network.SummaryObject)
// }
// session.Summary.EndOfCallStatus, err = session.GetInt(4, true, true)
// if err != nil {
// return err
// }
// }
// if session.HasFSAPCapability {
// if session.Summary == nil {
// session.Summary = new(network.SummaryObject)
// }
// session.Summary.EndToEndECIDSequence, err = session.GetInt(2, true, true)
// if err != nil {
// return err
// }
// }
// loop = false
// default:
// return errors.New(fmt.Sprintf("message code error: received code %d and expected code is 4, 9", msg))
// }
// }
// if session.HasError() {
// return errors.New(session.GetError())
// }
// return nil
//}
func (conn *Connection) Open() error {
tracer := conn.connOption.Tracer
tracer.Print("Open :", conn.connOption.ConnectionData())
switch conn.conStr.DBAPrivilege {
case SYSDBA:
conn.LogonMode |= SysDba
case SYSOPER:
conn.LogonMode |= SysOper
default:
conn.LogonMode = 0
}
conn.session = network.NewSession(*conn.connOption)
session := conn.session
err := session.Connect()
if err != nil {
return err
}
// advanced negotiation
if session.Context.ACFL0&1 != 0 && session.Context.ACFL0&4 == 0 && session.Context.ACFL1&8 == 0 {
tracer.Print("Advance Negotiation")
ano, err := advanced_nego.NewAdvNego(conn.connOption)
if err != nil {
return err
}
err = ano.Write(session)
if err != nil {
return err
}
err = ano.Read(session)
if err != nil {
return err
}
}
//else {
//
//}
tracer.Print("TCP Negotiation")
conn.tcpNego, err = NewTCPNego(conn.session)
if err != nil {
return err
}
tracer.Print("Server Charset: ", conn.tcpNego.ServerCharset)
tracer.Print("Server National Charset: ", conn.tcpNego.ServernCharset)
// create string converter object
conn.strConv = converters.NewStringConverter(conn.tcpNego.ServerCharset)
conn.session.StrConv = conn.strConv
conn.tcpNego.ServerFlags |= 2
tracer.Print("Data Type Negotiation")
conn.dataNego = buildTypeNego(conn.tcpNego, conn.session)
err = conn.dataNego.write(conn.session)
if err != nil {
return err
}
err = conn.dataNego.read(conn.session)
if err != nil {
return err
}
conn.session.TTCVersion = conn.dataNego.CompileTimeCaps[7]
if conn.tcpNego.ServerCompileTimeCaps[7] < conn.session.TTCVersion {
conn.session.TTCVersion = conn.tcpNego.ServerCompileTimeCaps[7]
}
tracer.Print("TTC Version: ", conn.session.TTCVersion)
//this.m_b32kTypeSupported = this.m_dtyNeg.m_b32kTypeSupported;
//this.m_bSupportSessionStateOps = this.m_dtyNeg.m_bSupportSessionStateOps;
//this.m_marshallingEngine.m_bServerUsingBigSCN = this.m_serverCompiletimeCapabilities[7] >= (byte) 8;
err = conn.doAuth()
if err != nil {
return err
}
conn.State = Opened
conn.dBVersion, err = GetDBVersion(conn.session)
if err != nil {
return err
}
tracer.Print("Connected")
tracer.Print("Database Version: ", conn.dBVersion.Text)
sessionID, err := strconv.ParseUint(conn.SessionProperties["AUTH_SESSION_ID"], 10, 32)
if err != nil {
return err
}
conn.sessionID = int(sessionID)
serialNum, err := strconv.ParseUint(conn.SessionProperties["AUTH_SERIAL_NUM"], 10, 32)
if err != nil {
return err
}
conn.serialID = int(serialNum)
conn.connOption.InstanceName = conn.SessionProperties["AUTH_SC_INSTANCE_NAME"]
conn.connOption.Host = conn.SessionProperties["AUTH_SC_SERVER_HOST"]
conn.connOption.ServiceName = conn.SessionProperties["AUTH_SC_SERVICE_NAME"]
conn.connOption.DomainName = conn.SessionProperties["AUTH_SC_DB_DOMAIN"]
conn.connOption.DBName = conn.SessionProperties["AUTH_SC_DBUNIQUE_NAME"]
if len(conn.NLSData.Language) == 0 {
_, err = conn.GetNLS()
if err != nil {
return err
}
}
return nil
}
func (conn *Connection) Begin() (driver.Tx, error) {
conn.connOption.Tracer.Print("Begin transaction")
conn.autoCommit = false
return &Transaction{conn: conn}, nil
}
func NewConnection(databaseUrl string) (*Connection, error) {
//this.m_id = this.GetHashCode().ToString();
conStr, err := newConnectionStringFromUrl(databaseUrl)
if err != nil {
return nil, err
}
userName := ""
User, err := user.Current()
if err == nil {
userName = User.Username
}
hostName, _ := os.Hostname()
indexOfSlash := strings.LastIndex(os.Args[0], "/")
indexOfSlash += 1
if indexOfSlash < 0 {
indexOfSlash = 0
}
connOption := &network.ConnectionOption{
Port: conStr.Port,
TransportConnectTo: 0xFFFF,
SSLVersion: "",
WalletDict: "",
TransportDataUnitSize: 0xFFFF,
SessionDataUnitSize: 0xFFFF,
Protocol: "tcp",
Host: conStr.Host,
UserID: conStr.UserID,
//IP: "",
SID: conStr.SID,
//Addr: "",
//Server: conn.conStr.Host,
ServiceName: conStr.ServiceName,
InstanceName: conStr.InstanceName,
ClientData: network.ClientData{
ProgramPath: os.Args[0],
ProgramName: os.Args[0][indexOfSlash:],
UserName: userName,
HostName: hostName,
DriverName: "OracleClientGo",
PID: os.Getpid(),
},
//InAddrAny: false,
}
if len(conStr.Trace) > 0 {
tf, err := os.Create(conStr.Trace)
if err != nil {
//noinspection GoErrorStringFormat
return nil, fmt.Errorf("Can't open trace file: %w", err)
}
connOption.Tracer = trace.NewTraceWriter(tf)
} else {
connOption.Tracer = trace.NilTracer()
}
return &Connection{
State: Closed,
conStr: conStr,
connOption: connOption,
autoCommit: true,
}, nil
}
func (conn *Connection) Close() (err error) {
conn.connOption.Tracer.Print("Close")
//var err error = nil
if conn.session != nil {
//err = conn.Logoff()
conn.session.Disconnect()
conn.session = nil
}
conn.connOption.Tracer.Print("Connection Closed")
conn.connOption.Tracer.Close()
return
}
func (conn *Connection) doAuth() error {
conn.connOption.Tracer.Print("doAuth")
conn.session.ResetBuffer()
conn.session.PutBytes(3, 118, 0, 1)
conn.session.PutUint(len(conn.conStr.UserID), 4, true, true)
conn.LogonMode = conn.LogonMode | NoNewPass
conn.session.PutUint(int(conn.LogonMode), 4, true, true)
conn.session.PutBytes(1, 1, 5, 1, 1)
conn.session.PutString(conn.conStr.UserID)
//conn.session.PutBytes([]byte()...)
conn.session.PutKeyValString("AUTH_TERMINAL", conn.connOption.ClientData.HostName, 0)
conn.session.PutKeyValString("AUTH_PROGRAM_NM", conn.connOption.ClientData.ProgramName, 0)
conn.session.PutKeyValString("AUTH_MACHINE", conn.connOption.ClientData.HostName, 0)
conn.session.PutKeyValString("AUTH_PID", fmt.Sprintf("%d", conn.connOption.ClientData.PID), 0)
conn.session.PutKeyValString("AUTH_SID", conn.connOption.ClientData.UserName, 0)
err := conn.session.Write()
if err != nil {
return err
}
conn.authObject, err = NewAuthObject(conn.conStr.UserID, conn.conStr.Password, conn.tcpNego, conn.session)
if err != nil {
return err
}
// if proxyAuth ==> mode |= PROXY
err = conn.authObject.Write(conn.connOption, conn.LogonMode, conn.session)
if err != nil {
return err
}
stop := false
for !stop {
msg, err := conn.session.GetByte()
if err != nil {
return err
}
switch msg {
case 4:
conn.session.Summary, err = network.NewSummary(conn.session)
if err != nil {
return err
}
if conn.session.HasError() {
return errors.New(conn.session.GetError())
}
stop = true
case 8:
dictLen, err := conn.session.GetInt(2, true, true)
if err != nil {
return err
}
conn.SessionProperties = make(map[string]string, dictLen)
for x := 0; x < dictLen; x++ {
key, val, _, err := conn.session.GetKeyVal()
if err != nil {
return err
}
conn.SessionProperties[string(key)] = string(val)
}
case 15:
warning, err := network.NewWarningObject(conn.session)
if err != nil {
return err
}
if warning != nil {
fmt.Println(warning)
}
case 23:
opCode, err := conn.session.GetByte()
if err != nil {
return err
}
if opCode == 5 {
err = conn.loadNLSData()
if err != nil {
return err
}
} else {
err = conn.getServerNetworkInformation(opCode)
if err != nil {
return err
}
}
default:
return errors.New(fmt.Sprintf("message code error: received code %d and expected code is 8", msg))
}
}
// if verifyResponse == true
// conn.authObject.VerifyResponse(conn.SessionProperties["AUTH_SVR_RESPONSE"])
return nil
}
func (conn *Connection) loadNLSData() error {
_, err := conn.session.GetInt(2, true, true)
if err != nil {
return err
}
_, err = conn.session.GetByte()
if err != nil {
return err
}
length, err := conn.session.GetInt(4, true, true)
if err != nil {
return err
}
_, err = conn.session.GetByte()
if err != nil {
return err
}
for i := 0; i < length; i++ {
nlsKey, nlsVal, nlsCode, err := conn.session.GetKeyVal()
if err != nil {
return err
}
conn.NLSData.SaveNLSValue(string(nlsKey), string(nlsVal), nlsCode)
}
_, err = conn.session.GetInt(4, true, true)
return err
}
func (conn *Connection) getServerNetworkInformation(code uint8) error {
session := conn.session
if code == 0 {
_, err := session.GetByte()
return err
}
switch code - 1 {
case 1:
// receive OCOSPID
length, err := session.GetInt(2, true, true)
if err != nil {
return err
}
_, err = session.GetByte()
if err != nil {
return err
}
_, err = session.GetBytes(length)
if err != nil {
return err
}
case 3:
// receive OCSESSRET session return values
_, err := session.GetInt(2, true, true)
if err != nil {
return err
}
_, err = session.GetByte()
if err != nil {
return err
}
length, err := session.GetInt(2, true, true)
if err != nil {
return err
}
// get nls data
for i := 0; i < length; i++ {
nlsKey, nlsVal, nlsCode, err := session.GetKeyVal()
if err != nil {
return err
}
conn.NLSData.SaveNLSValue(string(nlsKey), string(nlsVal), nlsCode)
}
flag, err := session.GetInt(4, true, true)
if err != nil {
return err
}
sessionID, err := session.GetInt(4, true, true)
if err != nil {
return err
}
serialID, err := session.GetInt(2, true, true)
if err != nil {
return err
}
if flag&4 == 4 {
conn.sessionID = sessionID
conn.serialID = serialID
// save session id and serial number to connection
}
case 4:
err := conn.loadNLSData()
if err != nil {
return err
}
case 6:
length, err := session.GetInt(4, true, true)
if err != nil {
return err
}
conn.transactionID, err = session.GetClr()
if len(conn.transactionID) > length {
conn.transactionID = conn.transactionID[:length]
}
case 7:
_, err := session.GetInt(2, true, true)
if err != nil {
return err
}
_, err = session.GetByte()
if err != nil {
return err
}
_, err = session.GetInt(4, true, true)
if err != nil {
return err
}
_, err = session.GetInt(4, true, true)
if err != nil {
return err
}
_, err = session.GetByte()
if err != nil {
return err
}
_, err = session.GetDlc()
if err != nil {
return err
}
case 8:
_, err := session.GetInt(2, true, true)
if err != nil {
return err
}
_, err = session.GetByte()
if err != nil {
return err
}
}
return nil
}
func (nls *NLSData) SaveNLSValue(key, value string, code int) {
key = strings.ToUpper(key)
if len(key) > 0 {
switch key {
case "AUTH_NLS_LXCCURRENCY":
code = 0
case "AUTH_NLS_LXCISOCURR":
code = 1
case "AUTH_NLS_LXCNUMERICS":
code = 2
case "AUTH_NLS_LXCDATEFM":
code = 7
case "AUTH_NLS_LXCDATELANG":
code = 8
case "AUTH_NLS_LXCTERRITORY":
code = 9
case "SESSION_NLS_LXCCHARSET":
code = 10
case "AUTH_NLS_LXCSORT":
code = 11
case "AUTH_NLS_LXCCALENDAR":
code = 12
case "AUTH_NLS_LXLAN":
code = 16
case "AL8KW_NLSCOMP":
code = 50
case "AUTH_NLS_LXCUNIONCUR":
code = 52
case "AUTH_NLS_LXCTIMEFM":
code = 57
case "AUTH_NLS_LXCSTMPFM":
code = 58
case "AUTH_NLS_LXCTTZNFM":
code = 59
case "AUTH_NLS_LXCSTZNFM":
code = 60
case "SESSION_NLS_LXCNLSLENSEM":
code = 61
case "SESSION_NLS_LXCNCHAREXCP":
code = 62
case "SESSION_NLS_LXCNCHARIMP":
code = 63
}
}
switch code {
case 0:
nls.Currency = value
case 1:
nls.IsoCurrency = value
case 2:
nls.NumericChars = value
case 7:
nls.DateFormat = value
case 8:
nls.DateLang = value
case 9:
nls.Territory = value
case 10:
nls.Charset = value
case 11:
nls.Sort = value
case 12:
nls.Calender = value
case 16:
nls.Language = value
case 50:
nls.Comp = value
case 52:
nls.UnionCurrency = value
case 57:
nls.TimeFormat = value
case 58:
nls.Timestamp = value
case 59:
nls.TTimezoneFormat = value
case 60:
nls.NTimezoneFormat = value
case 61:
nls.LengthSemantics = value
case 62:
nls.NCharConvExcep = value
case 63:
nls.NCharConvImp = value
}
}