来源网址:http://www.orafaq.com/faq/oo4o
本站翻译:http://mytju.com/classocde/ ============================================================== OO4O
Oracle Objects for OLE -------------------------------------------------------------------- How does OO4O compare to ODBC?OO4O和ODBC比起来如何? OO4O provides native access to Oracle and only Oracle databases, and is thus faster than ODBC access.
ODBC is more generic and not database specific at all. One can use ODBC to connect to databases like
Oracle, DB/2, SQLServer, etc. For more information about ODBC, read the ODBC FAQ.
OO4O仅仅提供了针对Oracle数据库的本地访问,因此比ODBC访问更快。ODBC则更通用,它可以连接到Oracle、DB/2、SQL
Server等等数据库。更多关于ODBC的信息,请阅读ODBC的FAQ。
OO4O closely follows the ODBC query interface model, one can retain over 95% code compatibility between
the OO4O and ODBC versions of data layer procedures. This translates to very short retooling times when
porting between OO4O and ODBC.
OO4o紧密地遵循ODBC查询接口模型,在OO4o和ODBC版本的数据层程序之间,可以保持95%以上的代码兼容性。OO4O和ODBC
之间的相互移植转换只需花费很少的时间。
-------------------------------------------------------------------- What is Oracle Objects for OLE? OO4O是什么? Oracle Objects for OLE (OO4O) is a middleware product manufactured by Oracle Corporation that allows native access (no ODBC) to Oracle databases from client applications via Microsoft OLE (Object Linking and Embedding) and COM.
OO4O是Oracle公司开发的中间件产品,它允许客户端应用程序通过Microsoft的OLE和COM,对Oracle数据库进行本地访问
(不是ODBC)。
One can bind grids, text box widgets, and so on to OO4O via its own Data Control, one can also create dynasets, execute stored procedure code, or just about any other Oracle command one can think of. Oracle Objects consists of the following three components:
我们可以建立dynasets,执行存储过程,或者你可以想到的几乎所有的Oracle命令。 Oracle对象由以下3个组件构成:
An OLE 2.0 Automation (InProcess) Server - This provides an OLE Automation interface to applications that support OLE automation scripting such as Visual Basic (VB).
提供针对应用程序的OLE Automation接口,支持OLE automation脚本,如VB。
An Oracle Data Control - This is the Visual Basic custom control (VBX).
Two C++ Class Libraries - C-Libraries for Microsoft Foundation Classes (MFC) and Borland (OWL). -------------------------------------------------------------------- Can I use OO4O to access Oracle data from Microsoft applications? 我可以在Microsoft应用程序中使用OO4O访问Oracle数据吗?
Yes, you can use OO4O from any Microsoft application that uses the VB-style macro language. This includes applications like:
是的,你可以在任何使用VB风格宏语言的Microsoft应用程序中使用OO4O。 包括:
Microsoft Visual Basic Microsoft Excel Microsoft MS-Access Active Server Pages (ASP) C++, etc. -------------------------------------------------------------------- How does one install and configure OO4O?如何安装配置OO4O? Follow these steps to install and configure OO4O:
按以下步骤安装和配置OO4O:
Install the Oracle Client CD on your workstation. This will install OO4O (Oracle Objects for OLE) and
SQL*Net on your system.
在你的工作站上安装Oracle客户端CD,这样将在你的系统中安装OO4O和SQL*Net。
Configure SQL*Net and ensure you can tnsping and connect your Oracle database. This is done by adding an
entry to the TNSNAMES.ORA file or by using utilities like the "Net Easy Configurator" to do it for you.
See the SQL*Net FAQ for details.
配置SQL*Net,保证可以通过TNS连接到Oracle数据库。 可以通过在TNSNAMES.ORA中添加条目来实现,或者使用象"Net Easy Configurator"等使用工具来实现。
You are ready to GO!!! -------------------------------------------------------------------- What OO4O Objects are available for use while programming? 编程的时候,哪些OO4O对象是可用的?
OO4O makes the following high-level Objects available for use: OO4O有以下上层对象可用:
- OraSession - The first top-level object needed before we can connect to an Oracle database.
连接到Oracle数据库之前,第一个需要的上层对象。
- OraServer - Represents a physical connection to an Oracle database server instance. The OpenDatabase function can
be used to create client sessions by returning an OraDatabase object.
代表一个到Oracle数据库服务器实例的物理连接。 OpenDatabase方法可以用来建立客户端会话,它返回一个OraDatabase对象。
- OraDatabase - Represents a single login to an Oracle database. Similar to the ADO Connection object. OraDatabase
objects are returned by the OraSession.OpenDatabase function.
代表到Oracle数据库的一个单独的登录。类似于ADO Connection对象。OraDatabase对象由OraSession.OpenDatabase方
法返回。
- OraConnection - Returns various pieces of user information about the current OraSession object. It can be shared by
many OraDatabase objects, but each OraDatabase must exist in the same OraSession object.
返回当前OraSession的使用者信息。它可以被多个OraDatabase对象共享,但这些OraDatabase必须属于同一个
OraSession。
- OraDynaset - Similar to an ADO Recordset object. Represents the results retrieved by a call to the
OraDatabase.CreateDynaset function.
类似于ADO Recordset对象,代表OraDatabase.CreateDynaset方法返回的结果。
- OraField - Represents a column of data within an OraDynaset object. Similar to the ADO Field object of an ADO
Recordset.
代表OraDynaset对象中的数据的列。类似于ADO Recordset中的ADO Field对象。
- OraClient - Automatically created by OO4O as needed. Maintains a list of all active OraSession objects currently
running on the workstation.
OO4O需要时自动创建。维持一个在当前工作站上运行的所有活动OraSession对象的列表。
- OraParameter - Represents a bind variable for a SQL statement or PL/SQL block to be executed using the OraDynaset
object. Similar to the Parameter object in an ADO Command object.
代表提供给OraDynaset对象执行的SQL语句或PL/SQL语句块的绑定变量。 类似于ADO Command对象中的Parameter 对象。
- OraParamArray - Allows arrays of parameters to be set for the OraDatabase.Parameters function.
提供给OraDatabase.Parameters方法的参数数组。
- OraSQLStmt - Represents a single SQL statement. Typically used with SQL statements that include bind variables to
improve performance as Oracle does not have to parse the statement each time it is executed. Can be
thought of as conceptually similar to the ADO Command object.
代表一个单独的SQL声明。它的典型应用就是包含绑定变量,以改进性能,因为Oracle不必每次执行时都解析语句。 概念上类似于ADO Command对象。
- OraMetaData - Returns meta data to describe a particular schema such as column names. Similar to the SQL Server DMO
object library. See the meta data example below.
返回描述特定的模式(如列名)的元数据。类似于SQL Server 的DMO对象库。
- OraAQ - The CreateAQ method of the OraDatabase returns an OraAQ object. This provides access to Oracle's
Advanced Queuing message system that allows messages to be passed between applications, much like MSMQ.
OraDatabase的CreateAQ方法返回一个OraAQ对象。它提供了对Oracle的Advanced Queuing message system的访问,允许
消息在应用程序(如MSMQ消息中间件)之间传递。 -------------------------------------------------------------------- How does one connect to an Oracle Database? 如何连接到一个Oracle数据库?
Connect to Oracle using the OpenDatabase function. The OpenDatabase function returns an OraDatabase object. Parameters are DB_NAME, CONNECT_DESCRIPTOR and CONNECT_OPTIONS. Look at the following Visual Basic code example:
使用OpenDatabase方法连接到Oracle。 OpenDatabase方法返回一个OraDatabase对象, 参数是DB_NAME(DB名称)、CONNECT_DESCRIPTOR(连接描述)和CONNECT_OPTIONS(连接选项)。 看看下面的Visual Basic代码范例:
Dim OraSession As Object 'Declare variables as OLE Objects Dim OraDatabase As Object Dim OraDynaset As Object
Set OraSession = CreateObject("OracleInProcServer.XOraSession") Set OraDatabase = OraSession.DbOpenDatabase("SQL*Net_Connect_String", "scott/tiger", 0&) MsgBox "Connected to " & OraDatabase.Connect & "@" & OraDatabase.DatabaseName MsgBox "OO4O Version: " & OraSession.OIPVersionNumber MsgBox "Oracle Version: " & OraDatabase.RDBMSVersion
-------------------------------------------------------------------- How does one select data from an Oracle Database using OO4O? 如何通过OO4O从Oracle数据库中取得数据?
Use the OraDynaSet object to define recordsets. Look at this simple example:
使用OraDynaSet对象定义记录集,看范例:
Set OraSession = CreateObject("OracleInProcServer.XOraSession") Set OraDatabase = OraSession.DbOpenDatabase("SQL*Net_Connect_String", "scott/tiger", 0&) Set OraDynaset = OraDatabase.DbCreateDynaset("select empno, ename from emp", 0&) MsgBox "Employee " & OraDynaset.Fields("empno").value & ", #" & OraDynaset.Fields("ename").value
One can also loop through the result set using code like this: 也可以这样循环输出结果。
Do While(OraDynaset.EOF = FALSE) Response.write(OraDynaset.Fields("TNAME") & " ") osRecordSet.MoveNext Loop
-------------------------------------------------------------------- How does one use bind variables in OO4O? 在OO4O中如何使用绑定变量?
Use the "OraParameters.Add Name, Value, IOType" method to substitute bind variables with values before
executing a statement. If you don't, you will get error "not all variables bound". The IOType filed can be one of the following:
执行语句之前,使用"OraParameters.Add Name, Value, IOType"方法用值替换绑定变量。 如果你没有这样做,将报错:"not all variables bound" IOType列可以是以下值:
ORAPARM_INPUT - Use as input variable only (只是输入变量)
ORAPARM_OUTPUT - Use as output variable only(只是输出变量)
ORAPARM_BOTH - Use the variable for input and output (输入和输出变量)
Look at this example:
sqlStmt = "SELECT tname FROM tab WHERE tname LIKE :var1" OraDatabase.Parameters.add "var1", "%A%", 1 ' Substitute Name=Value of type ORAPARM_INPUT Set osRecordSet = OraDatabase.DbCreateDynaset(sqlStmt, cint(0)) Do While(osRecordset.EOF = FALSE) ' Use data: osRecordset.Fields("TNAME") in this example... osRecordSet.MoveNext Loop
-------------------------------------------------------------------- How does one execute DML and DDL statements using OO4O? 如何使用OO4O执行DML和DDL语句?
One can use any valid DDL and DML statement with the ExecuteSQL (or DBExecuteSQL) method. Look at this
example: 可以使用ExecuteSQL (或者 DBExecuteSQL)方法执行任何有效的DML和DDL语句。
rowcount = OraDatabase.ExecuteSQL("create table X (A date)") rowcount = OraDatabase.ExecuteSQL("insert into X values (sysdate)") OraSession.CommitTrans ' or OraSession.Rollback
-------------------------------------------------------------------- How does one call a stored procedure from OO4O? 如何使用OO4O调用存储过程?
A stored procedure block can be executed from the CreateSQL or ExecuteSQL methods. OO4O supports the SQL
statement objects for PL/SQL stored procedures. Look at this VB example:
可以使用CreateSQL 或者ExecuteSQL方法执行存储过程。 OO4O支持PL/SQL存储过程。
sql1 = "begin test_sproc(param2=>'two_b', param1=>'one_b'); end;" rowcnt = OraDatabase.DbExecuteSQL(sql1)
More complex example using input and output parameters. Note that the output parameter returns a cursor:
下面是使用输入和输出参数的较复杂的例子。注意输出参数返回了一个游标。
OraDatabase.Parameters.Add "NAME", "SUPERSPORT", ORAPARM_INPUT OraDatabase.Parameters("NAME").ServerType = ORATYPE_VARCHAR2
OraDatabase.Parameters.Add "ORDCURSOR", 0, ORAPARM_OUTPUT OraDatabase.Parameters("ORDCURSOR").ServerType = ORATYPE_CURSOR
Set OraSQLStmt = OraDatabase.CreateSql("begin CUSTOMERS.GetCutomerSalesOrder(:Name,:OrdCursor);end;",
ORASQL_FAILEXEC)
Set OrderDynaset = OraDatabase.Parameters("ORDCURSOR").Value 'Now display the Dynaset's field value MsgBox "Order Details are " & OrderDynaset.fields("ordid").Value & " " &
-------------------------------------------------------------------- How does one use the OraMetaData Object to describe tables? 如何使用OraMetaData对象描述Table?
The OraMetaData object (available from Oracle8i) can be used to retrieve all sorts of information about an Oracle schema. For example, one can list all objects in a schema, all columns of a table, etc. Look at this simple ASP example:
OraMetaData对象(从Oracle8i可用)可以用来取得Oracle模式的所有种类的信息。 如:列出schema中的所有对象,一个表的所有列,等等。 看下面一个简单的ASP例子:
Response.write("<H1>Describe Table EMP:</H1>") Set objOraMetaData = OraDatabase.Describe("EMP") Set objOraMDAttribute = objOraMetaData("ColumnList") Set objColumnList = objOraMDAttribute.Value For iColCount = 0 To objColumnList.Count - 1 Set objColumnDetails = objColumnList(iColCount).Value Response.Write "<P>Column: " & objColumnDetails("Name") & _ " Type: " & objColumnDetails("DataType") & _ " Size: " & objColumnDetails("DataSize") & _ " IsNull: " & objColumnDetails("IsNull") & _ "Precision: " & objColumnDetails("Precision") & _ " Scale: " & objColumnDetails("Scale") Next
-------------------------------------------------------------------- 本站翻译:http://mytju.com/classocde/
|