in reply to A Little review for a little DBI and CGI?

coolmichael, if this is your first useful piece of code, as you say, you are doing quite well. I can see that the advice from more experienced monks is influencing your coding style. With that said, I have a few comments:

That's all the suggestions I have for now. All in all your code is quite good, please don't take the length of the review as an insult. I wanted to explain each point so that you, and others, understood the significance of each point I was trying to make.

Replies are listed 'Best First'.
Re: (dkubb) Re: (2) A Little review for a little DBI and CGI?
by coolmichael (Deacon) on Mar 28, 2001 at 13:38 UTC
    I am thrilled to have so many comments. Thank you dkubb.

    I've got taint checking on now, and I use $q=CGI->new. Eventually, I want to write a function that dies gracefully, printing an error to the web browser before it dies. I don't think I want to use CGI::Carp "fatalsToBrowser" as that gives too much information to the nasty people that might be using the stuff. I've changed the sql statement and untainted $criteria, so it has to be only letters and numbers. It was a bit of a pain getting the place holder to work, but eventually...

    I don't take such a long critique personally. I'm quite happy to recieve positive and constructive comments. Thank you again.

    Unfortunatly, now that it's working so well, I've discovered a bug and need some help. The data is comming from a paradox database. Paradox is able to export it to CSV but isn't smart enough to escape the quote in the titles. I've been looking for a regex on the monastery to add escapes, but haven't found one yet. Do you have any suggestions?

      Ugh. What if you have a title of 'Why "foo", "bar", and "baz"?' and it gets written to a CSV file as: ...,16,"Why "foo", "bar", and "baz"?",20,... then how do you expect to be able to tell which "s need to be escaped??

      Well, I'll try me best... Let's assume that no title contains a string matching /",\S/ and that there is never whitespace after a comma in your CSV file.

      s{ \G( [^",]+ | "(.*?)" )(,(?=\S)|$) }{ if( ! $2 ) { $1.$3; } else { my $f= $2; $f =~ s/"/""/g; '"'.$f.'"'.$2; } }gx;

      If you do have whitespace after commas, then an alternate solution would be to assume that all titles that contain "s always contain an even number of quotes and that the first character after the first quote of a pair isn't a comma:

      s{ \G( [^",]+ | "((?: [^"]+ | "" | "[^",][^"]*" ))*" )(,|$) }{ if( ! $2 ) { $1.$3; } else { my $f= $2; $f =~ s/"/""/g; '"'.$f.'"'.$2; } }gx;
      I hope one of those helps. (Sorry, they aren't tested. Just tell me which one matches your situation and I'll be happy to help if there are bugs.)

              - tye (but my friends call me "Tye")
        Unfortunatly, neither situation applies. Some of the titles have only one quote in them, some have three or four. Some of the quotes have commas after them. The solution I've decided to go with is editing the paradox database to get rid of the commas. Find and Replace, yeah, baby, yeah. Groovy.

        I think it'll be the only reliable way to do it, and it'll probably fix some of the errors the database has been having.

        /me crosses his fingers.

      coolmichael,
      Add escapes? quotemeta() is your friend.

      -marius