Developing Python application with Sybase ASEGetting Started Guide for Sybase ASE and Python
www.sap.comTABLE OF CONTENTSINTRODUCTION . 3ASE CONFIGURATION STEPS . 3PYTHON REQUIREMENTS . 3Using Extension Module for Python . 4Connecting to ASE Server . 4Sample Python Program to query and display rows . 5Sample Program to insert, update rows . 6RUN SAMPLE PROGRAMS . 6Output from starting Python Program . 6SYBASE SUPPORT FOR PYTHON ODBC DRIVER . 6Connection String for PyODBC . 7Using PyODBC . 10Row Modification . 10 2013 SAP AG. All rights reserved.SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAPBusinessObjects Explorer, StreamWork, SAP HANA, and other SAPproducts and services mentioned herein as well as their respectivelogos are trademarks or registered trademarks of SAP AG in Germanyand other countries.Business Objects and the Business Objects logo, BusinessObjects,Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, andother Business Objects products and services mentioned herein aswell as their respective logos are trademarks or registered trademarksof Business Objects Software Ltd. Business Objects is an SAPcompany.Sybase and Adaptive Server, iAnywhere, Sybase 365, SQLAnywhere, and other Sybase products and services mentioned hereinas well as their respective logos are trademarks or registeredtrademarks of Sybase Inc. Sybase is an SAP company.Crossgate, m@gic EDDY, B2B 360 , and B2B 360 Services areregistered trademarks of Crossgate AG in Germany and othercountries. Crossgate is an SAP company.All other product and service names mentioned are the trademarks oftheir respective companies. Data contained in this document servesinformational purposes only. National product specifications may vary.These materials are subject to change without notice. These materialsare provided by SAP AG and its affiliated companies ("SAP Group")for informational purposes only, without representation or warranty ofany kind, and SAP Group shall not be liable for errors or omissionswith respect to the materials. The only warranties for SAP Groupproducts and services are those that are set forth in the expresswarranty statements accompanying such products and services, ifany. Nothing herein should be construed as constituting an additionalwarranty.
Developing Python application with Sybase ASEINTRODUCTIONASE Developer Edition as well as other editions come bundled with a client software development calledOpen Client Software Development kit or OCS in short) which contains database drivers and extensionmodule for different programming languagesSybase ASE supports Python by providing extension module- called sybpydb- which lets Python connect toSybase ASE database, Perform queries and retrieve results from database.This guide will teach how to setup Python environment to start developing applications which use SybaseASEASE CONFIGURATION STEPSFor simplicity, this tutorial assumes that Windows 7 is used for application development, and same machineis used for database installation as well as client application.Here is typical install file structure for Sybase ASE Developer Edition on Windows 7 box.C:\Sybase\C:\sybase\ase-15 0 corresponds to actual ASE database installationC:\Sybase\ocs-15 0 corresponds to bundled client software (called OCS in Sybase ASE parlance)development kit. It is interesting to note that that updates to OCS can be downloaded fromsoftware.sybase.com (or other release mechanism if support contract purchased) independent of updates toDatabase.Set following environment variables %SYBASE% to c:\syabse %SYBASE OCS% to %SYBASE%\ocs-15 0PYTHON REQUIREMENTSSybase ASE extension module sybpydb currently supports 2.6, 2.7 and 3.1. Make sure that 64 bit version oflanguage installed as Sybase supports only 64 bit platform for all OS. These python version are availablypublicly from internet.Extension module for 2.6, 2.7, or 3.1 will be located in corresponding %SYBASE OCS%\python directoryCheck version of Open Client SDK by %SYBASE OCS%\ bin\isql –v. It should be 15.7 or more.PlatformDefault Installation PathPython VersionWindows %SYBASE%\%SYBASE OCS%\python\python26 64\dll2.6Windows SYBASE%\%SYBASE OCS%\python\python27 64\dll2.7Windows SYBASE%\%SYBASE OCS%\python\python31 64\dll3.1All Other Platforms SYBASE/ SYBASE OCS/python/python26 64r/lib2.6,2.7All Other Platforms SYBASE/ SYBASE OCS/python/python31 64r/lib3.13
Developing Python application with Sybase ASETo use the Adaptive Server Enterprise extension module for Python in an application, there are two ways. Set PYTHONPATH,o In console window, set environment variable PYTHONPATH to Sybase ASE’s Python Extensiondll. For example, if your development environment is using Python 3.1 64 bit,PYTHONPATH would be set to %SYBASE OCS%\python\31 64\dll set PYTHONPATH c:\Sybase\OCS-15 0\python\python6 64\dll A simple Python program to verify if sybpydb is in pathimport sysfor d in sys.path:print(d); Set Python variable sys.path to one of the following directory paths in table above inside your Python code.Using Extension Module for PythonConnecting to ASE ServerUse the import statement to load the extension modulethe python script.sybpydbfor Python by including this line at the top ofimport sybpydbsybpydb connect method can take username, password and optional servername as parameter to connect toSybase ASE database. If servername is not specified, then it is read from DSQUERY environment variableatabase name can be specified either in# Create a connection conn sybpydb.connect(user 'john', password 'sybase') conn sybpydb.connect(user 'john', password 'sybase', servername ’localhost’)Note: If neither DSQUERY environment variable is set, nor servername is passed as parameter, then default“SYBASE” is selected.Detail Sybase Python API reference is available 2398.html4
Developing Python application with Sybase ASESample Python Program to query and display rows Open connection by calling sybpydb.connect method, save connection object After a connection is established, get cursor from connection object, to manage the context of a fetchoperation Execute native Sybase ASE SQL or call stored procedure using cursor object Fetch result row by calling cursor’s fetchall method Perform operations on result row Close cursor, and connection objectIt is possible to pass input and output parameters to stored procedure as well as perform aggregatecomputations on result rows retrieved.Here is complete end to end example:import sybpydb#Create a connection.conn sybpydb.connect(user 'sa',password ’abcdefgh’)# Create a cursor object.cur conn.cursor()cur.execute("drop table footab")cur.execute("create table footab ( id integer, first char(20) null, last char(50)null)")cur.execute("insert into footab values( ?, ?, ? )", (1, "John", "Doe"))cur.execute("select * from footab")rows cur.fetchall()for row in rows:print "-" * 55for col in range (len(row)):print "%s" % (row[col]),#Close the cursor objectcur.close()#Close the connectionconn.close()5
Developing Python application with Sybase ASESample Program to insert, update rowsRUN SAMPLE PROGRAMSSybase ASE comes bundled with Python sample program based on sample database “pubs3”- both sampleprogram and database is included with Developer Edition. Start Sybase ASE server by going to Control Panel Administrative Services- Start Sybase ASEService Set %SYBASE%, %SYBASE OCS%, %PYTHONPATH% environment variable as mentioned inconfiguration step above cd %SYBASE OCS%\ sample\python Test environment is correctly setup and ASE server is up and running by executing “python test.py”first.import sybpydbconn sybpydb.connect(user 'sa', password '')print("Successfully established connection, exiting.")conn.close() Other programs are self-explanatory.Output from starting Python Programcd %SYBASE OCS%\sample\pythonSYBASE SUPPORT FOR PYTHON ODBC DRIVERPyODBC is not officially developed by Sybase ASE but it is possible to access Sybase ASE databasethrough Sybase ODBC driver and PyODBC combination.pyodbc is a Python 2.x and 3.x module that allows you to use ODBC to connect to almost any database fromWindows, Linux, OS/X, and more.pyodbc is licensed using an MIT license, so it is free for commercial and personal usePyODBC can be downloaded from here http://code.google.com/p/pyodbc/ . PyODBC installation requiresright Python version to be installed already before installation of PyODBC can begin.6
Developing Python application with Sybase ASEPlatform specific download http://code.google.com/p/pyodbc/downloads/list . So far, Python 2.6 and Python2.7 are supported.Connection String for PyODBCThe most important thing to know is that pyodbc lets any generic ODBC connection string documentationshould be valid. And anything ODBC supports, pyodbc supports, including DSN-less connections andFILEDSNHere is sample DSN for Sybase ODBC Driver on Windows 7.Control Panel - Administrative Tools - DataSources (ODBC)Step 1.Step 2.Enter Servername, port , database etc. Password is not stored in DSN , required just for testing connectionto database.7
Developing Python application with Sybase ASE8
Developing Python application with Sybase ASEStep 3.9
Developing Python application with Sybase ASEUsing PyODBCAfter installing PyODBC module , import pyodbc module in your Python script , connect to Sybase ASEdatabase either through 1) DSN or 2) connection string.For this example, we will be using DSN “sybaseodbc” just created.Here is sample program using pyodbc to make connection to sample “pub3” database and display rows fromtable.Output from program.Row ModificationInsertIt will be something similar to:cursor.execute("insert into products(id, name) values ('pyodbc', 'awesome library')")cnxn.commit()Update and Deletecursor.execute("insert into products(id, name) values (?, ?)", 'pyodbc', 'awesome library')cnxn.commit()10
for Sybase ASE . Developer Edition on Windows 7 box. C: \ Sybase \ C:\ sybase \ase-15_0 corresponds to actual ASE database installation C:\ Sybase \ocs-15_0 corresponds to bundled client software (called OCS in Sybase ASE parlance) development kit. It is interestin
Difﬁculty in upgrading from Sybase 12.x to Sybase ASE 15 Many Sybase customers who have not yet upgraded to Sybase ASE 15 are considering migrating away from Sybase and toward Oracle. This is because the expense associated with a Sybase ASE 15 upgrade, in many cases, would cover
Audience This guide is for users of Sybase ETL Development. How to use this book This book contains these chapters: † Chapter 1, "Sybase ETL," is an overview of the Sybase ETL architecture and the feature set of Sybase ETL Development and Sybase ETL Server. † Chapter 2, "Getting Started," describes how to get started using Sybase ETL.
Understanding SYBASE Update Rules 16 Naming Conventions for SYBASE 16 Case Sensitivity in SYBASE 17 Data Types for SYBASE 17 Character Data 17 Numeric Data 18 Abstract Data 18 User-Deﬁned Data Types 19 . Sybase ASE Perfor
all" for the Sybase dataserver by connecting to isql session. Supported software for Sybase The Veritas agent for Sybase supports the following software versions: Sybase Sybase Adaptive Server Enterprise (ASE) 12.5.x and 15.x Veritas Cluster Server VCS 5.1 on Solaris SPARC: Sola
"active/passive" support. For "active/active" support for ASE Enterprise Edition, contact Sybase for their agent. Supported software for the VCS agent for Sybase The VCS for Sybase agent for Sybase supports the following software versions: Sybase Adaptive Server Enterprise (ASE) Enterprise Edition 1
data transformation process by using the unique Sybase ETL "Step and See" technology. How to use this book This book contains the following chapters: Chapter 1, "Sybase ETL" gives you a brief overview of Sybase ETL architecture and the feature set of Sybase ETL Development and Sybase ETL Server.
Python 2 versus Python 3 - the great debate Installing Python Setting up the Python interpreter About virtualenv Your first virtual environment Your friend, the console How you can run a Python program Running Python scripts Running the Python interactive shell Running Python as a service Running Python as a GUI application How is Python code .
Dictator Adolf Hitler was born in Branau am Inn, Austria, on April 20, 1889, and was the fourth of six children born to Alois Hitler and Klara Polzl. When Hitler was 3 years old, the family moved from Austria to Germany. As a child, Hitler clashed frequently with his father. Following the death of his younger brother, Edmund, in 1900, he became detached and introverted. His father did not .