Comments (6)
when ran directly on the database
How did you run prepared query directly on the database, without sending query from any client?
from mysql.
I assume "directly" means "not using prepared statement", and you used some client like "mysql" command. Please write a "complete step" next time.
Anyway, this is what happend in MySQL.
json->'$.alive'
: this value doesn't have boolean type, but JSON type.json->'$.alive' == true
: MySQL convert "true" to JSON "true" automatically. So it works fine.json->'$.alive' == ?
: MySQL doesn't convert the parameter "true". Since JSON true != BOOLEAN true (e.g. TINYINT 1), this is false.
Since TRUE is alias of 1 in MySQL, you need to write this complex code.
query := "SELECT * FROM test_table WHERE json->'$.alive' = CAST(? AS JSON)"
rows, err := db.Query(query, "true") // Not true, but "true"!
Full code is here.
https://github.com/methane/sandbox/blob/master/2023/go_mysql_1465/main.go
from mysql.
There may be a better way. But we are expert of mysql client/server protocol, not query.
Ask support on MySQL community, not on here.
from mysql.
Maybe, this is easier.
query := "SELECT * FROM test_table WHERE CAST(json->'$.alive' AS UNSIGNED) = ?"
rows, err := db.Query(query, true)
from mysql.
I misspoke. I was issuing to the database via my mysql driver in VSCode. I just tried (in a fresh docker image for sanity) as a prepared statement ie:
PREPARE stmt FROM "SELECT * FROM test_table WHERE json->'$.alive' = ?";
SET @a = true;
EXECUTE stmt USING @a;
Hmm. Interesting though, I was aware of it being stored as a TINYINT(1), but didn't realize that there was some additional type handling that went on with prepared statements here. Thank you for the help, I will try that. (and hopefully not have to have where clauses on json fields anyways for production filtering...)
from mysql.
PREPARE stmt FROM "SELECT * FROM test_table WHERE json->'$.alive' = ?";
SET @a = true;
EXECUTE stmt USING @a;
I execute it, but result is "0 rows in set (0.00 sec)".
It is same to this driver.
from mysql.
Related Issues (20)
- 'go get' no longer supported HOT 1
- Please update documentation (installation - go get -u github.com/go-sql-driver/mysql fails for newer go versions) HOT 1
- BUG: resource don't release when db.Exec have error. HOT 8
- DSN: support - in database name HOT 2
- context deadline exceeded HOT 1
- panic in escapeStringBackslash HOT 3
- Empty result with max unsigned int value
- For some reason the data is not showing. HOT 1
- Cut a new v1.7.2 release HOT 14
- Potential out of bound access in `(*mysqlConn).handleErrorPacket` HOT 7
- Toggle Click in Leaderboards
- mysql startWatcher panic error HOT 3
- Bizarre hanging issue in rows.Close() HOT 7
- Can't Install, bug in edwards25519/scalar.go HOT 1
- Likely race that can prevent to recycle closed connections HOT 5
- Return timeout error instead of Invalid connection err when read packet network timeout HOT 5
- 保存时报错:Prepared statement contains too many placeholders
- too may ram usage when lost connection HOT 13
- SEGV writing packet HOT 1
- Connection liveness/goodeness check and AWS Aurora HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mysql.