Last active
February 16, 2024 09:23
-
-
Save robstradling/93d461f916c37e17a724e54d78942fbc to your computer and use it in GitHub Desktop.
go-ora: Regression since v2.8.7 for simple SELECTs into integer and floating point variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"database/sql" | |
"flag" | |
"fmt" | |
"os" | |
go_ora "github.com/sijms/go-ora/v2" | |
) | |
func usage() { | |
fmt.Println() | |
fmt.Println("cant_assign_value") | |
fmt.Println(" a demonstration of a regression introduced in go-ora v2.8.7.") | |
fmt.Println() | |
fmt.Println("Usage:") | |
fmt.Println(` cant_assign_value -server server_url`) | |
flag.PrintDefaults() | |
fmt.Println() | |
fmt.Println("Example:") | |
fmt.Println(` cant_assign_value -server "oracle://user:pass@server/service_name"`) | |
fmt.Println() | |
} | |
func main() { | |
var ( | |
server string | |
) | |
flag.StringVar(&server, "server", "", "Server's URL, oracle://user:pass@server/service_name") | |
flag.Parse() | |
connStr := os.ExpandEnv(server) | |
if connStr == "" { | |
fmt.Println("Missing -server option") | |
usage() | |
os.Exit(1) | |
} | |
fmt.Println("Connection string: ", connStr) | |
conn, err := go_ora.NewConnection(connStr) | |
if err != nil { | |
fmt.Println("Can't create connection: ", err) | |
return | |
} else if err = conn.Open(); err != nil { | |
fmt.Println("Can't open the driver: ", err) | |
return | |
} | |
defer func() { | |
err = conn.Close() | |
if err != nil { | |
fmt.Println("Can't close driver: ", err) | |
} | |
}() | |
err = conn.Ping(context.Background()) | |
if err != nil { | |
fmt.Println("Can't ping connection: ", err) | |
return | |
} | |
fmt.Println("\n'SELECT 1 FROM DUAL' into an 'int' variable") | |
var oneInt int | |
err = conn.QueryRowContext(context.Background(), "SELECT 1 FROM DUAL", nil).Scan(&oneInt) | |
if err != nil { | |
fmt.Println("Failed: ", err) | |
} else { | |
fmt.Println("OK: ", oneInt) | |
} | |
fmt.Println("\n'SELECT 1 FROM DUAL' into an 'int64' variable") | |
var oneInt64 int64 | |
err = conn.QueryRowContext(context.Background(), "SELECT 1 FROM DUAL", nil).Scan(&oneInt64) | |
if err != nil { | |
fmt.Println("Failed: ", err) | |
} else { | |
fmt.Println("OK: ", oneInt64) | |
} | |
fmt.Println("\n'SELECT 1 FROM DUAL' into a 'sql.NullInt32' variable") | |
var oneNullInt32 sql.NullInt32 | |
err = conn.QueryRowContext(context.Background(), "SELECT 1 FROM DUAL", nil).Scan(&oneNullInt32) | |
if err != nil { | |
fmt.Println("Failed: ", err) | |
} else { | |
fmt.Println("OK: ", oneNullInt32) | |
} | |
fmt.Println("\n'SELECT 1 FROM DUAL' into a 'sql.NullInt64' variable") | |
var oneNullInt64 sql.NullInt64 | |
err = conn.QueryRowContext(context.Background(), "SELECT 1 FROM DUAL", nil).Scan(&oneNullInt64) | |
if err != nil { | |
fmt.Println("Failed: ", err) | |
} else { | |
fmt.Println("OK: ", oneNullInt64) | |
} | |
fmt.Println("\n'SELECT 1 FROM DUAL' into a 'float32' variable") | |
var oneFloat32 float32 | |
err = conn.QueryRowContext(context.Background(), "SELECT 1 FROM DUAL", nil).Scan(&oneFloat32) | |
if err != nil { | |
fmt.Println("Failed: ", err) | |
} else { | |
fmt.Println("OK: ", oneFloat32) | |
} | |
fmt.Println("\n'SELECT 1 FROM DUAL' into a 'float64' variable") | |
var oneFloat64 float64 | |
err = conn.QueryRowContext(context.Background(), "SELECT 1 FROM DUAL", nil).Scan(&oneFloat64) | |
if err != nil { | |
fmt.Println("Failed: ", err) | |
} else { | |
fmt.Println("OK: ", oneFloat64) | |
} | |
fmt.Println("\n'SELECT 1 FROM DUAL' into a 'sql.NullFloat64' variable") | |
var oneNullFloat64 sql.NullFloat64 | |
err = conn.QueryRowContext(context.Background(), "SELECT 1 FROM DUAL", nil).Scan(&oneNullFloat64) | |
if err != nil { | |
fmt.Println("Failed: ", err) | |
} else { | |
fmt.Println("OK: ", oneNullFloat64) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module gist.github.com/robstradling/93d461f916c37e17a724e54d78942fbc | |
go 1.21.6 | |
require github.com/sijms/go-ora/v2 v2.8.9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
github.com/sijms/go-ora/v2 v2.8.9 h1:XIghcG8hjtYu+G9H235VEe5JXPLJtdzzj7pQm7JucVo= | |
github.com/sijms/go-ora/v2 v2.8.9/go.mod h1:EHxlY6x7y9HAsdfumurRfTd+v8NrEOTR3Xl4FWlH6xk= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Connection string: oracle://www:[email protected]:1522/saspdev.sectigo.gb | |
'SELECT 1 FROM DUAL' into an 'int' variable | |
OK: 1 | |
'SELECT 1 FROM DUAL' into an 'int64' variable | |
OK: 1 | |
'SELECT 1 FROM DUAL' into a 'sql.NullInt32' variable | |
OK: {1 true} | |
'SELECT 1 FROM DUAL' into a 'sql.NullInt64' variable | |
OK: {1 true} | |
'SELECT 1 FROM DUAL' into a 'float32' variable | |
OK: 1 | |
'SELECT 1 FROM DUAL' into a 'float64' variable | |
OK: 1 | |
'SELECT 1 FROM DUAL' into a 'sql.NullFloat64' variable | |
OK: {1 true} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Connection string: oracle://www:[email protected]:1522/saspdev.sectigo.gb | |
'SELECT 1 FROM DUAL' into an 'int' variable | |
Failed: can't assign value: 1 to object of type: int | |
'SELECT 1 FROM DUAL' into an 'int64' variable | |
Failed: can't assign value: 1 to object of type: int64 | |
'SELECT 1 FROM DUAL' into a 'sql.NullInt32' variable | |
Failed: can't assign value: 1 to object of type: NullInt32 | |
'SELECT 1 FROM DUAL' into a 'sql.NullInt64' variable | |
Failed: can't assign value: 1 to object of type: NullInt64 | |
'SELECT 1 FROM DUAL' into a 'float32' variable | |
Failed: can't assign value: 1 to object of type: float32 | |
'SELECT 1 FROM DUAL' into a 'float64' variable | |
Failed: can't assign value: 1 to object of type: float64 | |
'SELECT 1 FROM DUAL' into a 'sql.NullFloat64' variable | |
Failed: can't assign value: 1 to object of type: NullFloat64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Connection string: oracle://www:[email protected]:1522/saspdev.sectigo.gb | |
'SELECT 1 FROM DUAL' into an 'int' variable | |
Failed: can't assign value: 1 to object of type: int | |
'SELECT 1 FROM DUAL' into an 'int64' variable | |
Failed: can't assign value: 1 to object of type: int64 | |
'SELECT 1 FROM DUAL' into a 'sql.NullInt32' variable | |
Failed: can't assign value: 1 to object of type: NullInt32 | |
'SELECT 1 FROM DUAL' into a 'sql.NullInt64' variable | |
Failed: can't assign value: 1 to object of type: NullInt64 | |
'SELECT 1 FROM DUAL' into a 'float32' variable | |
Failed: can't assign value: 1 to object of type: float32 | |
'SELECT 1 FROM DUAL' into a 'float64' variable | |
Failed: can't assign value: 1 to object of type: float64 | |
'SELECT 1 FROM DUAL' into a 'sql.NullFloat64' variable | |
Failed: can't assign value: 1 to object of type: NullFloat64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Connection string: oracle://www:[email protected]:1522/saspdev.sectigo.gb | |
'SELECT 1 FROM DUAL' into an 'int' variable | |
Failed: unsupported primitive type: int | |
'SELECT 1 FROM DUAL' into an 'int64' variable | |
Failed: unsupported primitive type: int64 | |
'SELECT 1 FROM DUAL' into a 'sql.NullInt32' variable | |
OK: {1 true} | |
'SELECT 1 FROM DUAL' into a 'sql.NullInt64' variable | |
OK: {1 true} | |
'SELECT 1 FROM DUAL' into a 'float32' variable | |
Failed: unsupported primitive type: float32 | |
'SELECT 1 FROM DUAL' into a 'float64' variable | |
Failed: unsupported primitive type: float64 | |
'SELECT 1 FROM DUAL' into a 'sql.NullFloat64' variable | |
OK: {1 true} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment