Introduction
ODBC PowerPack v1.2 release brought an interesting feature for all API drivers. New version gives you an ability to create Custom Objects. You can create parameterized Stored Procedure and Virtual Tables on the same Data Source (ODBC DSN or Data Gateway Data Source). For more information you see here
Custom Objects
There are mainly 3 types of custom objects you can create using ZappySys Drivers.
Custom Stored Procedure
You can create procedures to encapsulate custom logic and then only pass handful parameters rather than long SQL to execute your API call.
Stored Procedure with Parameters
Here is an example stored procedure for JSON Driver. You can insert Placeholders anywhere inside Proc Body. Read more about placeholders here
1 2 3 4 5 6 7 8 9 10 11 |
CREATE PROCEDURE usp_UploadData @file='test.json', @source='HRApp' AS SELECT * FROM $ WITH (METHOD='POST', HEADER='Content-Type: text/plain || x-hdr1: AAA' ,SRC='http://httpbin.org/post?src=<@source>×tamp=<<FUN_TODAY>>' ,BODY='@c:\files\<@file,FUN_TRIM>' ,IsMultiPart='True' ) |
To call stored procedure from client app using below SQL. Must prefix EXEC proc_name [parameter values….]
1 |
EXEC usp_UploadData 'Jan_data1.json' , 'HRApp' |
Stored Procedure without Parameters
Using Functions in Stored Procedure
ZappySys provides many functions which can be used as placeholder anywhere inside Stored Proc code or in your SQL query for Driver
Example of simple function (No parameter)
1 2 3 4 5 |
CREATE PROCEDURE usp_OrdersByCountry @country='INDIA' --always supply some default parameter so metadata can be guessed AS SELECT * FROM Orders WHERE Country='<@country,FUN_TRIM>') |
Example of function with parameters
In below example we have invoked function after we replaced parameter. Our function FUN_TO_DATE has 2 parameters (actual date value and format we want to output). This way we can control replacement order
1 2 3 4 5 |
CREATE PROCEDURE usp_OrdersByDate @orderdate='2012-01-01' --always supply some default parameter so metadata can be guessed AS SELECT * FROM Orders WHERE OrderDate=DATETIME('<<<@orderdate>||yyyy-MM-dd,FUN_TO_DATE>>') |
Virtual Table – Connection String Mode
ZappySys Drivers support flexible Query language so you can override Default Properties you configured on Data Source such as URL, Body. This way you dont have to create multiple Data Sources if you like to read data from multiple EndPoints. However not every application support supplying custom SQL to driver so you can only select Table from list returned from driver.
Many applications like MS Access, Informatica Designer wont give you option to specify custom SQL when you import Objects. In such case Virtual Table is very useful. You can create many Virtual Tables on the same Data Source (e.g. If you have 50 URLs with slight variations you can create virtual tables with just URL as Parameter setting.
1 2 3 4 5 6 7 8 |
<strong>vt__Accounts</strong> DataPath=http://mycompany/api/customers <strong>vt__Leads</strong> DataPath=http://mycompany/api/leads <strong>vt__Contacts</strong> DataPath=http://mycompany/api/contacts |
All Virtual Tables will be listed along with Other Tables returned by your Data Source from Response.
Virtual Table – SQL Mode (v1.6 or higher)
Version 1.6+ introduced new mode to create Virtual Table. Now you can write custom SQL just like a View in Relational DB.
See below example
Virtual Table Use Cases
Now lets look at a few real world use cases where Virtual Tables might be useful. You can use when your Client Application doesn’t have support to connect to ODBC in SQL Query mode and only allows Table selection / import.
MS Access – Import Tables
If you are using ZappySys ODBC Driver to integrate API in MS Access then Virtual Tables are useful because MS Access only allows to choose Tables when you import and no place to enter custom Query.
Informatica – Import Tables (Create Source / Target Schema from ODBC DSN)
Here is another use case of informatica rest / json api integration. Informatica doesnt allow to import SQL Query structure so you must choose exposed tables. Using Virtual Tables feature you can import multiple tables from Same ODBC DSN
Preview Data
Once virtual tables are defined you can go to preview tab and it will show entries there regardless your Data Source settings on main UI.
Troubleshooting Errors
While running in Access\Excel\other and reading data from DSN created with ODBC PowerPack, if you get this error "License type [ODBC_PP_TRIAL] not found or its expired"
Please refer to this article for the same: Troubleshooting "License type [ODBC_PP_TRIAL] not found or its expired" error in Microsoft Access