OLE DB PROVIDER
DEVELOPMENT
Arun Seetharaman
Computer Call
January 20, 1999
AGENDA
• Universal Data Access
• What is an OLE DB provider?
• Creating an OLE DB provider with the OLE DB Provider
Templates
• Extending the provider
• Questions and answers
Data
access
Universal Data Access
WHAT IS AN OLE DB
DATA PROVIDER?
• Implements core OLE DB interfaces
• Common interfaces to native functionality
• Does not require data to look like a relational
database
• Implements extended OLE DB interfaces to
expose native extended functionality
SCENARIOS
• Relational Data
• ODBC Driver exists, No OLE DB Provider
• You App uses ADO to talk to OLE DB Provider for ODBC ,
which talks to the ODBC driver
◆ Relational Data
⚫ OLE DB Provider exists
⚫ You App uses ADO to talk to OLE DB Provider
SCENARIOS
• Data in Exchange Server
• OLE DB Provider exists, No Query Engine
• You App uses ADO to talk to MS Exchange OLE DB Provider,
calls upon a Query Processor component to handle querying
◆ Data in NT File System
⚫ OLE DB Provider over Microsoft Index Server
⚫ You App uses ADO to talk to OLE DB Provider
WHY WRITE A PROVIDER?
• To participate in Universal Data Access:
⚫ Take advantage of ADO to provide C/C++,
Java , Visual Basic®, IIS and OLE
Automation programmers easy access to
your data
⚫ Expose your data to SQL Server , Access,
Excel, and third-party consumers
⚫ Add power to your data through common
Query Processor, Cursor, Notification, and
Remoting components
⚫ Participate in heterogeneous joins
PROVIDER TEMPLATE SUPPORT
• You could implement a bunch
of interfaces
• OLE DB Provider Templates
• Implements 20 of the most common OLE DB interfaces
• New option in ATL Object Wizard
• Minimal providers ready to go
in ten minutes
PROVIDER TEMPLATE SUPPORT
• Implements data source, session, command, and rowset
objects
• Implements all mandatory interfaces
• Minimal case:
• Developer changes PROVIDER_COLUMN_MAP and Execute()
• Significant case:
• Developer adds in additional objects
and interfaces
CreateSession()
Session
IDBCreateCommand
IOpenRowset
Execute()
Rowset
Rowset
OpenRowset()
Command
ICommand
CreateCommand()
OLE DB PROVIDER STRUCTURE
Data Source
IDBCreateSession
PROPERTIES
• Can be set Objectwise
• Defines Object specific behaviour
• Type, Value, Read/Write attribute
• Property Sets
• Properties with the same GUID
• Many are Pre-defined in OLEDB
• Provider can define custom properties
GUID : PropertySet A
Count: 3
Pointer :
DBPROPSET Array
ID: Property 1
Value : Value1
ID: Property 2
Value : Value2
ID: Property 1
Value : Value1
GUID : PropertySet A
Count: 3
Pointer :
DBPROPIDSET Array
Property 1
Property 2
Property 3
DBPROPID Arrays
DATA SOURCE INTERFACES
• IDBProperties
• Sets properties used in initialization
• Returns information about
provider's capabilities
• Data Source Properties
Data Source Name, Version, Threading Model
• Initialization Properties
User ID, Password, Locale ID, Timeout
DATA SOURCE INTERFACES
• IDBInitialize
• Connects to the provider
• State Change to ‘Initialized’
◆ IDBCreateSession
⚫ Gets a session object
◆ IPersist
⚫ Returns your CLSID
⚫ To persist Connection Information
SESSION INTERFACES
• IGetDataSource
• Returns parent datasource
• ISessionProperties
• Sets properties on session
Transaction Isolation Levels Supported in Auto-Commit Mode
SESSION INTERFACES
• IOpenRowset
• To Work directly with Table
• No overhead of Query Language support
◆ IDBCreateCommand (Optional)
⚫ Only if you support commands
COMMAND INTERFACES
• ICommandProperties
• Set properties for open rowset
◆ ICommandText
⚫ Set and execute command
COMMAND INTERFACES
• IAccessor
• Defines how parameters are read
• Binds each column or parameter to Consumer’s buffer
◆ IColumnsInfo
⚫ Provides metadata about Columns
ROWSET OBJECT
People
Name Address Papers Picture Voice
David
Mike
Monica
NY
CA
DC
...
IStream
IRowset
IDraw IPlay
ROWSET OBJECT
• Universal abstraction for tabular data
• Base data, query results,
computed data, schema…
◆ Rows can contain COM objects
◆ Efficient, streamlined access to large objects
ROWSET OBJECT
• Rowset data can be shared
⚫ Multiple Consumers
⚫ Multiple Components
⚫ Notifications
⚫ Deferred/Immediate Updates
ROWSET INTERFACES
• IColumnsInfo
• Describes the columns of the rowset
◆ IAccessor
⚫ Defines how consumer reads data
◆ IRowsetInfo
⚫ Returns rowset properties
 Updatability, Bookmarks ...
