codekingpro/portable-devtools
115k
1<?xml version="1.0" encoding="UTF-8" standalone="no"?>2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>36.8. Error Handling</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="ecpg-descriptors.html" title="36.7. Using Descriptor Areas" /><link rel="next" href="ecpg-preproc.html" title="36.9. Preprocessor Directives" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">36.8. Error Handling</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="ecpg-descriptors.html" title="36.7. Using Descriptor Areas">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="ecpg.html" title="Chapter 36. ECPG — Embedded SQL in C">Up</a></td><th width="60%" align="center">Chapter 36. <span class="application">ECPG</span> — Embedded <acronym class="acronym">SQL</acronym> in C</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="ecpg-preproc.html" title="36.9. Preprocessor Directives">Next</a></td></tr></table><hr /></div><div class="sect1" id="ECPG-ERRORS"><div class="titlepage"><div><div><h2 class="title" style="clear: both">36.8. Error Handling <a href="#ECPG-ERRORS" class="id_link">#</a></h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="ecpg-errors.html#ECPG-WHENEVER">36.8.1. Setting Callbacks</a></span></dt><dt><span class="sect2"><a href="ecpg-errors.html#ECPG-SQLCA">36.8.2. sqlca</a></span></dt><dt><span class="sect2"><a href="ecpg-errors.html#ECPG-SQLSTATE-SQLCODE">36.8.3. <code class="literal">SQLSTATE</code> vs. <code class="literal">SQLCODE</code></a></span></dt></dl></div><p>3 This section describes how you can handle exceptional conditions4 and warnings in an embedded SQL program. There are two5 nonexclusive facilities for this.6 7 </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">8 Callbacks can be configured to handle warning and error9 conditions using the <code class="literal">WHENEVER</code> command.10 </li><li class="listitem">11 Detailed information about the error or warning can be obtained12 from the <code class="varname">sqlca</code> variable.13 </li></ul></div><p>14 </p><div class="sect2" id="ECPG-WHENEVER"><div class="titlepage"><div><div><h3 class="title">36.8.1. Setting Callbacks <a href="#ECPG-WHENEVER" class="id_link">#</a></h3></div></div></div><p>15 One simple method to catch errors and warnings is to set a16 specific action to be executed whenever a particular condition17 occurs. In general:18</p><pre class="programlisting">19EXEC SQL WHENEVER <em class="replaceable"><code>condition</code></em> <em class="replaceable"><code>action</code></em>;20</pre><p>21 </p><p>22 <em class="replaceable"><code>condition</code></em> can be one of the following:23 24 </p><div class="variablelist"><dl class="variablelist"><dt id="ECPG-WHENEVER-SQLERROR"><span class="term"><code class="literal">SQLERROR</code></span> <a href="#ECPG-WHENEVER-SQLERROR" class="id_link">#</a></dt><dd><p>25 The specified action is called whenever an error occurs during26 the execution of an SQL statement.27 </p></dd><dt id="ECPG-WHENEVER-SQLWARNING"><span class="term"><code class="literal">SQLWARNING</code></span> <a href="#ECPG-WHENEVER-SQLWARNING" class="id_link">#</a></dt><dd><p>28 The specified action is called whenever a warning occurs29 during the execution of an SQL statement.30 </p></dd><dt id="ECPG-WHENEVER-NOT-FOUND"><span class="term"><code class="literal">NOT FOUND</code></span> <a href="#ECPG-WHENEVER-NOT-FOUND" class="id_link">#</a></dt><dd><p>31 The specified action is called whenever an SQL statement32 retrieves or affects zero rows. (This condition is not an33 error, but you might be interested in handling it specially.)34 </p></dd></dl></div><p>35 </p><p>36 <em class="replaceable"><code>action</code></em> can be one of the following:37 38 </p><div class="variablelist"><dl class="variablelist"><dt id="ECPG-WHENEVER-CONTINUE"><span class="term"><code class="literal">CONTINUE</code></span> <a href="#ECPG-WHENEVER-CONTINUE" class="id_link">#</a></dt><dd><p>39 This effectively means that the condition is ignored. This is40 the default.41 </p></dd><dt id="ECPG-WHENEVER-GOTO"><span class="term"><code class="literal">GOTO <em class="replaceable"><code>label</code></em></code><br /></span><span class="term"><code class="literal">GO TO <em class="replaceable"><code>label</code></em></code></span> <a href="#ECPG-WHENEVER-GOTO" class="id_link">#</a></dt><dd><p>42 Jump to the specified label (using a C <code class="literal">goto</code>43 statement).44 </p></dd><dt id="ECPG-WHENEVER-SQLPRINT"><span class="term"><code class="literal">SQLPRINT</code></span> <a href="#ECPG-WHENEVER-SQLPRINT" class="id_link">#</a></dt><dd><p>45 Print a message to standard error. This is useful for simple46 programs or during prototyping. The details of the message47 cannot be configured.48 </p></dd><dt id="ECPG-WHENEVER-STOP"><span class="term"><code class="literal">STOP</code></span> <a href="#ECPG-WHENEVER-STOP" class="id_link">#</a></dt><dd><p>49 Call <code class="literal">exit(1)</code>, which will terminate the50 program.51 </p></dd><dt id="ECPG-WHENEVER-DO-BREAK"><span class="term"><code class="literal">DO BREAK</code></span> <a href="#ECPG-WHENEVER-DO-BREAK" class="id_link">#</a></dt><dd><p>52 Execute the C statement <code class="literal">break</code>. This should53 only be used in loops or <code class="literal">switch</code> statements.54 </p></dd><dt id="ECPG-WHENEVER-DO-CONTINUE"><span class="term"><code class="literal">DO CONTINUE</code></span> <a href="#ECPG-WHENEVER-DO-CONTINUE" class="id_link">#</a></dt><dd><p>55 Execute the C statement <code class="literal">continue</code>. This should56 only be used in loops statements. if executed, will cause the flow57 of control to return to the top of the loop.58 </p></dd><dt id="ECPG-WHENEVER-CALL"><span class="term"><code class="literal">CALL <em class="replaceable"><code>name</code></em> (<em class="replaceable"><code>args</code></em>)</code><br /></span><span class="term"><code class="literal">DO <em class="replaceable"><code>name</code></em> (<em class="replaceable"><code>args</code></em>)</code></span> <a href="#ECPG-WHENEVER-CALL" class="id_link">#</a></dt><dd><p>59 Call the specified C functions with the specified arguments. (This60 use is different from the meaning of <code class="literal">CALL</code>61 and <code class="literal">DO</code> in the normal PostgreSQL grammar.)62 </p></dd></dl></div><p>63 64 The SQL standard only provides for the actions65 <code class="literal">CONTINUE</code> and <code class="literal">GOTO</code> (and66 <code class="literal">GO TO</code>).67 </p><p>68 Here is an example that you might want to use in a simple program.69 It prints a simple message when a warning occurs and aborts the70 program when an error happens:71</p><pre class="programlisting">72EXEC SQL WHENEVER SQLWARNING SQLPRINT;73EXEC SQL WHENEVER SQLERROR STOP;74</pre><p>75 </p><p>76 The statement <code class="literal">EXEC SQL WHENEVER</code> is a directive77 of the SQL preprocessor, not a C statement. The error or warning78 actions that it sets apply to all embedded SQL statements that79 appear below the point where the handler is set, unless a80 different action was set for the same condition between the first81 <code class="literal">EXEC SQL WHENEVER</code> and the SQL statement causing82 the condition, regardless of the flow of control in the C program.83 So neither of the two following C program excerpts will have the84 desired effect:85</p><pre class="programlisting">86/*87 * WRONG88 */89int main(int argc, char *argv[])90{91 ...92 if (verbose) {93 EXEC SQL WHENEVER SQLWARNING SQLPRINT;94 }95 ...96 EXEC SQL SELECT ...;97 ...98}99</pre><p>100 101</p><pre class="programlisting">102/*103 * WRONG104 */105int main(int argc, char *argv[])106{107 ...108 set_error_handler();109 ...110 EXEC SQL SELECT ...;111 ...112}113 114static void set_error_handler(void)115{116 EXEC SQL WHENEVER SQLERROR STOP;117}118</pre><p>119 </p></div><div class="sect2" id="ECPG-SQLCA"><div class="titlepage"><div><div><h3 class="title">36.8.2. sqlca <a href="#ECPG-SQLCA" class="id_link">#</a></h3></div></div></div><p>120 For more powerful error handling, the embedded SQL interface121 provides a global variable with the name <code class="varname">sqlca</code>122 (SQL communication area)123 that has the following structure:124</p><pre class="programlisting">125struct126{127 char sqlcaid[8];128 long sqlabc;129 long sqlcode;130 struct131 {132 int sqlerrml;133 char sqlerrmc[SQLERRMC_LEN];134 } sqlerrm;135 char sqlerrp[8];136 long sqlerrd[6];137 char sqlwarn[8];138 char sqlstate[5];139} sqlca;140</pre><p>141 (In a multithreaded program, every thread automatically gets its142 own copy of <code class="varname">sqlca</code>. This works similarly to the143 handling of the standard C global variable144 <code class="varname">errno</code>.)145 </p><p>146 <code class="varname">sqlca</code> covers both warnings and errors. If147 multiple warnings or errors occur during the execution of a148 statement, then <code class="varname">sqlca</code> will only contain149 information about the last one.150 </p><p>151 If no error occurred in the last <acronym class="acronym">SQL</acronym> statement,152 <code class="literal">sqlca.sqlcode</code> will be 0 and153 <code class="literal">sqlca.sqlstate</code> will be154 <code class="literal">"00000"</code>. If a warning or error occurred, then155 <code class="literal">sqlca.sqlcode</code> will be negative and156 <code class="literal">sqlca.sqlstate</code> will be different from157 <code class="literal">"00000"</code>. A positive158 <code class="literal">sqlca.sqlcode</code> indicates a harmless condition,159 such as that the last query returned zero rows.160 <code class="literal">sqlcode</code> and <code class="literal">sqlstate</code> are two161 different error code schemes; details appear below.162 </p><p>163 If the last SQL statement was successful, then164 <code class="literal">sqlca.sqlerrd[1]</code> contains the OID of the165 processed row, if applicable, and166 <code class="literal">sqlca.sqlerrd[2]</code> contains the number of167 processed or returned rows, if applicable to the command.168 </p><p>169 In case of an error or warning,170 <code class="literal">sqlca.sqlerrm.sqlerrmc</code> will contain a string171 that describes the error. The field172 <code class="literal">sqlca.sqlerrm.sqlerrml</code> contains the length of173 the error message that is stored in174 <code class="literal">sqlca.sqlerrm.sqlerrmc</code> (the result of175 <code class="function">strlen()</code>, not really interesting for a C176 programmer). Note that some messages are too long to fit in the177 fixed-size <code class="literal">sqlerrmc</code> array; they will be truncated.178 </p><p>179 In case of a warning, <code class="literal">sqlca.sqlwarn[2]</code> is set180 to <code class="literal">W</code>. (In all other cases, it is set to181 something different from <code class="literal">W</code>.) If182 <code class="literal">sqlca.sqlwarn[1]</code> is set to183 <code class="literal">W</code>, then a value was truncated when it was184 stored in a host variable. <code class="literal">sqlca.sqlwarn[0]</code> is185 set to <code class="literal">W</code> if any of the other elements are set186 to indicate a warning.187 </p><p>188 The fields <code class="structfield">sqlcaid</code>,189 <code class="structfield">sqlabc</code>,190 <code class="structfield">sqlerrp</code>, and the remaining elements of191 <code class="structfield">sqlerrd</code> and192 <code class="structfield">sqlwarn</code> currently contain no useful193 information.194 </p><p>195 The structure <code class="varname">sqlca</code> is not defined in the SQL196 standard, but is implemented in several other SQL database197 systems. The definitions are similar at the core, but if you want198 to write portable applications, then you should investigate the199 different implementations carefully.200 </p><p>201 Here is one example that combines the use of <code class="literal">WHENEVER</code>202 and <code class="varname">sqlca</code>, printing out the contents203 of <code class="varname">sqlca</code> when an error occurs. This is perhaps204 useful for debugging or prototyping applications, before205 installing a more <span class="quote">“<span class="quote">user-friendly</span>”</span> error handler.206 207</p><pre class="programlisting">208EXEC SQL WHENEVER SQLERROR CALL print_sqlca();209 210void211print_sqlca()212{213 fprintf(stderr, "==== sqlca ====\n");214 fprintf(stderr, "sqlcode: %ld\n", sqlca.sqlcode);215 fprintf(stderr, "sqlerrm.sqlerrml: %d\n", sqlca.sqlerrm.sqlerrml);216 fprintf(stderr, "sqlerrm.sqlerrmc: %s\n", sqlca.sqlerrm.sqlerrmc);217 fprintf(stderr, "sqlerrd: %ld %ld %ld %ld %ld %ld\n", sqlca.sqlerrd[0],sqlca.sqlerrd[1],sqlca.sqlerrd[2],218 sqlca.sqlerrd[3],sqlca.sqlerrd[4],sqlca.sqlerrd[5]);219 fprintf(stderr, "sqlwarn: %d %d %d %d %d %d %d %d\n", sqlca.sqlwarn[0], sqlca.sqlwarn[1], sqlca.sqlwarn[2],220 sqlca.sqlwarn[3], sqlca.sqlwarn[4], sqlca.sqlwarn[5],221 sqlca.sqlwarn[6], sqlca.sqlwarn[7]);222 fprintf(stderr, "sqlstate: %5s\n", sqlca.sqlstate);223 fprintf(stderr, "===============\n");224}225</pre><p>226 227 The result could look as follows (here an error due to a228 misspelled table name):229 230</p><pre class="screen">231==== sqlca ====232sqlcode: -400233sqlerrm.sqlerrml: 49234sqlerrm.sqlerrmc: relation "pg_databasep" does not exist on line 38235sqlerrd: 0 0 0 0 0 0236sqlwarn: 0 0 0 0 0 0 0 0237sqlstate: 42P01238===============239</pre><p>240 </p></div><div class="sect2" id="ECPG-SQLSTATE-SQLCODE"><div class="titlepage"><div><div><h3 class="title">36.8.3. <code class="literal">SQLSTATE</code> vs. <code class="literal">SQLCODE</code> <a href="#ECPG-SQLSTATE-SQLCODE" class="id_link">#</a></h3></div></div></div><p>241 The fields <code class="literal">sqlca.sqlstate</code> and242 <code class="literal">sqlca.sqlcode</code> are two different schemes that243 provide error codes. Both are derived from the SQL standard, but244 <code class="literal">SQLCODE</code> has been marked deprecated in the SQL-92245 edition of the standard and has been dropped in later editions.246 Therefore, new applications are strongly encouraged to use247 <code class="literal">SQLSTATE</code>.248 </p><p>249 <code class="literal">SQLSTATE</code> is a five-character array. The five250 characters contain digits or upper-case letters that represent251 codes of various error and warning conditions.252 <code class="literal">SQLSTATE</code> has a hierarchical scheme: the first253 two characters indicate the general class of the condition, the254 last three characters indicate a subclass of the general255 condition. A successful state is indicated by the code256 <code class="literal">00000</code>. The <code class="literal">SQLSTATE</code> codes are for257 the most part defined in the SQL standard. The258 <span class="productname">PostgreSQL</span> server natively supports259 <code class="literal">SQLSTATE</code> error codes; therefore a high degree260 of consistency can be achieved by using this error code scheme261 throughout all applications. For further information see262 <a class="xref" href="errcodes-appendix.html" title="Appendix A. PostgreSQL Error Codes">Appendix A</a>.263 </p><p>264 <code class="literal">SQLCODE</code>, the deprecated error code scheme, is a265 simple integer. A value of 0 indicates success, a positive value266 indicates success with additional information, a negative value267 indicates an error. The SQL standard only defines the positive268 value +100, which indicates that the last command returned or269 affected zero rows, and no specific negative values. Therefore,270 this scheme can only achieve poor portability and does not have a271 hierarchical code assignment. Historically, the embedded SQL272 processor for <span class="productname">PostgreSQL</span> has assigned273 some specific <code class="literal">SQLCODE</code> values for its use, which274 are listed below with their numeric value and their symbolic name.275 Remember that these are not portable to other SQL implementations.276 To simplify the porting of applications to the277 <code class="literal">SQLSTATE</code> scheme, the corresponding278 <code class="literal">SQLSTATE</code> is also listed. There is, however, no279 one-to-one or one-to-many mapping between the two schemes (indeed280 it is many-to-many), so you should consult the global281 <code class="literal">SQLSTATE</code> listing in <a class="xref" href="errcodes-appendix.html" title="Appendix A. PostgreSQL Error Codes">Appendix A</a>282 in each case.283 </p><p>284 These are the assigned <code class="literal">SQLCODE</code> values:285 286 </p><div class="variablelist"><dl class="variablelist"><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-NO-ERROR"><span class="term">0 (<code class="symbol">ECPG_NO_ERROR</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-NO-ERROR" class="id_link">#</a></dt><dd><p>287 Indicates no error. (SQLSTATE 00000)288 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-NOT-FOUND"><span class="term">100 (<code class="symbol">ECPG_NOT_FOUND</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-NOT-FOUND" class="id_link">#</a></dt><dd><p>289 This is a harmless condition indicating that the last command290 retrieved or processed zero rows, or that you are at the end of291 the cursor. (SQLSTATE 02000)292 </p><p>293 When processing a cursor in a loop, you could use this code as294 a way to detect when to abort the loop, like this:295</p><pre class="programlisting">296while (1)297{298 EXEC SQL FETCH ... ;299 if (sqlca.sqlcode == ECPG_NOT_FOUND)300 break;301}302</pre><p>303 But <code class="literal">WHENEVER NOT FOUND DO BREAK</code> effectively304 does this internally, so there is usually no advantage in305 writing this out explicitly.306 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-OUT-OF-MEMORY"><span class="term">-12 (<code class="symbol">ECPG_OUT_OF_MEMORY</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-OUT-OF-MEMORY" class="id_link">#</a></dt><dd><p>307 Indicates that your virtual memory is exhausted. The numeric308 value is defined as <code class="literal">-ENOMEM</code>. (SQLSTATE309 YE001)310 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-UNSUPPORTED"><span class="term">-200 (<code class="symbol">ECPG_UNSUPPORTED</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-UNSUPPORTED" class="id_link">#</a></dt><dd><p>311 Indicates the preprocessor has generated something that the312 library does not know about. Perhaps you are running313 incompatible versions of the preprocessor and the314 library. (SQLSTATE YE002)315 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-TOO-MANY-ARGUMENTS"><span class="term">-201 (<code class="symbol">ECPG_TOO_MANY_ARGUMENTS</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-TOO-MANY-ARGUMENTS" class="id_link">#</a></dt><dd><p>316 This means that the command specified more host variables than317 the command expected. (SQLSTATE 07001 or 07002)318 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-TOO-FEW-ARGUMENTS"><span class="term">-202 (<code class="symbol">ECPG_TOO_FEW_ARGUMENTS</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-TOO-FEW-ARGUMENTS" class="id_link">#</a></dt><dd><p>319 This means that the command specified fewer host variables than320 the command expected. (SQLSTATE 07001 or 07002)321 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-TOO-MANY-MATCHES"><span class="term">-203 (<code class="symbol">ECPG_TOO_MANY_MATCHES</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-TOO-MANY-MATCHES" class="id_link">#</a></dt><dd><p>322 This means a query has returned multiple rows but the statement323 was only prepared to store one result row (for example, because324 the specified variables are not arrays). (SQLSTATE 21000)325 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-INT-FORMAT"><span class="term">-204 (<code class="symbol">ECPG_INT_FORMAT</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-INT-FORMAT" class="id_link">#</a></dt><dd><p>326 The host variable is of type <code class="type">int</code> and the datum in327 the database is of a different type and contains a value that328 cannot be interpreted as an <code class="type">int</code>. The library uses329 <code class="function">strtol()</code> for this conversion. (SQLSTATE330 42804)331 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-UINT-FORMAT"><span class="term">-205 (<code class="symbol">ECPG_UINT_FORMAT</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-UINT-FORMAT" class="id_link">#</a></dt><dd><p>332 The host variable is of type <code class="type">unsigned int</code> and the333 datum in the database is of a different type and contains a334 value that cannot be interpreted as an <code class="type">unsigned335 int</code>. The library uses <code class="function">strtoul()</code>336 for this conversion. (SQLSTATE 42804)337 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-FLOAT-FORMAT"><span class="term">-206 (<code class="symbol">ECPG_FLOAT_FORMAT</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-FLOAT-FORMAT" class="id_link">#</a></dt><dd><p>338 The host variable is of type <code class="type">float</code> and the datum339 in the database is of another type and contains a value that340 cannot be interpreted as a <code class="type">float</code>. The library341 uses <code class="function">strtod()</code> for this conversion.342 (SQLSTATE 42804)343 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-NUMERIC-FORMAT"><span class="term">-207 (<code class="symbol">ECPG_NUMERIC_FORMAT</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-NUMERIC-FORMAT" class="id_link">#</a></dt><dd><p>344 The host variable is of type <code class="type">numeric</code> and the datum345 in the database is of another type and contains a value that346 cannot be interpreted as a <code class="type">numeric</code> value.347 (SQLSTATE 42804)348 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-INTERVAL-FORMAT"><span class="term">-208 (<code class="symbol">ECPG_INTERVAL_FORMAT</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-INTERVAL-FORMAT" class="id_link">#</a></dt><dd><p>349 The host variable is of type <code class="type">interval</code> and the datum350 in the database is of another type and contains a value that351 cannot be interpreted as an <code class="type">interval</code> value.352 (SQLSTATE 42804)353 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-DATE-FORMAT"><span class="term">-209 (<code class="symbol">ECPG_DATE_FORMAT</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-DATE-FORMAT" class="id_link">#</a></dt><dd><p>354 The host variable is of type <code class="type">date</code> and the datum in355 the database is of another type and contains a value that356 cannot be interpreted as a <code class="type">date</code> value.357 (SQLSTATE 42804)358 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-TIMESTAMP-FORMAT"><span class="term">-210 (<code class="symbol">ECPG_TIMESTAMP_FORMAT</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-TIMESTAMP-FORMAT" class="id_link">#</a></dt><dd><p>359 The host variable is of type <code class="type">timestamp</code> and the360 datum in the database is of another type and contains a value361 that cannot be interpreted as a <code class="type">timestamp</code> value.362 (SQLSTATE 42804)363 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-CONVERT-BOOL"><span class="term">-211 (<code class="symbol">ECPG_CONVERT_BOOL</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-CONVERT-BOOL" class="id_link">#</a></dt><dd><p>364 This means the host variable is of type <code class="type">bool</code> and365 the datum in the database is neither <code class="literal">'t'</code> nor366 <code class="literal">'f'</code>. (SQLSTATE 42804)367 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-EMPTY"><span class="term">-212 (<code class="symbol">ECPG_EMPTY</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-EMPTY" class="id_link">#</a></dt><dd><p>368 The statement sent to the <span class="productname">PostgreSQL</span>369 server was empty. (This cannot normally happen in an embedded370 SQL program, so it might point to an internal error.) (SQLSTATE371 YE002)372 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-MISSING-INDICATOR"><span class="term">-213 (<code class="symbol">ECPG_MISSING_INDICATOR</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-MISSING-INDICATOR" class="id_link">#</a></dt><dd><p>373 A null value was returned and no null indicator variable was374 supplied. (SQLSTATE 22002)375 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-NO-ARRAY"><span class="term">-214 (<code class="symbol">ECPG_NO_ARRAY</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-NO-ARRAY" class="id_link">#</a></dt><dd><p>376 An ordinary variable was used in a place that requires an377 array. (SQLSTATE 42804)378 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-DATA-NOT-ARRAY"><span class="term">-215 (<code class="symbol">ECPG_DATA_NOT_ARRAY</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-DATA-NOT-ARRAY" class="id_link">#</a></dt><dd><p>379 The database returned an ordinary variable in a place that380 requires array value. (SQLSTATE 42804)381 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-ARRAY-INSERT"><span class="term">-216 (<code class="symbol">ECPG_ARRAY_INSERT</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-ARRAY-INSERT" class="id_link">#</a></dt><dd><p>382 The value could not be inserted into the array. (SQLSTATE383 42804)384 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-NO-CONN"><span class="term">-220 (<code class="symbol">ECPG_NO_CONN</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-NO-CONN" class="id_link">#</a></dt><dd><p>385 The program tried to access a connection that does not exist.386 (SQLSTATE 08003)387 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-NOT-CONN"><span class="term">-221 (<code class="symbol">ECPG_NOT_CONN</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-NOT-CONN" class="id_link">#</a></dt><dd><p>388 The program tried to access a connection that does exist but is389 not open. (This is an internal error.) (SQLSTATE YE002)390 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-INVALID-STMT"><span class="term">-230 (<code class="symbol">ECPG_INVALID_STMT</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-INVALID-STMT" class="id_link">#</a></dt><dd><p>391 The statement you are trying to use has not been prepared.392 (SQLSTATE 26000)393 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-INFORMIX-DUPLICATE-KEY"><span class="term">-239 (<code class="symbol">ECPG_INFORMIX_DUPLICATE_KEY</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-INFORMIX-DUPLICATE-KEY" class="id_link">#</a></dt><dd><p>394 Duplicate key error, violation of unique constraint (Informix395 compatibility mode). (SQLSTATE 23505)396 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-UNKNOWN-DESCRIPTOR"><span class="term">-240 (<code class="symbol">ECPG_UNKNOWN_DESCRIPTOR</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-UNKNOWN-DESCRIPTOR" class="id_link">#</a></dt><dd><p>397 The descriptor specified was not found. The statement you are398 trying to use has not been prepared. (SQLSTATE 33000)399 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-INVALID-DESCRIPTOR-INDEX"><span class="term">-241 (<code class="symbol">ECPG_INVALID_DESCRIPTOR_INDEX</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-INVALID-DESCRIPTOR-INDEX" class="id_link">#</a></dt><dd><p>400 The descriptor index specified was out of range. (SQLSTATE401 07009)402 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-UNKNOWN-DESCRIPTOR-ITEM"><span class="term">-242 (<code class="symbol">ECPG_UNKNOWN_DESCRIPTOR_ITEM</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-UNKNOWN-DESCRIPTOR-ITEM" class="id_link">#</a></dt><dd><p>403 An invalid descriptor item was requested. (This is an internal404 error.) (SQLSTATE YE002)405 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-VAR-NOT-NUMERIC"><span class="term">-243 (<code class="symbol">ECPG_VAR_NOT_NUMERIC</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-VAR-NOT-NUMERIC" class="id_link">#</a></dt><dd><p>406 During the execution of a dynamic statement, the database407 returned a numeric value and the host variable was not numeric.408 (SQLSTATE 07006)409 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-VAR-NOT-CHAR"><span class="term">-244 (<code class="symbol">ECPG_VAR_NOT_CHAR</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-VAR-NOT-CHAR" class="id_link">#</a></dt><dd><p>410 During the execution of a dynamic statement, the database411 returned a non-numeric value and the host variable was numeric.412 (SQLSTATE 07006)413 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-INFORMIX-SUBSELECT-NOT-ONE"><span class="term">-284 (<code class="symbol">ECPG_INFORMIX_SUBSELECT_NOT_ONE</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-INFORMIX-SUBSELECT-NOT-ONE" class="id_link">#</a></dt><dd><p>414 A result of the subquery is not single row (Informix415 compatibility mode). (SQLSTATE 21000)416 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-PGSQL"><span class="term">-400 (<code class="symbol">ECPG_PGSQL</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-PGSQL" class="id_link">#</a></dt><dd><p>417 Some error caused by the <span class="productname">PostgreSQL</span>418 server. The message contains the error message from the419 <span class="productname">PostgreSQL</span> server.420 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-TRANS"><span class="term">-401 (<code class="symbol">ECPG_TRANS</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-TRANS" class="id_link">#</a></dt><dd><p>421 The <span class="productname">PostgreSQL</span> server signaled that422 we cannot start, commit, or rollback the transaction.423 (SQLSTATE 08007)424 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-CONNECT"><span class="term">-402 (<code class="symbol">ECPG_CONNECT</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-CONNECT" class="id_link">#</a></dt><dd><p>425 The connection attempt to the database did not succeed.426 (SQLSTATE 08001)427 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-DUPLICATE-KEY"><span class="term">-403 (<code class="symbol">ECPG_DUPLICATE_KEY</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-DUPLICATE-KEY" class="id_link">#</a></dt><dd><p>428 Duplicate key error, violation of unique constraint. (SQLSTATE429 23505)430 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-SUBSELECT-NOT-ONE"><span class="term">-404 (<code class="symbol">ECPG_SUBSELECT_NOT_ONE</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-SUBSELECT-NOT-ONE" class="id_link">#</a></dt><dd><p>431 A result for the subquery is not single row. (SQLSTATE 21000)432 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-WARNING-UNKNOWN-PORTAL"><span class="term">-602 (<code class="symbol">ECPG_WARNING_UNKNOWN_PORTAL</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-WARNING-UNKNOWN-PORTAL" class="id_link">#</a></dt><dd><p>433 An invalid cursor name was specified. (SQLSTATE 34000)434 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-WARNING-IN-TRANSACTION"><span class="term">-603 (<code class="symbol">ECPG_WARNING_IN_TRANSACTION</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-WARNING-IN-TRANSACTION" class="id_link">#</a></dt><dd><p>435 Transaction is in progress. (SQLSTATE 25001)436 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-WARNING-NO-TRANSACTION"><span class="term">-604 (<code class="symbol">ECPG_WARNING_NO_TRANSACTION</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-WARNING-NO-TRANSACTION" class="id_link">#</a></dt><dd><p>437 There is no active (in-progress) transaction. (SQLSTATE 25P01)438 </p></dd><dt id="ECPG-SQLSTATE-SQLCODE-ECPG-WARNING-PORTAL-EXISTS"><span class="term">-605 (<code class="symbol">ECPG_WARNING_PORTAL_EXISTS</code>)</span> <a href="#ECPG-SQLSTATE-SQLCODE-ECPG-WARNING-PORTAL-EXISTS" class="id_link">#</a></dt><dd><p>439 An existing cursor name was specified. (SQLSTATE 42P03)440 </p></dd></dl></div><p>441 </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ecpg-descriptors.html" title="36.7. Using Descriptor Areas">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ecpg.html" title="Chapter 36. ECPG — Embedded SQL in C">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ecpg-preproc.html" title="36.9. Preprocessor Directives">Next</a></td></tr><tr><td width="40%" align="left" valign="top">36.7. Using Descriptor Areas </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 36.9. Preprocessor Directives</td></tr></table></div></body></html>