odbc.html
来自「perl教程」· HTML 代码 · 共 822 行 · 第 1/2 页
HTML
822 行
<?xml version="1.0" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0017)http://localhost/ -->
<script language="JavaScript" src="../../displayToc.js"></script>
<script language="JavaScript" src="../../tocParas.js"></script>
<script language="JavaScript" src="../../tocTab.js"></script>
<link rel="stylesheet" type="text/css" href="../../scineplex.css">
<title>Win32::ODBC - ODBC Extension for Win32</title>
<link rel="stylesheet" href="../../Active.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>
<body>
<script>writelinks('__top__',2);</script>
<h1><a>Win32::ODBC - ODBC Extension for Win32</a></h1>
<p><a name="__index__"></a></p>
<!-- INDEX BEGIN -->
<ul>
<li><a href="#name">NAME</a></li>
<li><a href="#synopsis">SYNOPSIS</a></li>
<li><a href="#description">DESCRIPTION</a></li>
<ul>
<li><a href="#background">Background</a></li>
<li><a href="#benefits">Benefits</a></li>
</ul>
<li><a href="#constants">CONSTANTS</a></li>
<li><a href="#special_notation">SPECIAL NOTATION</a></li>
<li><a href="#constructor">CONSTRUCTOR</a></li>
<li><a href="#methods">METHODS</a></li>
<li><a href="#limitations">LIMITATIONS</a></li>
<li><a href="#installation_notes">INSTALLATION NOTES</a></li>
<li><a href="#other_documentation">OTHER DOCUMENTATION</a></li>
<li><a href="#author">AUTHOR</a></li>
<li><a href="#credits">CREDITS</a></li>
<li><a href="#disclaimer">DISCLAIMER</a></li>
<li><a href="#history">HISTORY</a></li>
<li><a href="#copyright">COPYRIGHT</a></li>
</ul>
<!-- INDEX END -->
<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>Win32::ODBC - ODBC Extension for Win32</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<p>To use this module, include the following statement at the top of your
script:</p>
<pre>
<span class="keyword">use</span> <span class="variable">Win32::ODBC</span><span class="operator">;</span>
</pre>
<p>Next, create a data connection to your DSN:</p>
<pre>
<span class="variable">$Data</span> <span class="operator">=</span> <span class="variable">new</span> <span class="variable">Win32::ODBC</span><span class="operator">(</span><span class="string">"MyDSN"</span><span class="operator">);</span>
</pre>
<p><strong>NOTE</strong>: <em>MyDSN</em> can be either the <em>DSN</em> as defined in the ODBC
Administrator, <em>or</em> it can be an honest-to-God <em>DSN Connect String</em>.</p>
<pre>
<span class="variable">Example</span><span class="operator">:</span> <span class="string">"DSN=My Database;UID=Brown Cow;PWD=Moo;"</span>
</pre>
<p>You should check to see if <code>$Data</code> is indeed defined, otherwise there
has been an error.</p>
<p>You can now send SQL queries and retrieve info to your heart's
content! See the description of the methods provided by this module
below and also the file <em>TEST.PL</em> as referred to in <a href="#installation_notes">INSTALLATION NOTES</a> to see how it all works.</p>
<p>Finally, <strong>MAKE SURE</strong> that you close your connection when you are
finished:</p>
<pre>
<span class="variable">$Data</span><span class="operator">-></span><span class="variable">Close</span><span class="operator">();</span>
</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>
</p>
<h2><a name="background">Background</a></h2>
<p>This is a hack of Dan DeMaggio's <<a href="mailto:dmag@umich.edu">dmag@umich.edu</a>> <em>NTXS.C</em> ODBC
implementation. I have recoded and restructured most of it including
most of the <em>ODBC.PM</em> package, but its very core is still based on
Dan's code (thanks Dan!).</p>
<p>The history of this extension is found in the file <em>HISTORY.TXT</em> that
comes with the original archive (see <a href="#installation_notes">INSTALLATION NOTES</a> below).</p>
<p>
</p>
<h2><a name="benefits">Benefits</a></h2>
<p>And what are the benefits of this module?</p>
<ul>
<li>
<p>The number of ODBC connections is limited by memory and ODBC itself
(have as many as you want!).</p>
</li>
<li>
<p>The working limit for the size of a field is 10,240 bytes, but you can
increase that limit (if needed) to a max of 2,147,483,647 bytes. (You
can always recompile to increase the max limit.)</p>
</li>
<li>
<p>You can open a connection by either specifing a DSN or a connection
string!</p>
</li>
<li>
<p>You can open and close the connections in any order!</p>
</li>
<li>
<p>Other things that I can not think of right now... :)</p>
</li>
</ul>
<p>
</p>
<hr />
<h1><a name="constants">CONSTANTS</a></h1>
<p>This package defines a number of constants. You may refer to each of
these constants using the notation <code>ODBC::xxxxx</code>, where <code>xxxxx</code> is
the constant.</p>
<p>Example:</p>
<pre>
<span class="keyword">print</span> <span class="variable">ODBC::SQL_SQL_COLUMN_NAME</span><span class="operator">,</span> <span class="string">"\n"</span><span class="operator">;</span>
</pre>
<p>
</p>
<hr />
<h1><a name="special_notation">SPECIAL NOTATION</a></h1>
<p>For the method documentation that follows, an <strong>*</strong> following the
method parameters indicates that that method is new or has been
modified for this version.</p>
<p>
</p>
<hr />
<h1><a name="constructor">CONSTRUCTOR</a></h1>
<dl>
<dt><strong><a name="item_new">new ( ODBC_OBJECT | DSN [, (OPTION1, VALUE1), (OPTION2, VALUE2) ...] )
*</a></strong>
<dd>
<p>Creates a new ODBC connection based on <code>DSN</code>, or, if you specify an
already existing ODBC object, then a new ODBC object will be created
but using the ODBC Connection specified by <code>ODBC_OBJECT</code>. (The new
object will be a new <em>hstmt</em> using the <em>hdbc</em> connection in
<code>ODBC_OBJECT</code>.)</p>
</dd>
<dd>
<p><code>DSN</code> is <em>Data Source Name</em> or a proper <code>ODBCDriverConnect</code> string.</p>
</dd>
<dd>
<p>You can specify SQL Connect Options that are implemented before the
actual connection to the DSN takes place. These option/values are the
same as specified in <a href="#item_getconnectoption"><code>GetConnectOption</code></a>/<a href="#item_setconnectoption"><code>SetConnectOption</code></a> (see
below) and are defined in the ODBC API specs.</p>
</dd>
<dd>
<p>Returns a handle to the database on success, or <em>undef</em> on failure.</p>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="methods">METHODS</a></h1>
<dl>
<dt><strong><a name="item_catalog">Catalog ( QUALIFIER, OWNER, NAME, TYPE )</a></strong>
<dd>
<p>Tells ODBC to create a data set that contains table information about
the DSN. Use <code>Fetch</code> and <a href="#item_data"><code>Data</code></a> or <a href="#item_datahash"><code>DataHash</code></a> to retrieve the data.
The returned format is:</p>
</dd>
<dd>
<pre>
[Qualifier] [Owner] [Name] [Type]</pre>
</dd>
<dd>
<p>Returns <em>true</em> on error.</p>
</dd>
</li>
<dt><strong><a name="item_colattributes">ColAttributes ( ATTRIBUTE [, FIELD_NAMES ] )</a></strong>
<dd>
<p>Returns the attribute <code>ATTRIBUTE</code> on each of the fields in the list
<code>FIELD_NAMES</code> in the current record set. If <code>FIELD_NAMES</code> is empty,
then all fields are assumed. The attributes are returned as an
associative array.</p>
</dd>
</li>
<dt><strong><a name="item_configdsn">ConfigDSN ( OPTION, DRIVER, ATTRIBUTE1 [, ATTRIBUTE2, ATTRIBUTE3, ...
] )</a></strong>
<dd>
<p>Configures a DSN. <code>OPTION</code> takes on one of the following values:</p>
</dd>
<dd>
<pre>
ODBC_ADD_DSN.......Adds a new DSN.
ODBC_MODIFY_DSN....Modifies an existing DSN.
ODBC_REMOVE_DSN....Removes an existing DSN.</pre>
</dd>
<dd>
<pre>
ODBC_ADD_SYS_DSN.......Adds a new System DSN.
ODBC_MODIFY_SYS_DSN....Modifies an existing System DSN.
ODBC_REMOVE_SYS_DSN....Removes an existing System DSN.</pre>
</dd>
<dd>
<p>You must specify the driver <code>DRIVER</code> (which can be retrieved by using
<a href="#item_datasources"><code>DataSources</code></a> or <a href="#item_drivers"><code>Drivers</code></a>).</p>
</dd>
<dd>
<p><code>ATTRIBUTE1</code> <strong>should</strong> be <em>"DSN=xxx"</em> where <em>xxx</em> is the name of
the DSN. Other attributes can be any DSN attribute such as:</p>
</dd>
<dd>
<pre>
"UID=Cow"
"PWD=Moo"
"Description=My little bitty Data Source Name"</pre>
</dd>
<dd>
<p>Returns <em>true</em> on success, <em>false</em> on failure.</p>
</dd>
<dd>
<p><strong>NOTE 1</strong>: If you use <code>ODBC_ADD_DSN</code>, then you must include at least
<em>"DSN=xxx"</em> and the location of the database.</p>
</dd>
<dd>
<p>Example: For MS Access databases, you must specify the
<em>DatabaseQualifier</em>:</p>
</dd>
<dd>
<pre>
"DBQ=c:\\...\\MyDatabase.mdb"</pre>
</dd>
<dd>
<p><strong>NOTE 2</strong>: If you use <code>ODBC_MODIFY_DSN</code>, then you need only specify
the <em>"DNS=xxx"</em> attribute. Any other attribute you include will be
changed to what you specify.</p>
</dd>
<dd>
<p><strong>NOTE 3</strong>: If you use <code>ODBC_REMOVE_DSN</code>, then you need only specify
the <em>"DSN=xxx"</em> attribute.</p>
</dd>
</li>
<dt><strong><a name="item_connection">Connection ()</a></strong>
<dd>
<p>Returns the connection number associated with the ODBC connection.</p>
</dd>
</li>
<dt><strong><a name="item_close">Close ()</a></strong>
<dd>
<p>Closes the ODBC connection. No return value.</p>
</dd>
</li>
<dt><strong><a name="item_data">Data ( [ FIELD_NAME ] )</a></strong>
<dd>
<p>Returns the contents of column name <code>FIELD_NAME</code> or the current row
(if nothing is specified).</p>
</dd>
</li>
<dt><strong><a name="item_datahash">DataHash ( [ FIELD1, FIELD2, ... ] )</a></strong>
<dd>
<p>Returns the contents for <code>FIELD1, FIELD2, ...</code> or the entire row (if
nothing is specified) as an associative array consisting of:</p>
</dd>
<dd>
<pre>
<span class="operator">{</span><span class="variable">Field</span> <span class="variable">Name</span><span class="operator">}</span> <span class="operator">=></span> <span class="variable">Field</span> <span class="variable">Data</span>
</pre>
</dd>
</li>
<dt><strong><a name="item_datasources">DataSources ()</a></strong>
<dd>
<p>Returns an associative array of Data Sources and ODBC remarks about them.
They are returned in the form of:</p>
</dd>
<dd>
<pre>
<span class="variable">$ArrayName</span><span class="operator">{</span><span class="string">'DSN'</span><span class="operator">}</span><span class="operator">=</span><span class="variable">Driver</span>
</pre>
</dd>
<dd>
<p>where <em>DSN</em> is the Data Source Name and ODBC Driver used.</p>
</dd>
</li>
<dt><strong><a name="item_debug">Debug ( [ 1 | 0 ] )</a></strong>
<dd>
<p>Sets the debug option to on or off. If nothing is specified, then
nothing is changed.</p>
</dd>
<dd>
<p>Returns the debugging value (<em>1</em> or <em>0</em>).</p>
</dd>
</li>
<dt><strong><a name="item_drivers">Drivers ()</a></strong>
<dd>
<p>Returns an associative array of ODBC Drivers and their attributes.
They are returned in the form of:</p>
</dd>
<dd>
<pre>
<span class="variable">$ArrayName</span><span class="operator">{</span><span class="string">'DRIVER'</span><span class="operator">}</span><span class="operator">=</span><span class="variable">Attrib1</span><span class="operator">;</span><span class="variable">Attrib2</span><span class="operator">;</span><span class="variable">Attrib3</span><span class="operator">;...</span>
</pre>
</dd>
<dd>
<p>where <em>DRIVER</em> is the ODBC Driver Name and <em>AttribX</em> are the
driver-defined attributes.</p>
</dd>
</li>
<dt><strong><a name="item_dropcursor">DropCursor ( [ CLOSE_TYPE ] )</a></strong>
<dd>
<p>Drops the cursor associated with the ODBC object. This forces the
cursor to be deallocated. This overrides <a href="#item_setstmtclosetype"><code>SetStmtCloseType</code></a>, but the
ODBC object does not lose the <code>StmtCloseType</code> setting. <code>CLOSE_TYPE</code>
can be any valid <code>SmtpCloseType</code> and will perform a close on the stmt
using the specified close type.</p>
</dd>
<dd>
<p>Returns <em>true</em> on success, <em>false</em> on failure.</p>
</dd>
</li>
<dt><strong><a name="item_dumpdata">DumpData ()</a></strong>
<dd>
<p>Dumps to the screen the fieldnames and all records of the current data
set. Used primarily for debugging. No return value.</p>
</dd>
</li>
<dt><strong><a name="item_error">Error ()</a></strong>
<dd>
<p>Returns the last encountered error. The returned value is context
dependent:</p>
</dd>
<dd>
<p>If called in a <em>scalar</em> context, then a <em>3-element array</em> is
returned:</p>
</dd>
<dd>
<pre>
( ERROR_NUMBER, ERROR_TEXT, CONNECTION_NUMBER )</pre>
</dd>
<dd>
<p>If called in a <em>string</em> context, then a <em>string</em> is returned:</p>
</dd>
<dd>
<pre>
"[ERROR_NUMBER] [CONNECTION_NUMBER] [ERROR_TEXT]"</pre>
</dd>
<dd>
<p>If debugging is on then two more variables are returned:</p>
</dd>
<dd>
<pre>
( ..., FUNCTION, LEVEL )</pre>
</dd>
<dd>
<p>where <code>FUNCTION</code> is the name of the function in which the error
occurred, and <code>LEVEL</code> represents extra information about the error
(usually the location of the error).</p>
</dd>
</li>
<dt><strong><a name="item_fetchrow">FetchRow ( [ ROW [, TYPE ] ] )</a></strong>
<dd>
<p>Retrieves the next record from the keyset. When <code>ROW</code> and/or <code>TYPE</code>
are specified, the call is made using <code>SQLExtendedFetch</code> instead of
<code>SQLFetch</code>.</p>
</dd>
<dd>
<p><strong>NOTE 1</strong>: If you are unaware of <code>SQLExtendedFetch</code> and its
implications, stay with just regular <a href="#item_fetchrow"><code>FetchRow</code></a> with no parameters.</p>
</dd>
<dd>
<p><strong>NOTE 2</strong>: The ODBC API explicitly warns against mixing calls to
<code>SQLFetch</code> and <code>SQLExtendedFetch</code>; use one or the other but not
both.</p>
</dd>
<dd>
<p>If <em>ROW</em> is specified, it moves the keyset <strong>RELATIVE</strong> <code>ROW</code> number
of rows.</p>
</dd>
<dd>
<p>If <em>ROW</em> is specified and <code>TYPE</code> is <strong>not</strong>, then the type used is
<strong>RELATIVE</strong>.</p>
</dd>
<dd>
<p>Returns <em>true</em> when another record is available to read, and <em>false</em>
when there are no more records.</p>
</dd>
</li>
<dt><strong><a name="item_fieldnames">FieldNames ()</a></strong>
<dd>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?