📄 otl3_faq.htm
字号:
<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<meta name="Author" content="Sergei Kuchin">
<meta name="GENERATOR"
content="Mozilla/4.77 [en] (Win95; U) [Netscape]">
<meta name="KeyWords"
content="OTL, Oracle, ODBC, DB2, CLI, database API, C++, Template Library">
<title>Oracle, Odbc and DB2-CLI Template Library, Version 4.0,
Frequently Asked Questions</title>
</head>
<body>
<ul>
<center>
<h1>Oracle, Odbc and DB2-CLI Template Library, Version 4.0</h1>
</center>
<center>
<h1>Frequently Asked Questions</h1>
</center>
</ul>
Please, send your questions and comments to <a
href="mailto:skuchin@aceweb.com">skuchin@aceweb.com</a>,
<a href="mailto:skuchin@gmail.com">skuchin@gmail.com</a><br>
<i><font size="+1"><br>
</font></i><i><font size="+1">Q. OTL: how does OTL handle NULLs?</font></i>
<ul>
<li>Call otl_stream::<a href="otl3_stream_class.htm#is_null">is_null</a>()
to check whether the value that was just read from the stream is NULL
or
not.<br>
</li>
<br>
<li>Use template class <a href="otl3_value.htm">otl_value</a><T>.<br>
<br>
</li>
<li>If there is a need to set the output variable to a value when
NULL is fetched (by default, OTL does not set the output byffer to any
value in the case of NULL), the following #defines could be enabled:<br>
<br>
</li>
<ul>
<li> <a href="otl3_compile.htm#OTL_DEFAULT_NUMERIC_NULL_TO_VAL">OTL_DEFAULT_NUMERIC_NULL_TO_VAL</a></li>
<li> <a href="otl3_compile.htm#OTL_DEFAULT_DATETIME_NULL_TO_VAL">OTL_DEFAULT_DATETIME_NULL_TO_VAL</a></li>
<li> <a href="otl3_compile.htm#OTL_DEFAULT_STRING_NULL_TO_VAL">OTL_DEFAULT_STRING_NULL_TO_VAL</a></li>
<li> <a href="otl3_compile.htm#OTL_DEFAULT_CHAR_NULL_TO_VAL">OTL_DEFAULT_CHAR_NULL_TO_VAL</a></li>
<li><a
href="otl3_compile.htm#OTL_USER_DEFINED_STRING_CLASS_DEFAULT_NULL_TO_VAL">OTL_USER_DEFINED_STRING_CLASS_DEFAULT_NULL_TO_VAL</a></li>
</ul>
</ul>
<br>
<i><font size="+1"><a name="Large_Nvarchar_MSSQL"></a>Q. OTL: How to
insert or update MS SQL NVARCHAR</font></i><span
style="font-style: italic;"> / NCHAR
values larger than 2000 characters?</span><br>
<br>
All versions of MS SQL ODBC / Native Client (including MS SQL 2008)
have a limitaion on how large an OTL <span
style="font-family: monospace;">:v<char[XXX]></span> can be when
#define OTL_UNICODE is enabled and the bind variable is bound with an
NVARCHAR / NCHAR table column: 2000 UTF-16 characters. If, say,
:v<char[2002]> is used, MS SQL 2005 issues the following error
message:<br>
<br>
[Microsoft][SQL Native Client]Invalid precision value<br>
<br>
MS SQL 2008's error message in a similar situation is more descriptive:<br>
<br>
[Microsoft][SQL Server Native Client 10.0][SQL Server]The size (XXX)
given to the parameter '@PN' exceeds the maximum allowed (4000).<br>
<br>
I couldn't find any good references to these error messages in the MSDN
Web site, so if anybody finds the right Web page, please, let me know,
and I'll add the URL to this answer.<br>
<br>
If there is a need to insert / update NVACHAR / NCHAR large (>2000
characters) table columns, <span style="font-family: monospace;">:v<varchar_long></span>
can be used instead of <span style="font-family: monospace;">:v<char[XXX]></span>.
otl_long_unicode_string can be used with :v<varchar_long>, for
example:<br>
<br>
<span style="font-family: monospace;">...</span><br>
<span style="font-family: monospace;">create table test_tab(f1 int, f2
nvarchar(4000));<br>
...<br>
</span><span style="font-family: monospace;"> db.set_max_long_size(4000);
// set the maximum varchar long to 4000 characters</span><br
style="font-family: monospace;">
<span style="font-family: monospace;"> otl_stream o(3, // buffer
size should can be > 1</span><br style="font-family: monospace;">
<span style="font-family: monospace;">
"insert into test_tab values(:f1<int>,:f2<varchar_long>)",</span><br
style="font-family: monospace;">
<span style="font-family: monospace;">
db // connect object</span><br style="font-family: monospace;">
<span style="font-family: monospace;">
);</span><br style="font-family: monospace;">
<br style="font-family: monospace;">
<span style="font-family: monospace;"> otl_long_unicode_string
f2(4000);</span><br style="font-family: monospace;">
<span style="font-family: monospace;"> for(int i=1;i<=5;++i){</span><br
style="font-family: monospace;">
<span style="font-family: monospace;"> o<<i;</span><br
style="font-family: monospace;">
<span style="font-family: monospace;"> for(int j=0;j<4000;++j)</span><br
style="font-family: monospace;">
<span style="font-family: monospace;"> f2[j]=...;</span><br
style="font-family: monospace;">
<span style="font-family: monospace;"> f2.set_len(4000);</span><br
style="font-family: monospace;">
<span style="font-family: monospace;"> o<<f2;</span><br
style="font-family: monospace;">
<span style="font-family: monospace;"> }</span><br
style="font-family: monospace;">
<br>
Besides otl_long_unicode_string, <span style="font-family: monospace;">std::wstring</span>
can be used with varchar_long, similar to example <a
href="otl4_ex368.htm">368</a>.<br>
<br>
<i><font size="+1"><a name="Nested_Quesry"></a>Q. OTL: why nested
queries with bind variables do
not work in MS SQL Server?</font></i>
<br>
<br>
Try to add otl_implicit_select right after the otl_connect parameter,
when you are opening the nested SELECT:<br>
<pre wrap=""> otl_stream s(1,<br> "select dt from "<br> " (select "<br> " dateadd(day, <span
style="color: rgb(0, 153, 0);">:v<int></span>, getdate() "<br> " )dt ) xt ",<br> db, // connect object<br> <span
style="font-style: italic;">otl_implicit_select</span><br> );<br><br></pre>
Problem is that SQLPrepare() doesn't return any SELECT output column
descriptors (OTL exception: Column: 0<UNKNOWN>), and it looks
like the nested SELECT gets converted into a temporary stored
procedure, which means you have to specify that it is a stored proc
that returns an implicit result set. I don't know why the database
server does it, probably as an optimization technique.<br>
<br>
<i><font size="+1"><a name="NO_DSN"></a>Q. OTL: How do I connect to my
database without
creating an ODBC DSN?</font></i>
<br>
<br>
Take a look this <a href="http://www.connectionstrings.com/">Web site</a>.<br>
<br>
<i><font size="+1">Q. OTL: is it thread safe?</font></i>
<p></p>
<p>OTL does not set any mutex locks or critical sections. In case if
each
thread has its own otl_connect object, there is no need for mutex
locks.
In case of sharable connections, it is the devloper's responsibility to
wrap up OTL calls with mutexes. In general, database APIs do not
guarantee
thread safety. otl_connect::<a
href="otl3_connect_class.htm#otl_initialize">otl_initialize</a>
passes a flag to the underlying database API only to let the API know
that
the progam is running in a multi-threaded mode.
</p>
<p><i><font size="+1">Q. OTL: does it work with SQLite?</font></i>
</p>
<p>Yes, it does. OTL/ODBC works with SQLite. See the following <a
href="otl4_sqlite_examples.htm">examples</a> for detail.<br>
</p>
<p><i><font size="+1">Q. OTL: does it support Oracle 10g?</font></i>
</p>
<p>The answer is Yes. Use #define
<a href="otl3_compile.htm#OTL_ORA10G">OTL_ORA10G</a>, <a
href="otl3_compile.htm#OTL_ORA10G_R2">OTL_ORA10G</a><a
href="otl3_compile.htm#OTL_ORA10G_R2">_R2</a> </p>
<p>
</p>
<p><i><font size="+1">Q. OTL: does it work with SAP DB?</font></i>
</p>
<p>Yes, it does. OTL/ODBC works with SAP DB. Fore more detail, see OTL <a
href="otl4_sap_db_examples.htm">examples</a> for SAP DB.
</p>
<p><i><font size="+1">Q. OTL: does it support CLOBs/BLOBs in PL/SQL?</font></i>
</p>
<p>The answer is: it depends. You need to keep in mind that "CLOB/BLOB"
as a PL/SQL datatype is a <i>locator</i> of a large object, not a
value.
That is, the object itself needs to be created first, its locator needs
to be retrieved from the database into C++, and only then the locator
can
be passed into PL/SQL. Also, see code example <a href="otl4_ex378.htm">378</a>.<br>
</p>
<p><i><font size="+1">Q. OTL: does it support Unicode?</font></i>
</p>
<p>The answer is Yes. See OTL examples and the manual. <br>
</p>
<p><i><font size="+1">Q. OTL: does it support Oracle 9i?</font></i>
</p>
<p>The answer is Yes. Starting with version 4.0.0, OTL introduces
#define
<a href="otl3_compile.htm#OTLORA9I">OTL_ORA9I</a>
that is dedicated to Oracle 9i. In OTL 4.0.0 itself, it's not much more
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -