ibm-information-center/dist/eclipse/plugins/i5OS.ic.cli_5.4.0.1/rzadpfnnsql.htm

197 lines
12 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="reference" />
<meta name="DC.Title" content="SQLNativeSql - Get native SQL text" />
<meta name="DC.Relation" scheme="URI" content="rzadphdapi.htm" />
<meta name="copyright" content="(C) Copyright IBM Corporation 1999, 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1999, 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="rzadpfnnsql" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>SQLNativeSql</title>
</head>
<body id="rzadpfnnsql"><a name="rzadpfnnsql"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">SQLNativeSql - Get native SQL text</h1>
<div><div class="section"><h4 class="sectiontitle">Purpose</h4> <p><samp class="codeph">SQLNativeSql()</samp> is
used to show how DB2<sup>®</sup> UDB CLI interprets vendor escape clauses. If the
original SQL string passed in by the application contains vendor escape clause
sequences, then DB2 UDB
CLI returns the transformed SQL string that is seen by the data source (with
vendor escape clauses either converted or discarded, as appropriate).</p>
</div>
<div class="section"><h4 class="sectiontitle">Syntax</h4><pre>SQLRETURN SQLNativeSql (SQLHDBC ConnectionHandle,
SQLCHAR *InStatementText,
SQLINTEGER TextLength1,
SQLCHAR *OutStatementText,
SQLINTEGER BufferLength,
SQLINTEGER *TextLength2Ptr);</pre>
</div>
<div class="section"><h4 class="sectiontitle">Function arguments</h4>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" width="100%" frame="hsides" border="1" rules="all"><caption>Table 1. SQLNativeSql arguments</caption><thead align="left"><tr><th align="left" valign="bottom" width="22.94776119402985%" id="d0e53">Data type</th>
<th align="left" valign="bottom" width="21.828358208955223%" id="d0e55">Argument </th>
<th align="left" valign="bottom" width="13.432835820895523%" id="d0e57">Use </th>
<th align="left" valign="bottom" width="41.7910447761194%" id="d0e59">Description </th>
</tr>
</thead>
<tbody><tr><td align="left" valign="top" width="22.94776119402985%" headers="d0e53 ">SQLCHAR *</td>
<td align="left" valign="top" width="21.828358208955223%" headers="d0e55 "><em>InStatementText </em></td>
<td align="left" valign="top" width="13.432835820895523%" headers="d0e57 ">Input </td>
<td align="left" valign="top" width="41.7910447761194%" headers="d0e59 ">Input SQL string.</td>
</tr>
<tr><td align="left" valign="top" width="22.94776119402985%" headers="d0e53 ">SQLCHAR *</td>
<td align="left" valign="top" width="21.828358208955223%" headers="d0e55 "><em>OutStatementText</em></td>
<td align="left" valign="top" width="13.432835820895523%" headers="d0e57 ">Output </td>
<td align="left" valign="top" width="41.7910447761194%" headers="d0e59 ">Pointer to buffer for the transformed output
string.</td>
</tr>
<tr><td align="left" valign="top" width="22.94776119402985%" headers="d0e53 ">SQLHDBC </td>
<td align="left" valign="top" width="21.828358208955223%" headers="d0e55 "><em>ConnectionHandle </em></td>
<td align="left" valign="top" width="13.432835820895523%" headers="d0e57 ">Input </td>
<td align="left" valign="top" width="41.7910447761194%" headers="d0e59 ">Connection handle.</td>
</tr>
<tr><td align="left" valign="top" width="22.94776119402985%" headers="d0e53 ">SQLINTEGER *</td>
<td align="left" valign="top" width="21.828358208955223%" headers="d0e55 "><em>TextLength2Ptr</em></td>
<td align="left" valign="top" width="13.432835820895523%" headers="d0e57 ">Output </td>
<td align="left" valign="top" width="41.7910447761194%" headers="d0e59 ">The total number of bytes available to return
in <span class="synph"><span class="var">OutStatementText</span></span>. If the number of bytes available
to return is greater than or equal to <span class="synph"><span class="var">BufferLength</span></span>,
the output SQL string in <span class="synph"><span class="var">OutStatementText</span></span> is truncated
to <span class="synph"><span class="var">BufferLength - 1</span></span> bytes. The value SQL_NULL_DATA
is returned if no output string is generated.</td>
</tr>
<tr><td align="left" valign="top" width="22.94776119402985%" headers="d0e53 ">SQLINTEGER </td>
<td align="left" valign="top" width="21.828358208955223%" headers="d0e55 "><em>BufferLength</em></td>
<td align="left" valign="top" width="13.432835820895523%" headers="d0e57 ">Input </td>
<td align="left" valign="top" width="41.7910447761194%" headers="d0e59 ">Size of buffer pointed by <span class="synph"><span class="var">OutStatementText</span>.</span></td>
</tr>
<tr><td align="left" valign="top" width="22.94776119402985%" headers="d0e53 ">SQLINTEGER</td>
<td align="left" valign="top" width="21.828358208955223%" headers="d0e55 "><em>TextLength1 </em></td>
<td align="left" valign="top" width="13.432835820895523%" headers="d0e57 ">Input </td>
<td align="left" valign="top" width="41.7910447761194%" headers="d0e59 ">Length of <span class="synph"><span class="var">InStatementText</span>.</span></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section"><h4 class="sectiontitle">Usage</h4><p>This function is called when the application
wants to examine or display the transformed SQL string that is passed to the
data source by DB2 UDB
CLI. Translation (mapping) only occurs if the input SQL statement string contains
vendor escape clause sequences.</p>
<p>There are no vendor
escape sequences on iSeries; this procedure is provided for compatibility
purposes. Also, note that this procedure can be used to evaluate an SQL string
for syntax errors.</p>
</div>
<div class="section"><h4 class="sectiontitle">Return codes</h4><div class="p"> <ul><li>SQL_SUCCESS </li>
<li>SQL_SUCCESS_WITH_INFO </li>
<li>SQL_ERROR </li>
<li>SQL_INVALID_HANDLE </li>
</ul>
</div>
</div>
<div class="section"><h4 class="sectiontitle">Error conditions</h4>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" width="100%" frame="hsides" border="1" rules="rows"><caption>Table 2. SQLNativeSql SQLSTATEs</caption><thead align="left"><tr><th align="left" valign="bottom" width="12.962962962962962%" id="d0e186">SQLSTATE </th>
<th align="left" valign="bottom" width="29.074074074074076%" id="d0e188">Description </th>
<th align="left" valign="bottom" width="57.96296296296296%" id="d0e190">Explanation </th>
</tr>
</thead>
<tbody><tr><td align="left" valign="top" width="12.962962962962962%" headers="d0e186 "><strong>01</strong>004 </td>
<td align="left" valign="top" width="29.074074074074076%" headers="d0e188 ">Data truncated</td>
<td align="left" valign="top" width="57.96296296296296%" headers="d0e190 ">The buffer <span class="synph"><span class="var">OutStatementText</span></span> is
not large enough to contain the entire SQL string, so truncation occurred.
The argument <span class="synph"><span class="var">TextLength2Ptr</span></span> contains the total length
of the untruncated SQL string. (Function returns with SQL_SUCCESS_WITH_INFO.)</td>
</tr>
<tr><td align="left" valign="top" width="12.962962962962962%" headers="d0e186 "><strong>08</strong>003 </td>
<td align="left" valign="top" width="29.074074074074076%" headers="d0e188 ">Connection is closed</td>
<td align="left" valign="top" width="57.96296296296296%" headers="d0e190 ">The <span class="synph"><span class="var">ConnectionHandle</span></span> does
not reference an open database connection.</td>
</tr>
<tr><td align="left" valign="top" width="12.962962962962962%" headers="d0e186 "><strong>37</strong>000 </td>
<td align="left" valign="top" width="29.074074074074076%" headers="d0e188 ">SQL syntax that is not valid</td>
<td align="left" valign="top" width="57.96296296296296%" headers="d0e190 ">The input SQL string in <span class="synph"><span class="var">InStatementText</span></span> contained
a syntax error.</td>
</tr>
<tr><td align="left" valign="top" width="12.962962962962962%" headers="d0e186 "><strong>HY</strong>001 </td>
<td align="left" valign="top" width="29.074074074074076%" headers="d0e188 ">Memory allocation failure</td>
<td align="left" valign="top" width="57.96296296296296%" headers="d0e190 ">DB2 UDB CLI is unable to allocate memory
required to support the processing or completion of the function.</td>
</tr>
<tr><td align="left" valign="top" width="12.962962962962962%" headers="d0e186 "><strong>HY</strong>009 </td>
<td align="left" valign="top" width="29.074074074074076%" headers="d0e188 ">Argument value that is not valid</td>
<td align="left" valign="top" width="57.96296296296296%" headers="d0e190 ">The argument <span class="synph"><span class="var">InStatementText</span></span>, <span class="synph"><span class="var">OutStatementText</span></span>,
or <span class="synph"><span class="var">TextLength2Ptr</span></span> is a null pointer.</td>
</tr>
<tr><td align="left" valign="top" width="12.962962962962962%" headers="d0e186 "><strong>HY</strong>090 </td>
<td align="left" valign="top" width="29.074074074074076%" headers="d0e188 ">String or buffer length that is not valid</td>
<td align="left" valign="top" width="57.96296296296296%" headers="d0e190 "> The argument <span class="synph"><span class="var">TextLength1</span></span> is
less than 0, but not equal to SQL_NTS. <p>The argument <span class="synph"><span class="var">BufferLength</span></span> is
less than 0.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section"><h4 class="sectiontitle">Restrictions</h4><p>None.</p>
</div>
<div class="section"><h4 class="sectiontitle">Example</h4></div>
<div class="example" id="rzadpfnnsql__xmnsql"><a name="rzadpfnnsql__xmnsql"><!-- --></a><div class="note"><span class="notetitle">Note:</span> By using the code examples, you
agree to the terms of the <a href="codedisclaimer.htm">Code license and disclaimer information</a>.</div>
<div class="p"> <pre>/* From CLI sample native.c */
/* ... */
SQLCHAR in_stmt[1024], out_stmt[1024] ;
SQLSMALLINT pcPar ;
SQLINTEGER indicator ;
/* ... */
/* Prompt for a statement to prepare */
printf("Enter an SQL statement: \n");
gets((char *)in_stmt);
/* prepare the statement */
rc = SQLPrepare(hstmt, in_stmt, SQL_NTS);
CHECK_HANDLE( SQL_HANDLE_STMT, hstmt, rc ) ;
SQLNumParams(hstmt, &amp;pcPar);
CHECK_HANDLE( SQL_HANDLE_STMT, hstmt, rc ) ;
SQLNativeSql(hstmt, in_stmt, SQL_NTS, out_stmt, 1024, &amp;indicator);
CHECK_HANDLE( SQL_HANDLE_STMT, hstmt, rc ) ;
if ( indicator == SQL_NULL_DATA ) printf( "Invalid statement\n" ) ;
else {
printf( "Input Statement: \n %s \n", in_stmt ) ;
printf( "Output Statement: \n %s \n", in_stmt ) ;
printf( "Number of Parameter Markers = %d\n", pcPar ) ;
}
rc = SQLFreeHandle( SQL_HANDLE_STMT, hstmt ) ;
CHECK_HANDLE( SQL_HANDLE_STMT, hstmt, rc ) ;
</pre>
</div>
</div>
<div class="section"><h4 class="sectiontitle">References</h4><p>None. </p>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzadphdapi.htm" title="This topic provides a description of each CLI function.">DB2 UDB CLI functions</a></div>
</div>
</div>
</body>
</html>