Browse Source

Use readBool func

Introduced a new readBool function to parse string values to bool
values.
The function is more general and makes the behavior consistent.
Julien Schmidt 12 năm trước cách đây
mục cha
commit
68de1a8701
3 tập tin đã thay đổi với 13 bổ sung7 xóa
  1. 2 6
      connection.go
  2. 1 1
      driver_test.go
  3. 10 0
      utils.go

+ 2 - 6
connection.go

@@ -68,15 +68,11 @@ func (mc *mysqlConn) handleParams() (err error) {
 
 		// time.Time parsing
 		case "parseTime":
-			if val == "true" {
-				mc.parseTime = true
-			}
+			mc.parseTime = readBool(val)
 
 		// Strict mode
 		case "strict":
-			if val == "true" {
-				mc.strict = true
-			}
+			mc.strict = readBool(val)
 
 		// TLS-Encryption
 		case "tls":

+ 1 - 1
driver_test.go

@@ -968,7 +968,7 @@ func TestStmtMultiRows(t *testing.T) {
 }
 
 func TestConcurrent(t *testing.T) {
-	if os.Getenv("MYSQL_TEST_CONCURRENT") != "1" {
+	if readBool(os.Getenv("MYSQL_TEST_CONCURRENT")) != true {
 		t.Log("CONCURRENT env var not set. Skipping TestConcurrent")
 		return
 	}

+ 10 - 0
utils.go

@@ -234,6 +234,16 @@ func formatBinaryDateTime(num uint64, data []byte) (driver.Value, error) {
 	return nil, fmt.Errorf("Invalid DATETIME-packet length %d", num)
 }
 
+func readBool(value string) bool {
+	switch strings.ToLower(value) {
+	case "true":
+		return true
+	case "1":
+		return true
+	}
+	return false
+}
+
 /******************************************************************************
 *                       Convert from and to bytes                             *
 ******************************************************************************/