From d9be1ec98e849e4a083bfcd5e7c7d00255cddd66 Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Wed, 12 Sep 2018 15:05:29 -0600 Subject: [PATCH] Updates for cx_Oracle 7 and Oracle Client 18.3 as well as some miscellaneous tweaks. --- ...le-Database-Scripting-for-the-Future.html} | 212 +++++++++--------- samples/tutorial/bind_sdo.py | 2 + samples/tutorial/connect.py | 2 +- samples/tutorial/drcp_query.sql | 2 +- samples/tutorial/query.py | 2 +- samples/tutorial/solutions/bind_sdo.py | 2 + samples/tutorial/solutions/connect_pool2.py | 3 +- samples/tutorial/solutions/query-2.py | 2 +- samples/tutorial/solutions/query.py | 2 +- samples/tutorial/solutions/query_scroll.py | 29 +++ samples/tutorial/solutions/versions.py | 2 +- samples/tutorial/versions.py | 2 +- 12 files changed, 149 insertions(+), 113 deletions(-) rename samples/tutorial/{Python-and-Oracle-Database-12c-Scripting-for-the-Future.html => Python-and-Oracle-Database-Scripting-for-the-Future.html} (92%) create mode 100644 samples/tutorial/solutions/query_scroll.py diff --git a/samples/tutorial/Python-and-Oracle-Database-12c-Scripting-for-the-Future.html b/samples/tutorial/Python-and-Oracle-Database-Scripting-for-the-Future.html similarity index 92% rename from samples/tutorial/Python-and-Oracle-Database-12c-Scripting-for-the-Future.html rename to samples/tutorial/Python-and-Oracle-Database-Scripting-for-the-Future.html index bbb7ae5..3ce2d3b 100644 --- a/samples/tutorial/Python-and-Oracle-Database-12c-Scripting-for-the-Future.html +++ b/samples/tutorial/Python-and-Oracle-Database-Scripting-for-the-Future.html @@ -1,7 +1,7 @@ -Python and Oracle Database 12c: Scripting for the Future +Python and Oracle Database: Scripting for the Future @@ -9,7 +9,7 @@ -

Python and Oracle Database 12c: Scripting for the Future

+

Python and Oracle Database: Scripting for the Future

