Win32::ODBC Object Document

原创 2002年01月05日 18:21:00

Win32::ODBC - Object
 
-----------------------------------------------------------------------------
---
 
Creating an ODBC Object
Your script will need to have the following line:
 
    use Win32::ODBC;
Then you will need to create a data connection to your DSN:
 
    $Data = new Win32::ODBC("MyDSN");
You shoud check to see if $Data is indeed defined otherwise there has been
an error. You can now send SQL queries and retrieve info to your heart's
content! See the description of functions below and also test.pl to see how
it all works.
 
Make sure that you close your connection when you are finished:
 
    $Data->Close();
 
 
-----------------------------------------------------------------------------
---
 
 Back to the top
 
Object Methods
General Note
All methods assume that you have the line:
    use Win32::ODBC;
somewhere before the method calls, and that you have an ODBC object called
$db which was created using some call similar to:
    $db = new Win32::ODBC("MyDSN");
See new for more information.
Also, in an effort to keep the examples short, no error checking is done on
return values for any calls other than the one being exemplified. You
should always check for error conditions in production code.
 
WARNING: The example code has not yet been tested. This will be fixed ASAP,
but be forwarned!
 
Methods
 Back to the top
 
Catalog
qualifier, owner, name, type
Retrieves the catalog from the current ODBC object. Returns a four-element
array (Qualifier, Owner, Name, Type). Note:All fieldnames are uppercase!
Example:
($qualifier, $owner, $name, $type) = $db->Catalog("", "", "%", "'TABLE'");
 
 Back to the top
 
Connection
Returns the object's ODBC connection number.
Example:
$cnum = $db->Connection;
 
 Back to the top
 
Close
Closes the ODBC connection for this object. It always returns undef.
Example:
$db->Close();
 
 Back to the top
 
Data
Data list
Retrieve data from previous fetch for a list of field names. In a scalar
context it returns all of the field values concatenated together. In an
array context, it returns an array of the values, in the order in which
they were specified. If no field names are given, all fields are returned
in an unspecified order.
Example:
$db->Sql("SELECT f1, f2, f3 FROM foo");
$db->FetchRow();
($f1, $f2) = $db->Data("f1", "f2");
 
or
 
$db->Sql("SELECT * FROM foo");
$db->FetchRow();
@values = $db->Data;
See also: DataHash
 
 Back to the top
 
DataHash
DataHash list
Retrieve data from previous fetch for a list of field names. Returns a hash
where the field name is the key. If no field names are given, all fields
are returned.
Example:
$db->Sql("SELECT f1, f2, f3 FROM foo");
$db->FetchRow();
%hash = $db->DataHash("f1", "f2");
print $hash{f1};
 
or
 
$db->Sql("SELECT * FROM foo");
$db->FetchRow();
%hash = $db->DataHash;
foreach $key (sort(keys %hash)) {
    print $key, '=', $hash{$key}, "/n";
}
See also: Data
 
 Back to the top
 
DataSources
Returns an associative array of Data Sources and ODBC remarks in the form
of:
$ArrayName{'DSN'} = Remark
where DSN is the Data Source Name and Remark is, well, the remark.
Example:
%rem = $db->DataSources;
print LOG qq(Current DSN's Remark: "), %rem{$db->GetDSN}, qq("/n);
 
 Back to the top
 
Drivers
Returns an associative array of Drivers and their attributes in the form
of:
$ArrayName{'DRIVER'} = Attrib1;Attrib2;Attrib3;...
where DRIVER is the ODBC Driver Name and AttribX are the driver-defined
attributes.
Example:
%attrib = $db->Drivers;
print LOG qq($driver: $attrib{$driver}/n) foreach $driver (keys %attrib);
 
 Back to the top
 
DumpError
Dump to the screen details about the last error condition. This includes
error number, error text and the ODBC connection number that caused the
error (if there is one). This is used primarily for debugging.
Example:
$db = new Win32::ODBC("My DSN");
if (undef $db){
    Win32::ODBC::DumpError();
}
if ($db->Sql("Select * FROM foo")){
    $db->DumpError;
}
 
 Back to the top
 
DumpData
Dump to the screen all field names and the data in all rows of the current
dataset. This is used primarily for debugging.
Example:
$db->Sql("Select * FROM foo");
$db->DumpData;
 
 Back to the top
 
Error
Returns the last recorded error in the form of an array or string
(depending upon the context) containing the error number, error text and
the ODBC connection that caused the error (if there is one).
Example:
die $db->Error(), qq(/n);
 
($ErrNum, $ErrText, $ErrConn) = $db->Error();
 
 Back to the top
 
FetchRow
Fetches the next row of data from the previous specified SQL statement. You
would then call Data or DataHash to actually retrieve the individual
elements of data. Returns undef if there's an error, TRUE otherwise.
Example:
$db->Sql("SELECT * FROM foo");
$db->FetchRow() || die qq(Fetch error: ), $db->Error(), qq(/n);
$f1 = $db->Data("f1");
See also: Sql, Data, DataHash
 
 Back to the top
 
FieldNames
Returns a list of field names extracted from the current dataset. This is
used mostly for testing/debugging. FieldNames returns the data in an array,
with no guarantee of the order of the names.
Example:
$db->Sql("SELECT * FROM foo");
$db->FetchRow();
foreach $fd ($db->FieldNames()) print qq($fd: "), $db->Data($fd), qq("/n);
 
 Back to the top
 
GetConnections
Returns an array of connection numbers for all objects.
Example:
@cnums = $db->GetConnections;
 
 Back to the top
 
GetDSN
GetDSN conn
Returns the DSN (Data Source Name) or the ODBCDriverConnect string for the
connection conn, or the current connection if not specified.
Example:
print LOG qq(Current connection: "), $db->GetDSN, qq("/n);
 
 Back to the top
 
GetMaxBufSize
Returns the current maximum single field data size, in bytes.
Example:
$max = $db->GetMaxBufSize;
$db->SetMaxBufSize($needed) if ($max < $needed);
See also: SetMaxBufSize
 
 Back to the top
 
GetStmtCloseType
Returns the current ODBC close type setting. This is used mainly for
debugging. Type will be one of: SQL_CLOSE, SQL_DROP, SQL_UNBIND, or
SQL_RESET_PARAMS. See SetStmtCloseType for more info on what each of the
types mean, and how they are used.
Example:
$oldct = $db->GetStmtCloseType;
$db->SetStmtCloseType(SQL_DROP);
...
$db->SetStmtCloseType($oldct);
See also: SetStmtCloseType
 
 Back to the top
 
MoreResults
Sees if more result sets are present and initializes for fetching rows from
next result set. You would then call FetchRow to actually fetch the next
row of the next result set. Returns undef if there's an error, TRUE
otherwise.
Example:
$db->Sql("SELECT * FROM foo/n  SELECT * FROM bar");
$db->FetchRow() || die qq(Fetch error: ), $db->Error(), qq(/n);
$f1 = $db->Data("f1");
$db->MoreResults() || die qq(Error checking for more result sets: ),
$db->Error(), qq(/n);
$db->FetchRow() || die qq(Fetch error: ), $db->Error(), qq(/n);
$f1 = $db->Data("f1");
See also: Sql, Data
 
 Back to the top
 
new Win32::ODBC(DSN)
new Win32::ODBC(ODBCDriverConnect)
Creates a new ODBC object, given a DSN (Data Source Name) or a properly
formatted ODBCDriverConnect string. Returns the created ODBC object or
undef if there is an error.
Example:
$DSN = "MyDSN";
$db = new Win32::ODBC($DSN);
die qq(Cannot open new ODBC/n) if ! $db;
 
or
 
$db = new Win32::ODBC("dsn=FOO;UID=BAR;PWD=FUBAR");
die qq(Cannot open new ODBC/n) if ! $db;
 
 Back to the top
 
RowCount
Returns the number of rows that were affected by the previous SQL command.
Note: This does not work on all ODBC connections.
Example:
$db->Sql("SELECT * FROM foo");
print DBG q(# of records: ), $db->RowCount(), qq(/n);
 Back to the top
 
Run
stmt
Submit the SQL statement stmt and print data about it. This is used only in
debugging.
Example:
$db->Run("SELECT * FROM foo");
See also: Sql
 
 Back to the top
 
SetMaxBufSize
size
Sets the maximum buffer size that a single field can allocate when
executing a FetchRow. The default limit is 10240 bytes and the absolute
maximum is set to 2147483647 bytes. This absolute maximum can be reset by
recompiling the module. Returns undef if successful.
Example:
$newsize = 20480;
$rc = $db->SetMaxBufSize($newsize);
die qq(SetMaxBufSize($newsize) error: ), $db->Error, qq(/n) if ! $rc;
See also: GetMaxBufSize
 
 Back to the top
 
SetStmtCloseType
type
Sets the current ODBC close type setting used by the ODBC Manager. This is
used mainly for debugging. Normally, when you open a statement handle and
perform a query (or whatever) the results are associated with the
statement. You need to free the statement in order to execute another
query. When you do this, usually the dataset (from the query) is cached.
This caching action may be good for speed but could cause some memory
problems if your dataset is huge. See the ODBC API call SQLFreeStmt(hstmt,
option) for more details. (All of this is handled automatically by the
Win32::ODBC package).
 
Type will be one of:
SQL_CLOSE - just close the statement (use caching)
SQL_DROP - close and drop all results (do not use caching)
SQL_UNBIND - close and remove bindings to columns (odbc.pll does not bind
vars to columns)
SQL_RESET_PARAMS - close and reset all of the bound parameters (such as
type casting for columns; see SQLFreeStmt())
Example:
$oldct = $db->GetStmtCloseType;
$db->SetStmtCloseType(SQL_DROP);
...
$db->SetStmtCloseType($oldct);
See also: GetStmtCloseType
 
 Back to the top
 
ShutDown
Closes the ODBC connection and print data about it. This is used only in
debugging.
Example:
$db->Shutdown;
See also: Close
 
 Back to the top
 
Sql
stmt
Executes the SQL command stmt. Returns undef on success, SQL error code on
failure.
Example:
$stmt = "SELECT * FROM foo";
$rc = $db->Sql($stmt);
die qq(SQL failed "$stmt": ), $db->Error(), qq(/n) if $rc;
See also: Error
 
 Back to the top
 
TableList
TableList qualifier, owner, name, type
Retrieves the list of table names from the current ODBC object using
Catalog. If not specified, qualifier and owner default to "", name defaults
to "%", and type defaults to "'TABLE'". TableList returns an array of table
names. Note:All fieldnames are uppercase!
Example:
@tables = $db->TableList;
See also: Catalog
 
 
-----------------------------------------------------------------------------
---
 
 Back to the top
 
Examples
 
 
-----------------------------------------------------------------------------
---
This page maintined by Joe Casadonte. Please let me if something is wrong
or does not make sense. Send these or other comments to: joc@netaxs.com.

 
 
-----------------------------------------------------------------------------
---
 
 Win32::ODBC Object Documentation Page.
Copyright ?Dave Roth and Joseph L. Casadonte Jr. 1996. All rights reserved.
Courtesy of Roth Consulting.
 
Last updated 2001.09.13

使用perl Win32::ODBC模块,让我蛋疼的经历。

尝试装了一下win32::ODBC模块。蛋疼从此开始了。按网上“泛滥”的方法,安装win32::ODBC模块,要先装gcc编译器,一水儿的说装dev c++,结果我安装完了,让我装dmake.exe。...
  • ChoasRules
  • ChoasRules
  • 2011年04月14日 11:39
  • 1992

VC++ WIN32程序利用ODBC连接MySQL数据库

VC++ WIN32程序利用ODBC连接MySQL进行数据库操作前步骤:在数据源(ODBC)进行数据源配置添加,需要有mysql-connector-odbc驱动(百度搜索下载相应位数版本)。 进行...
  • qq805886694
  • qq805886694
  • 2016年08月02日 21:27
  • 400

ODBC + WIN32 API 访问MYSQL 数据库实现简单QQ用户注册和登录

//在IT行业,不懂数据库是不行的,我自己在学校里还没有学过数据库有关的知识,不过由于前些日子写项目的要求,不得不去琢磨,虽然有很多数据库类别,包括微软的 SQL server ,access,ORA...
  • dai_jing
  • dai_jing
  • 2012年11月27日 20:20
  • 2403

【JS总结】——Document Object Model(DOM)

上一篇说道BOM,了解了什么是浏览器对象模型,下面就来了解一个新的模型。 简介: DOM:文档对象模型,是W3C组织推荐的处理可扩展标识语言的标准编程接口。BOM——浏览器对象模型到现在为止还是谁用谁...
  • u013038861
  • u013038861
  • 2015年05月24日 20:28
  • 1258

Document Object

Definition and Usage The Document object is the root of a document tree. The Document object gives...
  • Tender001
  • Tender001
  • 2012年05月30日 08:03
  • 867

MySQL在Windows上的安装及VC通过ODBC连接MySQL数据库

一、MySQL的安装1、下载地址http://dev.mysql.com/downloads/mysql/5.0.html2、下载内容(1)mysql-noinstall-5.0.45-win32.z...
  • zst126
  • zst126
  • 2007年11月16日 12:05
  • 6209

MySQL ODBC connector 在windows下自动安装的一个问题

在某些操作系统下,多次卸载安装MySQL ODBC connector会发现驱动出现异常不能使用,必须手工重装修复才可以。但如果你的驱动安装是集成在应用中一起安装的,怎么处理呢?您可以分两次两步来装,...
  • stephenxu111
  • stephenxu111
  • 2013年05月27日 12:18
  • 6931

【MySQL】 ODBC connector5.3.4 安装失败

今天安装mysql-installer-community-5.5.45.0其中有一个提示失败 Connector/ODBC 5.3.4 Failed 网上查了一下原因是: 需要安装Micros...
  • JCRunner
  • JCRunner
  • 2015年08月10日 18:01
  • 11142

利用反射实现简单的Class对象和Bson文档的转换

http://www.cnblogs.com/maybo/p/5182439.html  import java.util.List; import org.bson.Document; impo...
  • peterli_xue
  • peterli_xue
  • 2017年07月17日 19:25
  • 751

用VB操纵DHTML(Document)对象

要想有代码提示请按如下方法:1.工程->部件,选择Microsoft Internet Controls2.工程->引用,选择Microsoft HTML Object Library,OK可以按F2...
  • sbdx
  • sbdx
  • 2008年03月16日 00:04
  • 827
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Win32::ODBC Object Document
举报原因:
原因补充:

(最多只允许输入30个字)