Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Does anyone do database tier field validation?

Does anyone do database tier field validation?

Scheduled Pinned Locked Moved The Lounge
databasesql-serversysadminregextutorial
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    honey the codewitch
    wrote on last edited by
    #1

    A looong time ago, as part of a middleware builder I wrote, it would generate SQL-DDL scripts to create tables and the stored procedures necessary to access them. One of the things it did was use text cursors to run regular expressions over fields to validate them. Basically, it generated the SQL code to use a table based state machine to walk the fields and validate a regular expression so that if you passed a phone number or an email address in as a string it would reject invalid candidates. The same thing happened at the middle tier, and at the front end web page, so no matter how you hit it, it would *not* let you put invalid data in the database. I've almost never seen this done in practice elsewhere, but it has been a long time since I've done this kind of development professionally, and I was wondering how common a practice it is (maybe using some of the newfangled SQL Server features for example) to do granular field validation like that? One reason I ask is because I have a tool that can potentially generate the SQL-DDL scripts to do this, but I don't know how useful it would be to people in practice.

    Real programmers use butterflies

    P M 2 Replies Last reply
    0
    • H honey the codewitch

      A looong time ago, as part of a middleware builder I wrote, it would generate SQL-DDL scripts to create tables and the stored procedures necessary to access them. One of the things it did was use text cursors to run regular expressions over fields to validate them. Basically, it generated the SQL code to use a table based state machine to walk the fields and validate a regular expression so that if you passed a phone number or an email address in as a string it would reject invalid candidates. The same thing happened at the middle tier, and at the front end web page, so no matter how you hit it, it would *not* let you put invalid data in the database. I've almost never seen this done in practice elsewhere, but it has been a long time since I've done this kind of development professionally, and I was wondering how common a practice it is (maybe using some of the newfangled SQL Server features for example) to do granular field validation like that? One reason I ask is because I have a tool that can potentially generate the SQL-DDL scripts to do this, but I don't know how useful it would be to people in practice.

      Real programmers use butterflies

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      Not really, but the applications I work on don't take user input. My responsibility is pretty much just ETLing data from other places into a staging database (mostly with SSIS). There are some places where we check for IP addresses (in particular), but that's about it. And to do IP addresses, I wrote a CLR Function which uses .net's System.Net.IPAddress class to convert to VARBINARY(16) or return null.

      H 1 Reply Last reply
      0
      • P PIEBALDconsult

        Not really, but the applications I work on don't take user input. My responsibility is pretty much just ETLing data from other places into a staging database (mostly with SSIS). There are some places where we check for IP addresses (in particular), but that's about it. And to do IP addresses, I wrote a CLR Function which uses .net's System.Net.IPAddress class to convert to VARBINARY(16) or return null.

        H Offline
        H Offline
        honey the codewitch
        wrote on last edited by
        #3

        Spinning up the CLR/CLI inside an RDBMS makes me feel dirty.

        Real programmers use butterflies

        P 1 Reply Last reply
        0
        • H honey the codewitch

          Spinning up the CLR/CLI inside an RDBMS makes me feel dirty.

          Real programmers use butterflies

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          Yeah, baby! :cool: It's there anyway. And much faster than so many SQL-implemented chores -- text handling in particular.

          1 Reply Last reply
          0
          • H honey the codewitch

            A looong time ago, as part of a middleware builder I wrote, it would generate SQL-DDL scripts to create tables and the stored procedures necessary to access them. One of the things it did was use text cursors to run regular expressions over fields to validate them. Basically, it generated the SQL code to use a table based state machine to walk the fields and validate a regular expression so that if you passed a phone number or an email address in as a string it would reject invalid candidates. The same thing happened at the middle tier, and at the front end web page, so no matter how you hit it, it would *not* let you put invalid data in the database. I've almost never seen this done in practice elsewhere, but it has been a long time since I've done this kind of development professionally, and I was wondering how common a practice it is (maybe using some of the newfangled SQL Server features for example) to do granular field validation like that? One reason I ask is because I have a tool that can potentially generate the SQL-DDL scripts to do this, but I don't know how useful it would be to people in practice.

            Real programmers use butterflies

            M Offline
            M Offline
            megaadam
            wrote on last edited by
            #5

            A rather similar question came up hear maybe half a year ago. That poster got "corrected" for insisting that browser input validation was enuff. I would say: that DB-level validation is absolutely mandatory to protect the DB from data corruption. E.g. somebody my try to enter data with their own client (out of malice or just curiosity). Having data validation-as-you-type is matter of user friendliness. Eg I hate sites that tell you that the password I just entered twice needs more stuff, after having chewed on the entire form for bit.

            "If we don't change direction, we'll end up where we're going"

            D P 2 Replies Last reply
            0
            • M megaadam

              A rather similar question came up hear maybe half a year ago. That poster got "corrected" for insisting that browser input validation was enuff. I would say: that DB-level validation is absolutely mandatory to protect the DB from data corruption. E.g. somebody my try to enter data with their own client (out of malice or just curiosity). Having data validation-as-you-type is matter of user friendliness. Eg I hate sites that tell you that the password I just entered twice needs more stuff, after having chewed on the entire form for bit.

              "If we don't change direction, we'll end up where we're going"

              D Offline
              D Offline
              Dan Neely
              wrote on last edited by
              #6

              megaadam wrote:

              I would say: that DB-level validation is absolutely mandatory to protect the DB from data corruption. E.g. somebody my try to enter data with their own client (out of malice or just curiosity).

              Unless you're in a situation where arbitrary applications can write to your database, serverside validation is sufficient. If you have a big-One company database that dozens of different applications use, well Codethulu help you (because no lesser gods can); and yeah then you probably do need to do validation in the DB.

              Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius

              1 Reply Last reply
              0
              • M megaadam

                A rather similar question came up hear maybe half a year ago. That poster got "corrected" for insisting that browser input validation was enuff. I would say: that DB-level validation is absolutely mandatory to protect the DB from data corruption. E.g. somebody my try to enter data with their own client (out of malice or just curiosity). Having data validation-as-you-type is matter of user friendliness. Eg I hate sites that tell you that the password I just entered twice needs more stuff, after having chewed on the entire form for bit.

                "If we don't change direction, we'll end up where we're going"

                P Offline
                P Offline
                PIEBALDconsult
                wrote on last edited by
                #7

                One problem is that SQL-implemented routines often perform poorly, so "doing it in code" is preferred. So what about when using a Web Service as the front door to the database -- and not allowing direct access to the database? All clients have to go through the front door.

                H 1 Reply Last reply
                0
                • P PIEBALDconsult

                  One problem is that SQL-implemented routines often perform poorly, so "doing it in code" is preferred. So what about when using a Web Service as the front door to the database -- and not allowing direct access to the database? All clients have to go through the front door.

                  H Offline
                  H Offline
                  honey the codewitch
                  wrote on last edited by
                  #8

                  That works depending on the situation, and depending on how much confidence you have in your DMZ being adequately hardened. When the database is on a LAN, things become a bit different, but even if it's hooked to web facing internet servers behind a DMZ there is always the chance your webserver gets hacked, and when that happens, they at least have the same access to the database the webserver does. If the database is hardened with routines like this it can at least limit some of the damage.

                  Real programmers use butterflies

                  P 1 Reply Last reply
                  0
                  • H honey the codewitch

                    That works depending on the situation, and depending on how much confidence you have in your DMZ being adequately hardened. When the database is on a LAN, things become a bit different, but even if it's hooked to web facing internet servers behind a DMZ there is always the chance your webserver gets hacked, and when that happens, they at least have the same access to the database the webserver does. If the database is hardened with routines like this it can at least limit some of the damage.

                    Real programmers use butterflies

                    P Offline
                    P Offline
                    PIEBALDconsult
                    wrote on last edited by
                    #9

                    Yeah, see? I don't do that Web stuff. :| I stay in the back end and keep my head down.

                    H 1 Reply Last reply
                    0
                    • P PIEBALDconsult

                      Yeah, see? I don't do that Web stuff. :| I stay in the back end and keep my head down.

                      H Offline
                      H Offline
                      honey the codewitch
                      wrote on last edited by
                      #10

                      I *am* talking about the backend. This is a statement about infrastructure, not front end coding. If your DB is on a LAN, there's a good chance there's no DMZ which means a disgruntled employee could poison the database, probably pretty easily, unless there's security on the tables and validation.

                      Real programmers use butterflies

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups