SAS/ACCESS Interface to OLE DB |
Key Information |
For general information about this feature, see Overview of the SQL Pass-Through Facility. OLE DB examples are available.
Here are the SQL pass-through facility specifics for the OLE DB interface.
PROC SQL supports multiple connections to OLE DB. If you use multiple simultaneous connections, you must use an alias to identify the different connections. If you do not specify an alias, the default alias, OLEDB , is used. The functionality of multiple connections to the same OLE DB provider might be limited by a particular provider.
The CONNECT statement database-connection-arguments are identical to the LIBNAME connection options. For some data sources, the connection options have default values and are therefore not required.
Not all OLE DB providers support all connection options. See your provider documentation for more information.
Here are the LIBNAME options that are available with the CONNECT statement:
Examples |
This example uses an alias to connect to a Microsoft SQL Server database and select a subset of data from the PAYROLL table. The SAS/ACCESS engine uses OLE DB Services to connect to OLE DB because this is the default action when the OLEDB_SERVICES= option is omitted.
proc sql; connect to oledb as finance (user=username password=password datasource=dwtsrv1 provider=sqloledb); select * from connection to finance (select * from payroll where jobcode='FA3'); quit;
In this example, the CONNECT statement omits the provider name and properties. An OLE DB Services dialog box prompts you for the connection information.
proc sql; connect to oledb; quit;
This example uses OLE DB Services to connect to a provider that is configured under the data source name User's Data with the alias USER1. Note that the data source name can contain quotation marks and spaces.
proc sql; connect to oledb as user1 (provider=JET datasource='c:\db1.mdb');;
Special Catalog Queries |
SAS/ACCESS Interface to OLE DB supports the following special queries. Many databases provide or use system tables that allow queries to return the list of available tables, columns, procedures, and other useful information. OLE DB provides much of this functionality through special application programming interfaces (APIs) to accommodate databases that do not follow the SQL table structure. You can use these special queries on SQL and non-SQL databases.
Not all OLE DB providers support all queries. See your provider documentation for more information.
Here is the general format of the special queries:
OLEDB::schema-rowset("parameter 1","parameter n") |
is required to distinguish special queries from regular queries.
is the specific schema rowset that is being called. All valid schema rowsets are listed under the IDBSchemaRowset Interface in the Microsoft OLE DB Programmer's Reference. Both OLEDB:: and schema-rowset are case sensitive.
is a quoted string that is enclosed by commas. The values for the special query arguments are specific to each data source. For example, you supply the fully qualified table name for a "Qualifier" argument. In dBase, the value of "Qualifier" might be c:\dbase\tst.dbf , and in SQL Server, the value might be test.customer . In addition, depending on the data source that you use, values for an "Owner" argument might be a user ID, a database name, or a library. All arguments are optional. If you specify some but not all arguments within a parameter, use commas to indicate omitted arguments. If you do not specify any parameters, no commas are necessary. These special queries might not be available for all OLE DB providers.
OLE DB supports these special queries:
returns assertions that are defined in the catalog that a given user owns.
returns physical attributes that are associated with catalogs that are accessible from the DBMS.
returns the character sets that are defined in the catalog that a given user can access.
returns check constraints that are defined in the catalog and that a given user owns.
returns the character collations that are defined in the catalog and that a given user can access.
returns the columns that are defined in the catalog, are dependent on a domain that is defined in the catalog, and a given user owns.
returns the privileges on columns of tables that are defined in the catalog that a given user grants or can access.
returns the columns of tables that are defined in the catalogs that a given user can access.
returns the columns that referential constraints, unique constraints, check constraints, and assertions use that are defined in the catalog and that a given user owns.
returns the tables that referential constraints, unique constraints, check constraints, and assertions use that are defined in the catalog and that a given user owns.
returns the foreign key columns that a given user defined in the catalog.
returns the indexes that are defined in the catalog that a given user owns.
returns the columns that are defined in the catalog and that a given user has constrained as keys.
returns the primary key columns that a given user defined in the catalog.
returns information about the columns of rowsets that procedures return.
returns information about the parameters and return codes of the procedures.
returns procedures that are defined in the catalog that a given user owns.
returns output that contains these columns: PROVIDER_NAME, PROVIDER_DESCRIPTION, and PROVIDER_PROPERTIES. The PROVIDER_PROPERTIES column contains a list of all properties that the provider supports. A semicolon (;) separates the properties. See Examples of Special OLE DB Queries.
returns information about the base data types that the data provider supports.
returns the referential constraints that are defined in the catalog that a given user owns.
returns the conformance levels, options, and dialects that the SQL implementation processing data supports and that is defined in the catalog.
returns the statistics that is defined in the catalog that a given user owns.
returns the table constraints that is defined in the catalog that a given user owns.
returns the privileges on tables that are defined in the catalog that a given user grants or can access.
returns the tables defined in the catalog that a given user grants and can access.
returns the character translations that are defined in the catalog and that are accessible to a given user.
returns the USAGE privileges on objects that are defined in the catalog and that a given user grants or can access.
returns the columns on which viewed tables depend that are defined in the catalog and that a given user owns.
returns the tables on which viewed tables depend that are defined in the catalog and that a given user owns.
returns the viewed tables that are defined in the catalog and that a given user can access.
For a complete description of each rowset and the columns that are defined in each rowset, see the Microsoft OLE DB Programmer's Reference.
The following example retrieves a rowset that displays all tables that the HRDEPT schema accesses:
proc sql; connect to oledb(provider=sqloledb properties=("User ID"=testuser Password=testpass "Data Source"='dwtsrv1')); select * from connection to oledb (OLEDB::TABLES(,"HRDEPT")); quit;
It uses the special query OLEDB::PROVIDER_INFO() to produce this output:
proc sql; connect to oledb(provider=msdaora properties=("User ID"=testuser Password=testpass "Data Source"="Oraserver")); select * from connection to oledb (OLEDB::PROVIDER_INFO()); quit;
Provider and Properties Output
PROVIDER_NAME PROVIDER_DESCRIPTION PROVIDER_PROPERTIES ------------- -------------------- ------------------- MSDAORA Microsoft OLE DB Password;User ID;Data Provider for Oracle Source;Window Handle;Locale Identifier;OLE DB Services; Prompt; Extended Properties; SampProv Microsoft OLE DB Data Source;Window Handle; Sample Provider Prompt;
You could then reference the output when automating a connection to the provider. For the previous result set, you could write this SAS/ACCESS LIBNAME statement:
libname mydblib oledb provider=msdaora props=('Data Source'=OraServer 'User ID'=scott 'Password'=tiger);
Copyright © 2010 by SAS Institute Inc., Cary, NC, USA. All rights reserved.