Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • November 19, 2017, 02:42 AM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: MySQL Syntax Question  (Read 471 times)

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,400
    • View Profile
    • Donate to Member
MySQL Syntax Question
« on: October 18, 2017, 09:34 AM »
Okay, so I managed to get myself roped into a development project involving a web portal/reservation system that is huge (300,000+ lines of code), that was previously worked on by 3 other people - All of which (of course) had radically different coding styles.

...And most of the code comments are in Portuguese.. Which would be ok...if the half of me that is Portuguese, could actually read Portuguese ... But apparently I'm not quite that good at being Portuguese ... So in a nutshell, I'm F'ed :D

Anyhow... One of the thinks that I keep running across in the code - aside from the insanely excessive use of the (select all columns) asterisk - is the equally infuriating excessive use of 'like' - Example:

Code: Text [Select]
  1. SELECT * FROM table WHERE id LIKE '$id'

...Which to me means 'Where like exactly this' because there are no %'s used to allow the search to fuzz. So my question is, is there by chance some vaguely/obscure reason for this seeming insanity, or is it really ~'like'~ just as dumb as I think it is?


mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 37,597
    • View Profile
    • Donate to Member
Re: MySQL Syntax Question
« Reply #1 on: October 18, 2017, 09:43 AM »

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,051
    • View Profile
    • Donate to Member
Re: MySQL Syntax Question
« Reply #2 on: October 18, 2017, 10:32 AM »
I'd say its just lazy/stupid programming, assuming (something like "database design"...) that 'id' is of numeric type, so LIKE isn't going to work on that anyways, ever. (unless when using this kludge...)

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,400
    • View Profile
    • Donate to Member
Re: MySQL Syntax Question
« Reply #3 on: October 18, 2017, 11:19 AM »
Cool, thanks guys!

I had a feeling it was just totally borked (they actually used like on an integer), but being entirely self taught I thought it couldn't hurt to double check myself.

This project has been a total horror show. From finding 56 if statements in a row (Yeah...) to finding if, if else, if else combinations that left no way of handling 'surprises' ... And much of the rest of the code is just total shit.

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 8,994
    • View Profile
    • Donate to Member
Re: MySQL Syntax Question
« Reply #4 on: October 18, 2017, 11:22 AM »
Hope you're getting paid hourly...

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 37,597
    • View Profile
    • Donate to Member
Re: MySQL Syntax Question
« Reply #5 on: October 18, 2017, 11:29 AM »
Code: Text [Select]
  1. SELECT * FROM table WHERE id LIKE '$id'

Just make sure before you change it to an = that the $id variable is never used with % inside it to do a wildcard search.

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,400
    • View Profile
    • Donate to Member
Re: MySQL Syntax Question
« Reply #6 on: October 18, 2017, 01:13 PM »
Code: Text [Select]
  1. SELECT * FROM table WHERE id LIKE '$id'

Just make sure before you change it to an = that the $id variable is never used with % inside it to do a wildcard search.

Oh I passed that point months ago (been on this since April) ... It just finally got to me this morning. One of the other more glaring bits was a 1 page report that took almost 3 minutes to generate because of how badly it was coded. Now that same report only takes 300ms.

Hope you're getting paid hourly...

rofl ... Nope - Bid flat rate for job -  This is what's technically referred to as a huge fucking mistake.

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 8,994
    • View Profile
    • Donate to Member
Re: MySQL Syntax Question
« Reply #7 on: October 18, 2017, 02:33 PM »

Hope you're getting paid hourly...

rofl ... Nope - Bid flat rate for job -  This is what's technically referred to as a huge fucking mistake.

Vodka.  Lots of Vodka.  Might not make you feel better about it, but it will make you not care.  ;D