-
Notifications
You must be signed in to change notification settings - Fork 219
Expand file tree
/
Copy pathset.go
More file actions
60 lines (54 loc) · 1.37 KB
/
set.go
File metadata and controls
60 lines (54 loc) · 1.37 KB
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
/*
* Radon
*
* Copyright 2018 The Radon Authors.
* Code is licensed under the GPLv3.
*
*/
package proxy
import (
"fmt"
"strings"
"github.com/xelabs/go-mysqlstack/driver"
"github.com/xelabs/go-mysqlstack/sqlparser"
"github.com/xelabs/go-mysqlstack/sqlparser/depends/sqltypes"
)
const (
var_radon_streaming_fetch = "radon_streaming_fetch"
)
// handleSet used to handle the SET command.
func (spanner *Spanner) handleSet(session *driver.Session, query string, node *sqlparser.Set) (*sqltypes.Result, error) {
txSession := spanner.sessions.getTxnSession(session)
for _, expr := range node.Exprs {
name := expr.Name.Lowered()
if strings.HasPrefix(name, "@@session.") {
name = strings.TrimPrefix(name, "@@session.")
}
switch name {
case var_radon_streaming_fetch:
switch expr := expr.Expr.(type) {
case *sqlparser.SQLVal:
switch expr.Type {
case sqlparser.StrVal:
val := strings.ToLower(string(expr.Val))
switch val {
case "on":
txSession.setStreamingFetchVar(true)
case "off":
txSession.setStreamingFetchVar(false)
}
default:
return nil, fmt.Errorf("Invalid value type: %v", sqlparser.String(expr))
}
case sqlparser.BoolVal:
if expr {
txSession.setStreamingFetchVar(true)
} else {
txSession.setStreamingFetchVar(false)
}
}
}
}
qr := &sqltypes.Result{Warnings: 1}
return qr, nil
}