this post was submitted on 25 Nov 2023
41 points (95.6% liked)
Programming
17489 readers
205 users here now
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Rules
- Follow the programming.dev instance rules
- Keep content related to programming in some way
- If you're posting long videos try to add in some form of tldr for those who don't want to watch videos
Wormhole
Follow the wormhole through a path of communities [email protected]
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Write a function or macro so you can reuse them. The project I work on has dozens of debug assisting code paths. Here are two examples: normally when talking to the db you'll call
run($sql, $boundVariables)
on a handle. Alternatively you can calldebug($sql, $boundVariables)
to have the handle run the query normally then rerun the query prefixed withEXPLAIN (blah,blah)
to get the execution plan. We also haveassembleEmulatedQuery($sql, $boundVariables)
which will manually replace all the binding tokens in the SQL with their values, do some string escaping and return a big honking string that you can dump into the database... that last one is useful for performance tuning since it can be used to easily capture expensive query forms. Also - assembleEmulatedQuery will throw an exception on our production environment because it's unsafe due to the potential of SQL Injection.Build debugging functions and add tests over them - future you will thank you!