This is My First Time. Be Gentle.

RHH4292's profile image RHH4292 posted 4 months ago in General Permalink

I'm 84 yo and trying to learn web development which has taken me to MySQL which has taken me to Heidi. I'm not a complete newb; I spent a career in IT using ancient tools (COBOL/PL1/BAL). I decided to do this as a hobby. I've learned my way around HTML and CSS and a bit of javascript (but no PHP, yet). I've built a small db to serve my website.

My post today is to ask about using Heidi UI to implement REGEX constraints. I want to put contraints for US phone numbers and for email fields that occur in several of my tables.

I have searched and found intructions to use Heidi to set REGEX constraints but have been unable to follow them because, apparently, they don't address the way my version of Heidi (12.11.0.7065) displays so I can't find fields/menus/... they call for. I am trying to avoid using queries for the moment lest I get sucked into a MySQL learning curve. For now, I just want to learn to use Heidi to the fullest.

So . . . if anyone can point me to instructions for using Heidi that a 4-year old with 80 in front of it can use, I'd be very grateful.

ansgar's profile image ansgar posted 4 months ago Permalink

Respect for learning complex things at your age!

A table can have such "check constraints". See the screenshot below where you find them in HeidiSQL.

Just click the Add button, then head over to the check clause. A simple constraint can be seen in the image as well - this checks the "Operator" column gets a minimum length of 1 character when inserting or updating a row.

grafik.png

A check contraint based on a regular expression could look like so:

Operator REGEXP '^[[a-z]]'

Regular expressions in MySQL are explained here: https://dev.mysql.com/doc/refman/8.4/en/regexp.html#operator_regexp

RHH4292's profile image RHH4292 posted 4 months ago Permalink

Thank your for the response, ansgar.

I'm guessing, but does the CC1 in the Name column indicate the first constraint? Would this increment to CC2 if there were 2 constraints on the column? I was confused when this value populated when I tried to ADD a constraint.

Here are the steps you took as I understand your answer:

  1. select the table
  2. select the row
  3. click the Check Constraints tab
  4. click the ADD button
  5. click the Check clause tab
  6. enter the constraint to be applied

Is that close?

Again, thank you very much for the response.

ansgar's profile image ansgar posted 4 months ago Permalink

Yes, that's roughly it. Only point 2. confused me - not sure which row you mean.

And yes, "CC1" is just a name, given by HeidiSQL to the first check constraint. You can overwrite it, but the name does not really do anything.

RHH4292's profile image RHH4292 posted 4 months ago Permalink

Thank you, again, ansgar, for the response.

"Yes, that's roughly it. Only point 2. confused me - not sure which row you mean."

By 'select the row' I meant that one selects the table and the column. Heidi presents column names as rows and I conflated that positioning and chose the wrong term. Sorry.

As for the "CC1", I see it as an identifier with no other meaning or use, but I prefer to use a term like "chk_email_format" if setting a REGEX constraint for checking email entries.

Again, thank you for the posts and for clearing up my confusion.

Please login to leave a reply, or register at first.