Python cx_Oracle logo @@ -19,11 +19,11 @@
  • Preface
  • Connection Information
  • Overview
  • -
  • Using Python cx_Oracle 6 with Oracle Database 12c
  • +
  • Using Python cx_Oracle 7 with Oracle Database
  • +

    When you run scripts, Python automatically creates bytecode + versions of them in a folder called __pycache__. + These improve performance of scripts that are run multiple times. + They are automatically recreated if the source file changes.

    +

    Indentation

    Whitespace indentation is significant in Python. When copying @@ -2146,7 +2147,8 @@ print('Value:', count)

    Note the print syntax and output is different in Python - 2.

    + 2. Examples in this lab use from __future__ import print_function + so that they run with Python 2 and Python 3.

    Data Structures

    diff --git a/samples/tutorial/bind_sdo.py b/samples/tutorial/bind_sdo.py index ca9e767..edb358f 100644 --- a/samples/tutorial/bind_sdo.py +++ b/samples/tutorial/bind_sdo.py @@ -43,6 +43,8 @@ print("Adding row to table...") cur.execute("insert into testgeometry values (1, :obj)", obj = obj) print("Row added!") +# (Change below here) + # Query the row print("Querying row just inserted...") cur.execute("select id, geometry from testgeometry"); diff --git a/samples/tutorial/connect.py b/samples/tutorial/connect.py index 70a9346..627e643 100644 --- a/samples/tutorial/connect.py +++ b/samples/tutorial/connect.py @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------ -# connect.py (Section 1.1 and 1.2) +# connect.py (Section 1.2 and 1.3) #------------------------------------------------------------------------------ #------------------------------------------------------------------------------ diff --git a/samples/tutorial/drcp_query.sql b/samples/tutorial/drcp_query.sql index 7a642a0..1e497e4 100644 --- a/samples/tutorial/drcp_query.sql +++ b/samples/tutorial/drcp_query.sql @@ -1,5 +1,5 @@ ------------------------------------------------------------------------------- --- drcp_query.sql (Section 2.5) +-- drcp_query.sql (Section 2.4 and 2.5) ------------------------------------------------------------------------------- /*----------------------------------------------------------------------------- diff --git a/samples/tutorial/query.py b/samples/tutorial/query.py index 195b32f..fd16d5c 100644 --- a/samples/tutorial/query.py +++ b/samples/tutorial/query.py @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------ -# query.py (Section 1.3) +# query.py (Section 1.4 and 1.5) #------------------------------------------------------------------------------ #------------------------------------------------------------------------------ diff --git a/samples/tutorial/solutions/bind_sdo.py b/samples/tutorial/solutions/bind_sdo.py index ff65053..007fad7 100644 --- a/samples/tutorial/solutions/bind_sdo.py +++ b/samples/tutorial/solutions/bind_sdo.py @@ -50,6 +50,8 @@ print("Adding row to table...") cur.execute("insert into testgeometry values (1, :objbv)", objbv = obj) print("Row added!") +# (Change below here) + # Define a function to dump the contents of an Oracle object def dumpobject(obj, prefix = " "): if obj.type.iscollection: diff --git a/samples/tutorial/solutions/connect_pool2.py b/samples/tutorial/solutions/connect_pool2.py index a238ed3..cd977e5 100644 --- a/samples/tutorial/solutions/connect_pool2.py +++ b/samples/tutorial/solutions/connect_pool2.py @@ -14,7 +14,8 @@ import time import db_config pool = cx_Oracle.SessionPool(db_config.user, db_config.pw, db_config.dsn + ":pooled", - min = 2, max = 5, increment = 1, threaded = True) + min = 2, max = 5, increment = 1, threaded = True, + getmode = cx_Oracle.SPOOL_ATTRVAL_WAIT) def Query(): con = pool.acquire(cclass="PYTHONHOL", purity=cx_Oracle.ATTR_PURITY_SELF) diff --git a/samples/tutorial/solutions/query-2.py b/samples/tutorial/solutions/query-2.py index efa72d5..c7de475 100644 --- a/samples/tutorial/solutions/query-2.py +++ b/samples/tutorial/solutions/query-2.py @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------ -# query.py (Section 1.4) +# query.py (Section 1.5) #------------------------------------------------------------------------------ #------------------------------------------------------------------------------ diff --git a/samples/tutorial/solutions/query.py b/samples/tutorial/solutions/query.py index 0e4bde5..ca548bb 100644 --- a/samples/tutorial/solutions/query.py +++ b/samples/tutorial/solutions/query.py @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------ -# query.py (Section 1.3) +# query.py (Section 1.4 and 1.5) #------------------------------------------------------------------------------ #------------------------------------------------------------------------------ diff --git a/samples/tutorial/solutions/query_scroll.py b/samples/tutorial/solutions/query_scroll.py new file mode 100644 index 0000000..4c1a668 --- /dev/null +++ b/samples/tutorial/solutions/query_scroll.py @@ -0,0 +1,29 @@ +#------------------------------------------------------------------------------ +# query_scroll.py (Section 3.4) +#------------------------------------------------------------------------------ + +#------------------------------------------------------------------------------ +# Copyright 2017, 2018, Oracle and/or its affiliates. All rights reserved. +#------------------------------------------------------------------------------ + +from __future__ import print_function + +import cx_Oracle +import db_config + +con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn) +cur = con.cursor(scrollable = True) + +cur.execute("select * from dept order by deptno") + +cur.scroll(2, mode = "absolute") # go to second row +print(cur.fetchone()) + +cur.scroll(-1) # go back one row +print(cur.fetchone()) + +cur.scroll(1) # go to next row +print(cur.fetchone()) + +cur.scroll(mode = "first") # go to first row +print(cur.fetchone()) diff --git a/samples/tutorial/solutions/versions.py b/samples/tutorial/solutions/versions.py index efa90c3..cc683d4 100644 --- a/samples/tutorial/solutions/versions.py +++ b/samples/tutorial/solutions/versions.py @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------ -# versions.py (Section 1.5) +# versions.py (Section 1.6) #------------------------------------------------------------------------------ #------------------------------------------------------------------------------ diff --git a/samples/tutorial/versions.py b/samples/tutorial/versions.py index b2e776a..7bbafc8 100644 --- a/samples/tutorial/versions.py +++ b/samples/tutorial/versions.py @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------ -# versions.py (Section 1.5) +# versions.py (Section 1.6) #------------------------------------------------------------------------------ #------------------------------------------------------------------------------