Sekedar cuplikan tentang OO4O.
Semoga berguna.
===============================
Oracle Objects for OLE (OO4O) FAQ
$Date: 08-Jun-2002 $
$Revision: 1.14 $
$Author: Frank Naud� $
Topics
What is Oracle Objects for OLE (OO4O)?
How does OO4O compare to ODBC?
Can one use OO4O to access Oracle data from Microsoft applications?
How does one install and configure OO4O?
What OO4O Objects are available for use while programming?
How does one connect to an Oracle Database?
How does one select data from an Oracle Database using OO4O?
How does one use bind variables in OO4O?
How does one execute DML and DDL statements using OO4O?
How does one call a stored procedure from OO4O?
How does one use the OraMetaData Object to describe tables?
Where can one get more info about OO4O?
------------------------------------------------------------------------
--------
Back to Oracle FAQ Index
------------------------------------------------------------------------
--------
What is Oracle Objects for OLE?
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.
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:
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).
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).
OO4O's predecessor was called Oracle Glue.
Back to top of file
------------------------------------------------------------------------
--------
How does OO4O compare to 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 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.
Back to top of file
------------------------------------------------------------------------
--------
Can I use OO4O to access Oracle data from Microsoft applications?
Yes, you can use OO4O from any Microsoft application that uses the
VB-style macro language. This includes applications like:
Microsoft Visual Basic
Microsoft Excel
Microsoft MS-Access
Active Server Pages (ASP)
C++, etc.
Back to top of file
------------------------------------------------------------------------
--------
How does one install and configure OO4O?
Follow these steps to install and configure OO4O:
Install the Oracle Client CD on your workstation. This will install OO4O
(Oracle Objects for OLE) and SQL*Net on your system.
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.
You are ready to GO!!!
Back to top of file
------------------------------------------------------------------------
--------
What OO4O Objects are available for use while programming?
OO4O makes the following high-level Objects available for use:
OraSession The first top-level object needed before we can connect to
an Oracle database.
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.
OraDatabase Represents a single login to an Oracle database. Similar to
the ADO Connection object. OraDatabase objects are returned by the
OraSession.OpenDatabase function.
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.
OraDynaset Similar to an ADO Recordset object. Represents the results
retrieved by a call to the OraDatabase.CreateDynaset function.
OraField Represents a column of data within an OraDynaset object.
Similar to the ADO Field object of an ADO Recordset.
OraClient Automatically created by OO4O as needed. Maintains a list of
all active OraSession objects currently running on the workstation.
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.
OraParamArray Allows arrays of parameters to be set for the
OraDatabase.Parameters function.
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.
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.
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.
Back to top of file
------------------------------------------------------------------------
--------
How does one connect to an Oracle Database?
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:
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
Back to top of file
------------------------------------------------------------------------
--------
How does one select data from an Oracle Database using OO4O?
Use the OraDynaSet object to define recordsets. Look at this simple
example:
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") & "<BR>")
osRecordSet.MoveNext
Loop
Back to top of file
------------------------------------------------------------------------
--------
How does one use bind variables in 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:
1 ORAPARM_INPUT Use as input variable only
2 ORAPARM_OUTPUT Use as output variable only
3 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
Back to top of file
------------------------------------------------------------------------
--------
How does one execute DML and DDL statements using OO4O?
One can use any valid DDL and DML statement with the ExecuteSQL (or
DBExecuteSQL) method. Look at this example:
rowcount = OraDatabase.ExecuteSQL("create table X (A date)")
rowcount = OraDatabase.ExecuteSQL("insert into X values
(sysdate)")
OraSession.CommitTrans ' or OraSession.Rollback
Back to top of file
------------------------------------------------------------------------
--------
How does one call a stored procedure from 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:
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
& " " &
Back to top of file
------------------------------------------------------------------------
--------
How does one use the OraMetaData Object to describe tables?
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:
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")
& _
"<BR>Type: " &
objColumnDetails("DataType") & _
"<BR>Size: " &
objColumnDetails("DataSize") & _
"<BR>IsNull: " &
objColumnDetails("IsNull") & _
"<BR>Precision: " &
objColumnDetails("Precision") & _
"<BR>Scale: " & objColumnDetails("Scale")
Next
Back to top of file
------------------------------------------------------------------------
--------
Where can one get more info about OO4O?
OO4O on OTN
Untuk berhenti berlangganan kirim email kosong ke : [EMAIL PROTECTED]
Ikuti juga forum diskusi VB.net dengan
mengirim email kosong ke [EMAIL PROTECTED]
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/indoprog-vb/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/