From: | Yvon Thoraval <yvon(dot)thoraval(at)gmail(dot)com> |
---|---|
To: | Chris Angelico <rosuav(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: problem with serial |
Date: | 2012-04-19 18:21:08 |
Message-ID: | CAG6bkBwx6QdCiSFd4z-W9=ESLper7PyOt+b+TF__f3Knk3-xYg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
2012/4/19 Chris Angelico <rosuav(at)gmail(dot)com>
>
> No; ditch them. I mean no offense to you personally, but these
> functions are not worth keeping. Every SQL API includes a function for
> quoting something as a literal string. With PDO, it's this one:
>
> http://www.php.net/manual/en/pdo.quote.php
>
> I don't know where you would be using sql2str, but it's just as
> dangerous as the others (not to mention inefficient, there's no need
> to use regular expressions for simple string replacement). Replace all
> your calls to any of these functions with standard quoting functions
> and see if your problem disappears. If not, well, it's still not been
> a fruitless exercise, because now you are relying for safety and
> security on something that the database engine promises is correct :)
>
OK, OK, this comes from an old workaround with SQLite3...
I put the query into a try / catch like that :
$sql="INSERT INTO categories (idx, ctime, mtime, name) VALUES (
$idx, '$dat', '$dat', '".str2sql(quoteAsAre($name))."' ) RETURNING rowid;";
$xml.="<sql>$sql</sql>";
try {
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$ret=$db->query($sql);
$row=$ret->fetch();
$rowid=$row['rowid'];
$xml.="<rowid>$rowid</rowid>";
} catch (PDOException $e) {
$xml.="<PDOException>".$e->getMessage()."</PDOException>";
}
with that i can read the sql and the error.
I'l follow your advice about quoting, ASAP )))
--
Yvon
From | Date | Subject | |
---|---|---|---|
Next Message | Raymond O'Donnell | 2012-04-19 19:07:40 | Re: problem with serial |
Previous Message | Peter Eisentraut | 2012-04-19 18:11:32 | Re: Compile docs on ArchLinux |