Re: Getting error messages to the (PHP) user
"James K. Lowden" <[email protected]>
| Newsgroups | gmane.comp.db.tds.freetds |
|---|---|
| Message-ID | <[email protected]> |
On Tue, 05 Mar 2013 11:31:27 -0500 "Mark A. Hershberger" <[email protected]> wrote: > On 03/05/2013 10:45 AM, James K. Lowden wrote: > > Server messages arrive with a severity code. By convention, > > severity codes >= 10 are "errors" in the sense that the user can't > > fix them. > > But I'm seeing the hard-coded message for errors in my SQL that *I* > should fix. > > For example, I was getting the hard-coded message till I patched the > freetds library. Now I see the following: > > $ php import-sql.php > Error: [HY000] Incorrect syntax near 'AUTO_INCREMENT'. [102] > (severity 15) [CREATE TABLE ...] > > Yes, I know that this is MySQL code and I need MSSQL code. The point > here is that the error message and the severity and the severity (15 > > 10) is the direct result of something I can fix. Right. The "user" they meant isn't you the programmer, but a user of your application. If the data entered fail a contraint, the user can change the data and continue. Broken SQL is a severe problem in a production application, as I'm sure you agree! :-) It's not intended that you should have to change the FreeTDS code to alter the error-handling characteristics. db-lib itself never prints a anything in response to a server message or a library error. (This can be frustrating to someone just learning, but as you see it's helpful.) Instead, db-lib provides for the application -- in this case the PHP library -- to install a callback function. Errors and messages are passed to the installed function, which does what it does. If you look at the bsqldb application (src/apps/bsqldb.c) you'll see calls to dberrhandle() and dbmsghandle(). The function definitions are at the end of the source file. I don't know PHP. To control the error reporting behavior, you need either to change the callback function PHP installs, or somehow affect what it does. In applications I've written, for example, there was sometimes a list of message numbers that were suppressed. In your case, it sounds like you probably want to log the details and report a more naïve message. (I'm not sure I support that idea, but that's another question.) HTH. --jkl