github.com/dolthub/go-mysql-server@v0.18.0/sql/expression/function/version.go (about) 1 // Copyright 2020-2021 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package function 16 17 import ( 18 "fmt" 19 20 "github.com/dolthub/go-mysql-server/sql" 21 "github.com/dolthub/go-mysql-server/sql/types" 22 ) 23 24 const mysqlVersion = "8.0.11" 25 26 // Version is a function that returns server version. 27 type Version string 28 29 func (f Version) IsNonDeterministic() bool { 30 // Just means that the value can change over time, i.e. on an upgrade 31 return true 32 } 33 34 var _ sql.FunctionExpression = (Version)("") 35 var _ sql.CollationCoercible = (Version)("") 36 37 // NewVersion creates a new Version UDF. 38 func NewVersion(versionPostfix string) func(...sql.Expression) (sql.Expression, error) { 39 return func(...sql.Expression) (sql.Expression, error) { 40 return Version(versionPostfix), nil 41 } 42 } 43 44 // FunctionName implements sql.FunctionExpression 45 func (f Version) FunctionName() string { 46 return "version" 47 } 48 49 // Description implements sql.FunctionExpression 50 func (f Version) Description() string { 51 return "returns a string that indicates the SQL server version." 52 } 53 54 // Type implements the Expression interface. 55 func (f Version) Type() sql.Type { return types.LongText } 56 57 // CollationCoercibility implements the interface sql.CollationCoercible. 58 func (Version) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) { 59 return sql.Collation_utf8mb3_general_ci, 3 60 } 61 62 // IsNullable implements the Expression interface. 63 func (f Version) IsNullable() bool { 64 return false 65 } 66 67 func (f Version) String() string { 68 return fmt.Sprintf("%s()", f.FunctionName()) 69 } 70 71 // WithChildren implements the Expression interface. 72 func (f Version) WithChildren(children ...sql.Expression) (sql.Expression, error) { 73 if len(children) != 0 { 74 return nil, sql.ErrInvalidChildrenNumber.New(f, len(children), 0) 75 } 76 return f, nil 77 } 78 79 // Resolved implements the Expression interface. 80 func (f Version) Resolved() bool { 81 return true 82 } 83 84 // Children implements the Expression interface. 85 func (f Version) Children() []sql.Expression { return nil } 86 87 // Eval implements the Expression interface. 88 func (f Version) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) { 89 if f == "" { 90 return mysqlVersion, nil 91 } 92 93 return fmt.Sprintf("%s-%s", mysqlVersion, string(f)), nil 94 }