so, i'm trying to read through a file and run queries on that data. what i'm running into is if there's an apostrophe in the word, it screws up the sql query. how should i deal with this and in general what should i look for with strange sql input from files that might break my query. this is from a file so i'm more interested in what will break the query than security such as from a cgi script (where i do checking and use dbi's taint and the likes). however, if there is some sort of cleaner module i should use for general purposes, i'm all for that.
also, i've got bad data here, so i'm splitting by word, deduping, querying and deduping that. ah crap. just noticed that i should be splitting on what is in my tr and meant to put a - and not an =... oh well, it's not why i'm getting this err i've been trying to knock out.
here's the code:
while ( <FILE> ) { my $line = $_; chomp ($line); my @word = split / /, $line; $count = 0; while ( $word[ $count ] ) { $word[ $count ] =~ tr/^[\.\/\\=a-zA-Z]//; $count++; } foreach my $string ( @word ) { next if $uword{ $string } == 1; $uword{ $string } = 1; } } $count = 0; while ( my ($key, $value) = each(%uword) ) { my ( $owner, $om, $manager ); my $select = qq/SELECT r.owner, r.om, r.manager /; my $from = qq/FROM r, n /; my $where = qq/WHERE MATCH(r.owner, r.om, r.manager) AGAINST('+$ +key' IN BOOLEAN MODE) /; my $likedate = qq/AND n.time LIKE '$date%' /; my $join = qq/AND r.key = n.key/; my $query = $select . $from . $where . $likedate . $join; print "SQL: $query\n"; my $sth = $dbh->prepare( $query ); $sth->execute;
my error is:
SQL: SELECT r.owner, r.om, r.manager FROM r, n WHERE MATCH(r.owner, r. +om, r.manager) AGAINST('+Miller's' IN BOOLEAN MODE) AND n.time LIKE ' +2009%' AND r.key = n.key DBD::mysql::st execute failed: You have an error in your SQL syntax; c +heck the manual that corresponds to your MySQL server version for the + right syntax to use near 's' IN BOOLEAN MODE) AND n.time LIKE '2009% +' AND r.key = n.k' at line 1 at ./ssel.pl line 55, <FILE> line 57. DBD::mysql::st bind_columns failed: Statement has no result columns to + bind (perhaps you need to successfully call execute first) at ./ssel +.pl line 57, <FILE> line 57. DBD::mysql::st fetch failed: fetch() without execute() at ./ssel.pl li +ne 59, <FILE> line 57.
i'm needing to change the field names and variable names. so if something looks off, it was because of that.
In reply to cleaning up sql from file by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |