Re: ESQL/C question
Posted in 1995
} From: bvdcruys@egidius.rug.ac.be (Bart Van der Cruyssen) } Subject: Re: ESQL/C question } Date: 5 Apr 1995 07:23:53 GMT } Reply-To: bvdcruys@egidius.rug.ac.be (Bart Van der Cruyssen) } Organization: University of Ghent, Belgium } } wche@ucs.att.com (wche@ucs.att.com) wrote: } : The call } : rgetmsg((short) -206, errmsg, (short) sizeof(errmsg)); } : returns the folling in errmsg: } : The specified table (%s) is not in the database. } : Why is %s, instead of the table name, showing up ?? } : Any help will be greatly appreciated. } : wche@ucs.att.com } } This information (e.g. table name) can found as part of the } sqlca structure. The 'char sqlerrm[72]' field contains the } error message parameters. This can be used to fill in the } '%s' in the errmsg. One has to write something like : } } if (!rgetmsg(nr, errmsg, (short) sizeof(errmsg))) } printf(errmsg, sqlca.sqlerrm); } } Hope this helps. } -- } ----------------------------------------------------------- } Bart Van der Cruyssen Bart.VanderCruyssen@rug.ac.be As written, your if (...) printf (...); statement is rather dangerous. Not all returned messages contain format specifiers like %s. If you try to printf a list with a format string that contains no specifiers, your program could go into an infinite loop, or seg fault, or some other nasty error. If you want a general error handler, you should check for the presence of format specifiers in the error message before using the message as a format string. If you don't want something quite so general, you should have different printf statements depending on the error number or similar criterion. Regards, Alan +---------------------------+-----------------------------------------------+ | R. Alan Popiel | Internet: alan@den.mmc.com | | Lockheed Martin, SLS | Voice: 303-977-9998 | | P.O. Box 179, M/S 3810 | Standard disclaimers apply. Cutesy ones, too. | | Denver, CO 80201-0179 USA | Your mileage may vary. Void where prohibited. | +---------------------------+-----------------------------------------------+