Branching if statements
so. i have some data in a database that needs to be assigned data based on an id.
I have a database full of items, and each item has attributes. lets say they are tools. the id could be
HAMMERSTEEL.10
or HAMMERIRON12.12
. the first one means it's a 10" long steel hammer with a standard head size and the second one is a 12" long iron hammer with a 12mm head or something of that nature. i have at least four different base types HAMMER
AXE
SCREWDRIVER
. I need to assign attributes in a new table based on the item id's. what i already have is a database filled with what i want the data to look like. i'll read in hte item id HAMMERSTEEL.10
and then i'll asign the attributes in another table.
for example:
I want to cut down on the amount of branching if statements. any suggestions?12 Replies
If you could reasonable split those strings into
item
, material
, size
then sure, you could use a switch
If you rely on regex, then no
if...else
chain it is
If the items are limited, you could reasonably split it with reges, ig
(hammer|axe|screwdriver)\w+(0-9\.)+
or some suchStoring things like the length in the textual ID seems like a kind of questionable design choice.
But with capture groups
Oh yeah, I would absolutely never store data as
JOHNDOE42
yeah. it's a problem i can't really fix immediately
that's the way it was before i got here
interesting. i guess that's the best way to do it
yeah i can reliably do that. i just hate the idea of branching if statements
https://regex101.com/r/uy8HRT/1 this regex seems to be doing working
Again, assuming the list of tools is limited
i see what you did there.
yes it will be limited by what i know works in our database
everything else will be addressed afterwards.
https://regex101.com/r/FOMAob/1 will work, actually
The previous one didn't work for
SCREWDRIWERCOPPER18.
actually that's pretty nifty
mind if i copy and play with it to make it match what i actually am working with
Go ahead
ty
Any recommendations?
Store it in a separate column / field?
Lol. Well thats what im gonna do now.
Idk what happened 5 years ago to make them do this
Thanks anyways
Also the fact of the matter is its a database that we didnt design
I have to convert the data from a limited CRM/ERP system to usable for an ecommerce site