Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

how can i query with bit field in where clause #1608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
superceix opened this issue Jul 18, 2024 · 1 comment
Closed

how can i query with bit field in where clause #1608

superceix opened this issue Jul 18, 2024 · 1 comment

Comments

@superceix
Copy link

table info

-- table define
CREATE TABLE `t0` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `c1` int(11) NOT NULL,
  `c2` varchar(64) COLLATE utf8mb4_bin NOT NULL,
  `c3` bit(4) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin

-- row insert
insert into t0 values (1,1,'aaa',b'1100');

Example code

import (
	"database/sql"
	"fmt"

	_ "github.com/go-sql-driver/mysql"
)

func main() {
	connStr := "xxx:xxx@tcp(xxxxx:xxxx)/?timeout=3600s"
	if conn, err := sql.Open("mysql", connStr); err != nil {
		fmt.Print("ReCreate conn failure!", err.Error())
	} else {
		sql1 := "SELECT c3 FROM `test1`.`t0` WHERE `c2`=?"
		rows1 := conn.QueryRow(sql1, "aaa")
		c3 := []byte{}
		rows1.Scan(&c3)  // row scan success, and get c3 is '[0] = 12 = 0xc' in debug

		sql := "SELECT c2 FROM `test1`.`t0` WHERE `c3`=?"
		rows, err := conn.Query(sql, c3)
		if err != nil {
			fmt.Printf("quert errpor")
		}
		for rows.Next() {
			var c2 string
			if err := rows.Scan(&c2); err != nil {
				fmt.Print("Row.Scan rawRecord Error", err)
			}
			fmt.Printf("c2:%s", c2)
		}
	}
}

no rows result after conn.Query(sql, c3)

@methane
Copy link
Member

methane commented Jul 19, 2024

Try query with mysql cli first.

@go-sql-driver go-sql-driver locked and limited conversation to collaborators Apr 21, 2025
@methane methane converted this issue into discussion #1701 Apr 21, 2025

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants