Discover how a bimodal integration strategy can address the major data management challenges facing your organization today.
Get the Report →A PostgreSQL Interface for WooCommerce Data
Use the SQL Gateway and WooCommerce ODBC Driver to create a PostgreSQL entry-point for data access.
There are a vast number of PostgreSQL clients available on the Internet. From standard Drivers to BI and Analytics tools, PostgreSQL is a popular interface for data access. Using the SQL Gateway included in our ODBC Drivers, you can now create PostgreSQL entry-points that you can connect to from any standard client.
To access WooCommerce data as a PostgreSQL database on Windows, use the CData SQL Gateway, the ODBC Driver for WooCommerce, and the MySQL foreign data wrapper from EnterpriseDB. In this article, we compile the foreign data wrapper in Visual Studio, install it as an extension, and query WooCommerce data from PostgreSQL Server.
Configure the Connection to WooCommerce
If you have not already, first specify connection properties in an ODBC DSN (data source name). This is the last step of the driver installation. You can use the Microsoft ODBC Data Source Administrator to create and configure ODBC DSNs.
WooCommerce supports the following authentication methods: one-legged OAuth1.0 Authentication and standard OAuth2.0 Authentication.
Connecting using one-legged OAuth 1.0 Authentication
Specify the following properties (NOTE: the below credentials are generated from WooCommerce settings page and should not be confused with the credentials generated by using WordPress OAuth2.0 plugin):
- ConsumerKey
- ConsumerSecret
Connecting using WordPress OAuth 2.0 Authentication
After having configured the plugin, you may connect to WooCommerce by providing the following connection properties:
In either case, you will need to set the Url property to the URL of the WooCommerce instance.
The MySQL remoting service is a daemon process that listens for clients' incoming MySQL connections. See the setup guide in the SQL Gateway overview to configure the MySQL Remoting service in the CData SQL Gateway.
The Foreign Data Wrapper can be installed as an extension to PostgreSQL, without recompiling PostgreSQL. If you are running PostgreSQL on a Unix-based system, you can use the PostgreSQL Extension Network (PGXN) to install the FDW, mysql_fdw. If you are running PostgreSQL on Windows, compile the extension to ensure that you are working with the latest version. Follow the steps below to make the necessary modifications to build the extension from Visual Studio:
To build the foreign data wrapper, do the following:
After you have obtained the necessary software and source code, you are ready to compile the extension with Visual Studio. Follow the steps below to create a project using the mysql_fdw source:
Follow the steps below to configure your project:
Follow the steps below to add the required dependencies:
After setting up a project, make the following changes to build mysql_fdw in Visual Studio:
You can now select the Release configuration and build.
After you have compiled the DLL, follow the steps below to install the extension:
After you have installed the extension, follow the steps below to start executing queries to WooCommerce data:
You can now execute read/write commands to WooCommerce:
Start the Remoting Service
Build the MySQL Foreign Data Wrapper
Obtain Prerequisites
Configure a Project
postgres.lib
libmysql.lib
WS2_32.lib
Secur32.lib
Additionally, ensure that Inherit From Parent or Project Defaults is checked.
MyMySQLConnectorCInstallation\include
MyPostgreSQLInstallation\MyPostgreSQLVersion\include\server\port\win32_msvc
MyPostgreSQLInstallation\MyPostgreSQLVersion\include\server\port\win32
MyPostgreSQLInstallation\MyPostgreSQLVersion\include\server
MyPostgreSQLInstallation\MyPostgreSQLVersion\include
Configure mysql_fdw for Windows
#define dlsym(lib, name) (void*)GetProcAddress((HMODULE)lib, name)
#define dlopen(libname, unused) LoadLibraryEx(libname, NULL, 0)
mysql_dll_handle = dlopen(_MYSQL_LIBNAME, RTLD_LAZY | RTLD_DEEPBIND);
mysql_dll_handle = dlopen("libmysql.dll", 0);
__declspec(dllexport) extern Datum mysql_fdw_handler(PG_FUNCTION_ARGS);
__declspec(dllexport) extern Datum mysql_fdw_validator(PG_FUNCTION_ARGS);
Install the Extension
Query WooCommerce Data as a PostgreSQL Database
C:\> psql -U postgres
postgres=#CREATE EXTENSION mysql_fdw;
postgres=# CREATE SERVER WooCommerce FOREIGN DATA WRAPPER mysql_fdw OPTIONS (host
'127.0.0.1', port '3306');
postgres=# CREATE USER MAPPING for postgres SERVER WooCommerce OPTIONS (username
'admin', password 'test');
postgres=# CREATE SCHEMA WooCommerce_db;
postgres=# IMPORT FOREIGN SCHEMA "CData WooCommerce Sys" FROM SERVER WooCommerce INTO WooCommerce_db;
postgres=# SELECT * FROM WooCommerce_db."orders";