PyCharm でCData ODBC Driver for Sage US を使ってみた

Sage US にODBC データソースとしてPyCharm から連携。

CData ODBC Drivers は、ODBC をサポートするあらゆる環境から利用可能です。 本記事では、PyCharm からのCData ODBC Driver for Sage US の利用を説明します。ODBC Deriver をデータソースとして設定する方法、データソースをクエリするPyCharm のベーシックな方法を含みます。

To begin, this tutorial will assume that you have already installed the CData ODBC Driver for Sage US as well as PyCharm.

Pyodbc をプロジェクトに追加

Follow the steps below to add the pyodbc module to your project.

  1. Click File -> Settings to open the project settings window.
  2. Click Project Interpreter from the Project: YourProjectName menu.
  3. To add pyodbc, click the + button and enter pyodbc.
  4. Click Install Package to install pyodbc.

Sage US への接続

You can now connect with an ODBC connection string or a DSN. See the Getting Started section in the CData driver documentation for a guide to creating a DSN on your OS.

The Application Id and Company Name connection string options are required to connect to Sage as a data source. You can obtain an Application Id by contacting Sage directly to request access to the Sage 50 SDK.

Sage must be installed on the machine. The Sage.Peachtree.API.dll and Sage.Peachtree.API.Resolver.dll assemblies are required. These assemblies are installed with Sage in C:\Program Files\Sage\Peachtree\API\. Additionally, the Sage SDK requires .NET Framework 4.0 and is only compatible with 32-bit applications. To use the Sage SDK in Visual Studio, set the Platform Target property to "x86" in Project -> Properties -> Build.

You must authorize the application to access company data: To authorize your application to access Sage, restart the Sage application, open the company you want to access, and connect with your application. You will then be prompted to set access permissions for the application in the resulting dialog.

While the compiled executable will require authorization only once, during development you may need to follow this process to reauthorize a new build. To avoid restarting the Sage application when developing with Visual Studio, click Build -> Configuration Manager and uncheck "Build" for your project.

Below is the syntax for a DSN:

[CData Sage50US Source] Driver = CData ODBC Driver for Sage US Description = My Description ApplicationId = 8dfafu4V4ODmh1fM0xx CompanyName = Bellwether Garden Supply - Premium

Sage US へのクエリの実行

Instantiate a Cursor and use the execute method of the Cursor class to execute any SQL statement.

import pyodbc cnxn = pyodbc.connect('DRIVER={CData ODBC Driver for Sage50US};ApplicationId = 8dfafu4V4ODmh1fM0xx;CompanyName = Bellwether Garden Supply - Premium;') cursor = cnxn.cursor() cursor.execute("SELECT Name, LastInvoiceAmount FROM Customer WHERE Name = 'ALDRED'") rows = cursor.fetchall() for row in rows: print(row.Name, row.LastInvoiceAmount)

After connecting to Sage US in PyCharm using the CData ODBC Driver, you will be able to build Python apps with access to Sage US data as if it were a standard database. If you have any questions, comments, or feedback regarding this tutorial, please contact us at support@cdata.com.

 
 
ダウンロード