⚫ Interface Support
 Find, Conversions ...
ROWSET INTERFACES
• IRowset
• GetNextRows retrieves row handles
• GetData reads data from row handles
◆ IConvertType
⚫ Use the Data Conversion library
CREATING AN OLE DB PROVIDER
• Run the OLE DB Provider Wizard
• Generates COM objects for data source, session,
command, and rowset
• Modify and extend code
class CAgentMan
{
public:
TCHAR szCommand[256];
TCHAR szText[256];
BEGIN_PROVIDER_COLUMN_MAP(CAgentMan)
PROVIDER_COLUMN_ENTRY(“Field1”, 1, szCommand)
PROVIDER_COLUMN_ENTRY(“Field2”, 2, szText)
END_PROVIDER_COLUMN_MAP()
};
MODIFY DATA STRUCTURE
• Represents one row of data
• Contains data members and meta-data
HRESULT Execute(DBPARAMS * pParams, LONG* pcRowsAffected)
{
...
}
MODIFY EXECUTE IN ROWSET
• Command is stored in m_strCommandText
• Create instances of your
data structure
• Place instances in m_rgRowData
• Set pcRowsAffected
DEMO
• Creating a minimal provider
• Run Provider Wizard
• Modify data structure
• Modify PROVIDER_COLUMN_MAP
• Modify Execute()
EXTENDING THE PROVIDER
• Schema rowsets
• Properties
• Add in validation routines
• Add additional OLE DB interfaces
CONFORMANCE TESTS
• Generic OLE DB tests that:
• Verify conformance to minimum level
• Test correctness of exposed interfaces
• Based on sample test suites
in OLE DB SDK
• Provide a performance benchmark
• Include ADO acceptance tests
SUMMARY
• Writing a provider gives you…
• C/C++, OLE Automation, Java,
and scripting access to your data through ADO
• Exposure to Microsoft® and third-party tools, products, and
components

