Download Python For Oracle Geeks

Document related concepts

Microsoft SQL Server wikipedia , lookup

SQL wikipedia , lookup

IMDb wikipedia , lookup

Open Database Connectivity wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Database wikipedia , lookup

Concurrency control wikipedia , lookup

Relational model wikipedia , lookup

Database model wikipedia , lookup

PL/SQL wikipedia , lookup

Clusterpoint wikipedia , lookup

Oracle Database wikipedia , lookup

ContactPoint wikipedia , lookup

Transcript
Python for Oracle Geeks
or,
“Just a wafer-thin slice of Python”
or,
“Python as a Second Language (PSL)”
Catherine Devlin
IntelliTech Systems
Outline
Brainwashing
●
Getting started
●
Working with files
●
Querying Oracle
●
Building Web application
●
Me
S. B. (sic) in Chemical Engineering
Oracle DBA since1999
Pythonista since 2003
[email protected]
http://catherinedevlin.blogspot.com/
IntelliTech Systems
Fairborn, OH
http://www.itsysteminc.com/
“I work in the database.”
Is that really all you do?
From Oracle® Database Administrator's Guide 10g Release 2 (10.2):
Tasks of a Database Administrator
Task 1: Evaluate the Database Server Hardware
Task 2: Install the Oracle Database Software
Task 3: Plan the Database
Task 4: Create and Open the Database
Task 5: Back Up the Database
Task 6: Enroll System Users
Task 7: Implement the Database Design
Task 8: Back Up the Fully Functional Database
Task 9: Tune Database Performance
Task 10: Download and Install Patches
Task 11: Roll Out to Additional Hosts
Sometimes SQL and PL/SQL
aren't enough
Data files on filesystem
●Batch files and executables
●System resources (memory, CPU)
●Internet
●Object-oriented programming
●Complex text parsing
●
Dear Santa,
I have been a very good
DBA. For Christmas, I want a
language that is...
Easy to learn and use
●Easy to read and maintain
●Powerful and versatile
●Free of cost!
●
Consider a dynamic language
(Perl, PHP, Ruby...)
Easy to learn and use
Easy to read and maintain
Very readable - “executable
pseudocode”
Unit testing
Powerful and versatile
Exception handling, XML
Web publishing, Web browsing,
Web services, GUI development...
Free of cost!
Let's write something!
Compare init.ora file to parameters in
database
db_block_size=8192 -OKcompatible=10.2.0.10 (live) 9.2.0.1 (file)
cursor_sharing=EXACT -OKWeb application
www.python.
org
DEMO
Pitfalls for the Oracle-minded
1. Everything is case-sensitive
object-orientation
Pitfalls for the Oracle-minded
1. Everything is case-sensitive
2. When calling a function, () is not
optional
What we want is a table
Param (PK)
Value
log_archive_start
db_block_size
TRUE
8192
In Python, it's called a 'dictionary'
and indicated by {}
fileParams = {
'log_archive_start':
True,
'db_block_size': 8192
}
STOP IT!
Write a script already!
Pitfalls for the Oracle-minded
1. Everything is case-sensitive
2. When calling a function, () is not
optional
3. No knee-jerk indenting!
Are you confused about where the “for”
block begins and ends? Even though there
is no END LOOP?
Are you confused about where each
command ends? Even though there are no
semicolons?
Python reads your code the same way your
eye does!
Python core
You have access without doing
anything
Standard library
You must 'import' into a script or
session
External modules
You must go get and install the code
then import
1. Choose a web application platform
Albatross, Aquarium, CherryPy,
Cymbeline, Django, Draco,
Impostor, JOTWeb, Karrigell,
mod_python, Nevow, Paste,
Python Servlet Engine, PyWork,
QLime, Quixote, SkunkWeb,
Snakelets, SnakeSkin, Subway,
Twisted, TurboGears, WareWeb,
WebWare, Zope
1. Choose a web application platform
CherryPy – my favorite
TurboGears – compare to Ruby on Rails
(no Oracle support, yet)
Zope – most popular; Web
administration
Plone – content management
2. Download and install
3. Read the CherryPy tutorial
Pitfalls for the Oracle-minded
1. Everything is case-sensitive
2. When calling a function, () is not
optional
3. No knee-jerk indenting!
4. CherryPy tutorial is one version
obsolete
Bind variables in cx_Oracle
Use a :colon in the SQL string,
then send a dictionary as second
argument
cursor.execute(
“””SELECT hiredate FROM emp
WHERE ename = :empName”””,
{'empName':'SCOTT'})
What's next?
www.python.org
Documentation > Tutorial
Object-orientation
Convenience wrapper: sqlWrap.py
Object-relational mapping (a la Oracle
TopLink)
Exception handling, unit testing, ...
References
www.python.org
> Topic Guides > Databases
http://www.computronix.com/utilities.sh
tml
http://www.amk.ca/python/writing/DBAPI.html
http://www.ioug.org/Python.pdf
http://catherinedevlin.blogspot.com