OLE DB Provider Development - Encapsulating a Service Provider

  • 1.
    OLE DB PROVIDER DEVELOPMENT ArunSeetharaman Computer Call January 20, 1999
  • 2.
    AGENDA • Universal DataAccess • What is an OLE DB provider? • Creating an OLE DB provider with the OLE DB Provider Templates • Extending the provider • Questions and answers
  • 3.
  • 4.
    WHAT IS ANOLE DB DATA PROVIDER? • Implements core OLE DB interfaces • Common interfaces to native functionality • Does not require data to look like a relational database • Implements extended OLE DB interfaces to expose native extended functionality
  • 5.
    SCENARIOS • Relational Data •ODBC Driver exists, No OLE DB Provider • You App uses ADO to talk to OLE DB Provider for ODBC , which talks to the ODBC driver ◆ Relational Data ⚫ OLE DB Provider exists ⚫ You App uses ADO to talk to OLE DB Provider
  • 6.
    SCENARIOS • Data inExchange Server • OLE DB Provider exists, No Query Engine • You App uses ADO to talk to MS Exchange OLE DB Provider, calls upon a Query Processor component to handle querying ◆ Data in NT File System ⚫ OLE DB Provider over Microsoft Index Server ⚫ You App uses ADO to talk to OLE DB Provider
  • 7.
    WHY WRITE APROVIDER? • To participate in Universal Data Access: ⚫ Take advantage of ADO to provide C/C++, Java , Visual Basic®, IIS and OLE Automation programmers easy access to your data ⚫ Expose your data to SQL Server , Access, Excel, and third-party consumers ⚫ Add power to your data through common Query Processor, Cursor, Notification, and Remoting components ⚫ Participate in heterogeneous joins
  • 8.
    PROVIDER TEMPLATE SUPPORT •You could implement a bunch of interfaces • OLE DB Provider Templates • Implements 20 of the most common OLE DB interfaces • New option in ATL Object Wizard • Minimal providers ready to go in ten minutes
  • 9.
    PROVIDER TEMPLATE SUPPORT •Implements data source, session, command, and rowset objects • Implements all mandatory interfaces • Minimal case: • Developer changes PROVIDER_COLUMN_MAP and Execute() • Significant case: • Developer adds in additional objects and interfaces
  • 10.
  • 11.
    PROPERTIES • Can beset Objectwise • Defines Object specific behaviour • Type, Value, Read/Write attribute • Property Sets • Properties with the same GUID • Many are Pre-defined in OLEDB • Provider can define custom properties
  • 12.
    GUID : PropertySetA Count: 3 Pointer : DBPROPSET Array ID: Property 1 Value : Value1 ID: Property 2 Value : Value2 ID: Property 1 Value : Value1 GUID : PropertySet A Count: 3 Pointer : DBPROPIDSET Array Property 1 Property 2 Property 3 DBPROPID Arrays
  • 13.
    DATA SOURCE INTERFACES •IDBProperties • Sets properties used in initialization • Returns information about provider's capabilities • Data Source Properties Data Source Name, Version, Threading Model • Initialization Properties User ID, Password, Locale ID, Timeout
  • 14.
    DATA SOURCE INTERFACES •IDBInitialize • Connects to the provider • State Change to ‘Initialized’ ◆ IDBCreateSession ⚫ Gets a session object ◆ IPersist ⚫ Returns your CLSID ⚫ To persist Connection Information
  • 15.
    SESSION INTERFACES • IGetDataSource •Returns parent datasource • ISessionProperties • Sets properties on session Transaction Isolation Levels Supported in Auto-Commit Mode
  • 16.
    SESSION INTERFACES • IOpenRowset •To Work directly with Table • No overhead of Query Language support ◆ IDBCreateCommand (Optional) ⚫ Only if you support commands
  • 17.
    COMMAND INTERFACES • ICommandProperties •Set properties for open rowset ◆ ICommandText ⚫ Set and execute command
  • 18.
    COMMAND INTERFACES • IAccessor •Defines how parameters are read • Binds each column or parameter to Consumer’s buffer ◆ IColumnsInfo ⚫ Provides metadata about Columns
  • 19.
    ROWSET OBJECT People Name AddressPapers Picture Voice David Mike Monica NY CA DC ... IStream IRowset IDraw IPlay
  • 20.
    ROWSET OBJECT • Universalabstraction for tabular data • Base data, query results, computed data, schema… ◆ Rows can contain COM objects ◆ Efficient, streamlined access to large objects
  • 21.
    ROWSET OBJECT • Rowsetdata can be shared ⚫ Multiple Consumers ⚫ Multiple Components ⚫ Notifications ⚫ Deferred/Immediate Updates
  • 22.
    ROWSET INTERFACES • IColumnsInfo •Describes the columns of the rowset ◆ IAccessor ⚫ Defines how consumer reads data ◆ IRowsetInfo ⚫ Returns rowset properties  Updatability, Bookmarks ... ⚫ Interface Support  Find, Conversions ...
  • 23.
    ROWSET INTERFACES • IRowset •GetNextRows retrieves row handles • GetData reads data from row handles ◆ IConvertType ⚫ Use the Data Conversion library
  • 24.
    CREATING AN OLEDB PROVIDER • Run the OLE DB Provider Wizard • Generates COM objects for data source, session, command, and rowset • Modify and extend code
  • 25.
    class CAgentMan { public: TCHAR szCommand[256]; TCHARszText[256]; BEGIN_PROVIDER_COLUMN_MAP(CAgentMan) PROVIDER_COLUMN_ENTRY(“Field1”, 1, szCommand) PROVIDER_COLUMN_ENTRY(“Field2”, 2, szText) END_PROVIDER_COLUMN_MAP() }; MODIFY DATA STRUCTURE • Represents one row of data • Contains data members and meta-data
  • 26.
    HRESULT Execute(DBPARAMS *pParams, LONG* pcRowsAffected) { ... } MODIFY EXECUTE IN ROWSET • Command is stored in m_strCommandText • Create instances of your data structure • Place instances in m_rgRowData • Set pcRowsAffected
  • 27.
    DEMO • Creating aminimal provider • Run Provider Wizard • Modify data structure • Modify PROVIDER_COLUMN_MAP • Modify Execute()
  • 28.
    EXTENDING THE PROVIDER •Schema rowsets • Properties • Add in validation routines • Add additional OLE DB interfaces
  • 29.
    CONFORMANCE TESTS • GenericOLE DB tests that: • Verify conformance to minimum level • Test correctness of exposed interfaces • Based on sample test suites in OLE DB SDK • Provide a performance benchmark • Include ADO acceptance tests
  • 30.
    SUMMARY • Writing aprovider gives you… • C/C++, OLE Automation, Java, and scripting access to your data through ADO • Exposure to Microsoft® and third-party tools, products, and components