From bae5cbe76a58758543cb1199b36ae7c557004dfd Mon Sep 17 00:00:00 2001
From: Blaine Carter
-
To set up a similar environment yourself, install:
+To set up a similar environment yourself, install the following required software:
-It is easist to have a local pluggable database with the service - 'orclpdb' configured. If your database is not local, or has a - different service, you will need to modify the connect string in all - samples.
- -To create the schema run:
+To create the schema run:
sqlplus sys/yoursyspassword@localhost/orclpdb as sysdba @sql/SetupSamples+
The database connection information is set in two files: +
The username is "pythonhol" with
+ the password "welcome". The connect string is "localhost/orclpdb".
+ See sql/SampleEnv.sql.
It is easist to have a local pluggable database with the service + 'orclpdb' configured. If your database is not local, or has a + different service, you will need to modify the connection information in db_config.py and db_config.sql.
+The following sections may need adjusting, depending on how you have set up your environment.
@@ -138,10 +158,6 @@ sqlplus sys/yoursyspassword@localhost/orclpdb as sysdba @sql/SetupSamplesUse the Desktop icons to start editors and terminal windows.
- A pre-created schema exists. The username is "pythonhol" with
- the password "welcome". The connect string is "localhost/orclpdb".
- See sql/SampleEnv.sql.
If you are new to Python review the Appendix: Python Primer to gain an understanding of the language.
@@ -156,11 +172,32 @@ sqlplus sys/yoursyspassword@localhost/orclpdb as sysdba @sql/SetupSamplesReview the code contained in db_config.py and db_config.sql:
db_config.py
+ +user = "pythonhol" +pw = "welcome" +dsn = "localhost/orclpdb" ++
db_config.sql
+ +def user = "pythonhol" +def pw = "welcome" +def connect_string = "localhost/orclpdb" ++
Modify the values in both files to match the connection information for your environment.
+ +Review the code contained in connect.py:
import cx_Oracle
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+import db_config
+
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
print("Database version:", con.version)
@@ -168,9 +205,9 @@ print("Database version:", con.version)
accessing the Oracle database. Many inbuilt and third party
modules can be included in this way in Python scripts.
- The connect() method is passed the username
- "pythonhol", the password "welcome" and the connection
- string. In this case, Oracle's Easy Connect connection
+
The connect() method is passed the username,
+ the password and the connection string that you configured in
+ the db_config.py module. In this case, Oracle's Easy Connect connection
string syntax is used. It consists of the hostname of your
machine, localhost, and the database service name
orclpdb.
There are no statement terminators or begin/end keywords or braces to indicate blocks of code.
@@ -202,7 +239,9 @@ print("Database version:", con.version)
import cx_Oracle
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+import db_config
+
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
print("Database version:", con.version)
@@ -224,20 +263,24 @@ con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
Open query.py in an editor. It looks like:
import cx_Oracle
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+import db_config
+
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
Edit the file and add the code shown in bold below:
import cx_Oracle
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+import db_config
+
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
cur.execute("select * from dept order by deptno")
@@ -261,7 +304,7 @@ for row in res:
Connections and other resources used by cx_Oracle will automatically be closed at the end of scope. This is a common @@ -275,7 +318,9 @@ for row in res:
import cx_Oracle
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+import db_config
+
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
cur.execute("select * from dept order by deptno")
@@ -290,13 +335,17 @@ for row in res:
python query.py
- This gives the error "cx_Oracle.DatabaseError: DPI-1054: connection cannot be closed when open statements or LOBs exist".
+ If you are using cx_Oracle 6.2+ the connection will close and you can skip ahead to section 1.6.
+
+ If you are using an older version of cx_Oracle, this gives the error "cx_Oracle.DatabaseError: DPI-1054: connection cannot be closed when open statements or LOBs exist".
To fix this, edit the file and close the cursor:
import cx_Oracle
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+import db_config
+
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
cur.execute("select * from dept order by deptno")
@@ -317,13 +366,15 @@ con.close()
Review the code contained in versions.py:
import cx_Oracle
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+import db_config
+
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
print(cx_Oracle.version)
@@ -337,7 +388,9 @@ print(cx_Oracle.version)
import cx_Oracle
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+import db_config
+
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
print(cx_Oracle.version)
print("Database version:", con.version)
@@ -373,8 +426,9 @@ Client version: (12, 2, 0, 1, 0)
import cx_Oracle
import threading
+import db_config
-pool = cx_Oracle.SessionPool("pythonhol", "welcome", "localhost/orclpdb",
+pool = cx_Oracle.SessionPool(db_config.user, db_config.pw, db_config.dsn,
min = 2, max = 5, increment = 1, threaded = True)
def Query():
@@ -398,7 +452,7 @@ print("All done!")
The SessionPool() function creates a pool of
- Oracle "sessions" for the "pythonhol" user. Sessions in the pool
+ Oracle "sessions" for the user. Sessions in the pool
can be used by cx_Oracle connections by calling
pool.acquire(). The initial pool size is 2 sessions.
The maximum size is 5 sessions. When the pool needs to grow, 1 new
@@ -445,8 +499,9 @@ of threads:
import cx_Oracle
import threading
+import db_config
-pool = cx_Oracle.SessionPool("pythonhol", "welcome", "localhost/orclpdb",
+pool = cx_Oracle.SessionPool(db_config.user, db_config.pw, db_config.dsn,
min = 2, max = 5, increment = 1, threaded = True)
def Query():
@@ -533,7 +588,9 @@ is available.
import cx_Oracle
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb:pooled",
+import db_config
+
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn + ":pooled",
cclass="PYTHONHOL", purity=cx_Oracle.ATTR_PURITY_SELF)
print("Database version:", con.version)
@@ -575,7 +632,7 @@ print("Database version:", con.version)
import cx_Oracle
import threading
-pool = cx_Oracle.SessionPool("pythonhol", "welcome", "localhost/orclpdb:pooled",
+pool = cx_Oracle.SessionPool(db_config.user, db_config.pw, db_config.dsn + ":pooled",
min = 2, max = 5, increment = 1, threaded = True)
def Query():
@@ -658,7 +715,9 @@ import time
import cx_Oracle
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+import db_config
+
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
cur.execute("select * from dept order by deptno")
@@ -691,8 +750,9 @@ for deptno, dname, loc in cur:
import cx_Oracle
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
cur.execute("select * from dept order by deptno")
@@ -720,8 +780,9 @@ print(row)
import cx_Oracle
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
cur.execute("select * from dept order by deptno")
@@ -761,8 +822,9 @@ print(res)
import cx_Oracle
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+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")
@@ -826,8 +888,9 @@ commit;
import cx_Oracle
import time
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
start = time.time()
@@ -898,8 +961,9 @@ print(elapsed, "seconds")
import cx_Oracle
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
cur.prepare("select * from dept where deptno = :id order by deptno")
@@ -952,8 +1016,9 @@ create table mytab (id number, data varchar2(20), constraint my_pk primary key (
import cx_Oracle
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
rows = [ (1, "First" ), (2, "Second" ),
@@ -1018,8 +1083,9 @@ rows = [ (1, "First" ), (2, "Second" ),
import cx_Oracle
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
rows = [ (1, "First" ), (2, "Second" ),
@@ -1067,6 +1133,7 @@ print(res)
Spatial Data Objects (SDO).
In a terminal window, start SQL*Plus:
+ (Modify the following command to use your connection values.)
sqlplus pythonhol/welcome@localhost/orclpdb
@@ -1094,8 +1161,9 @@ desc MDSYS.SDO_GEOMETRY
import cx_Oracle
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
# Create table
@@ -1257,8 +1325,9 @@ create or replace function myfunc(d_p in varchar2, i_p in number) return number
import cx_Oracle
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
res = cur.callfunc('myfunc', int, ('abc', 2))
@@ -1302,8 +1371,9 @@ end;
import cx_Oracle
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
myvar = cur.var(int)
@@ -1350,8 +1420,9 @@ print(myvar.getvalue())
import cx_Oracle
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
print("Standard output...")
@@ -1407,8 +1478,9 @@ for row in cur.execute("select * from dept"):
import cx_Oracle
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
for value, in cur.execute("select 0.1 from dual"):
@@ -1429,8 +1501,9 @@ for value, in cur.execute("select 0.1 from dual"):
import cx_Oracle
import decimal
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
def ReturnNumbersAsDecimal(cursor, name, defaultType, size, precision, scale):
@@ -1481,8 +1554,9 @@ def ReturnNumbersAsDecimal(cursor, name, defaultType, size, precision, scale):
import cx_Oracle
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
# Create table
@@ -1600,8 +1674,9 @@ an Oracle object from the Python object values. The
import cx_Oracle
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
print("Inserting data...")
@@ -1648,8 +1723,9 @@ print("CLOB data:", clobdata)
import cx_Oracle
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
print("Inserting data...")
@@ -1704,8 +1780,9 @@ print("CLOB data:", clobdata)
import collections
import cx_Oracle
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
cur.execute("select deptno, dname from dept")
@@ -1777,12 +1854,13 @@ for row in rows:
import cx_Oracle
+import db_config
class MyConnection(cx_Oracle.Connection):
def __init__(self):
print("Connecting to database")
- return super(MyConnection, self).__init__("pythonhol", "welcome", "localhost/orclpdb")
+ return super(MyConnection, self).__init__(db_config.user, db_config.pw, db_config.dsn)
con = MyConnection()
cur = con.cursor()
@@ -1821,12 +1899,13 @@ print("Number of rows:", count)
import cx_Oracle
+import db_config
class MyConnection(cx_Oracle.Connection):
def __init__(self):
print("Connecting to database")
- return super(MyConnection, self).__init__("pythonhol", "welcome", "localhost/orclpdb")
+ return super(MyConnection, self).__init__(db_config.user, db_config.pw, db_config.dsn)
def cursor(self):
return MyCursor(self)
@@ -1879,8 +1958,9 @@ invoke the parent methods to do the actual statement execution.
import cx_Oracle
import decimal
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
BOOK_TYPE_NAME = "UDT_BOOK"
diff --git a/samples/tutorial/aq.py b/samples/tutorial/aq.py
index bcfb51f..a7a9564 100644
--- a/samples/tutorial/aq.py
+++ b/samples/tutorial/aq.py
@@ -10,8 +10,9 @@ from __future__ import print_function
import cx_Oracle
import decimal
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
BOOK_TYPE_NAME = "UDT_BOOK"
diff --git a/samples/tutorial/bind_insert.py b/samples/tutorial/bind_insert.py
index bbda40a..eb10195 100644
--- a/samples/tutorial/bind_insert.py
+++ b/samples/tutorial/bind_insert.py
@@ -9,8 +9,9 @@
from __future__ import print_function
import cx_Oracle
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
rows = [ (1, "First" ), (2, "Second" ),
diff --git a/samples/tutorial/bind_insert.sql b/samples/tutorial/bind_insert.sql
index 1b90835..068e088 100644
--- a/samples/tutorial/bind_insert.sql
+++ b/samples/tutorial/bind_insert.sql
@@ -8,9 +8,18 @@
set echo on
-connect pythonhol/welcome@localhost/orclpdb
+@@db_config.sql
+connect &user/&pw@&connect_string
-drop table mytab;
+begin
+ execute immediate 'drop table mytab';
+exception
+when others then
+ if sqlcode not in (-00942) then
+ raise;
+ end if;
+end;
+/
create table mytab (id number, data varchar2(20), constraint my_pk primary key (id));
diff --git a/samples/tutorial/bind_query.py b/samples/tutorial/bind_query.py
index 2b23c22..8ab8540 100644
--- a/samples/tutorial/bind_query.py
+++ b/samples/tutorial/bind_query.py
@@ -9,8 +9,9 @@
from __future__ import print_function
import cx_Oracle
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
cur.prepare("select * from dept where deptno = :id order by deptno")
diff --git a/samples/tutorial/bind_sdo.py b/samples/tutorial/bind_sdo.py
index 96dde29..164ca7c 100644
--- a/samples/tutorial/bind_sdo.py
+++ b/samples/tutorial/bind_sdo.py
@@ -9,8 +9,9 @@
from __future__ import print_function
import cx_Oracle
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+import db_config
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
# Create table
diff --git a/samples/tutorial/clob.py b/samples/tutorial/clob.py
index 8386e6e..d7f3d38 100644
--- a/samples/tutorial/clob.py
+++ b/samples/tutorial/clob.py
@@ -9,8 +9,9 @@
from __future__ import print_function
import cx_Oracle
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
print("Inserting data...")
diff --git a/samples/tutorial/clob_string.py b/samples/tutorial/clob_string.py
index 3e64db8..65eeb9b 100644
--- a/samples/tutorial/clob_string.py
+++ b/samples/tutorial/clob_string.py
@@ -9,8 +9,9 @@
from __future__ import print_function
import cx_Oracle
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
print("Inserting data...")
diff --git a/samples/tutorial/connect.py b/samples/tutorial/connect.py
index 36e7a0a..5686611 100644
--- a/samples/tutorial/connect.py
+++ b/samples/tutorial/connect.py
@@ -9,6 +9,7 @@
from __future__ import print_function
import cx_Oracle
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
print("Database version:", con.version)
diff --git a/samples/tutorial/connect_drcp.py b/samples/tutorial/connect_drcp.py
index e6e4511..335748a 100644
--- a/samples/tutorial/connect_drcp.py
+++ b/samples/tutorial/connect_drcp.py
@@ -9,7 +9,8 @@
from __future__ import print_function
import cx_Oracle
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb:pooled",
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn + ":pooled",
cclass="PYTHONHOL", purity=cx_Oracle.ATTR_PURITY_SELF)
print("Database version:", con.version)
diff --git a/samples/tutorial/connect_pool.py b/samples/tutorial/connect_pool.py
index 474d8fd..b4c5bc3 100644
--- a/samples/tutorial/connect_pool.py
+++ b/samples/tutorial/connect_pool.py
@@ -10,8 +10,9 @@ from __future__ import print_function
import cx_Oracle
import threading
+import db_config
-pool = cx_Oracle.SessionPool("pythonhol", "welcome", "localhost/orclpdb",
+pool = cx_Oracle.SessionPool(db_config.user, db_config.pw, db_config.dsn,
min = 2, max = 5, increment = 1, threaded = True)
def Query():
diff --git a/samples/tutorial/connect_pool2.py b/samples/tutorial/connect_pool2.py
index 12dd5c1..8abddbf 100644
--- a/samples/tutorial/connect_pool2.py
+++ b/samples/tutorial/connect_pool2.py
@@ -10,8 +10,9 @@ from __future__ import print_function
import cx_Oracle
import threading
+import db_config
-pool = cx_Oracle.SessionPool("pythonhol", "welcome", "localhost/orclpdb",
+pool = cx_Oracle.SessionPool(db_config.user, db_config.pw, db_config.dsn,
min = 2, max = 5, increment = 1, threaded = True)
def Query():
diff --git a/samples/tutorial/db_config.py b/samples/tutorial/db_config.py
new file mode 100644
index 0000000..8e78567
--- /dev/null
+++ b/samples/tutorial/db_config.py
@@ -0,0 +1,3 @@
+user = "pythonhol"
+pw = "welcome"
+dsn = "localhost/orclpdb"
diff --git a/samples/tutorial/db_config.sql b/samples/tutorial/db_config.sql
new file mode 100644
index 0000000..0f02b1b
--- /dev/null
+++ b/samples/tutorial/db_config.sql
@@ -0,0 +1,3 @@
+def user = "pythonhol"
+def pw = "welcome"
+def connect_string = "localhost/orclpdb"
diff --git a/samples/tutorial/plsql_func.py b/samples/tutorial/plsql_func.py
index b8173ea..12dd065 100644
--- a/samples/tutorial/plsql_func.py
+++ b/samples/tutorial/plsql_func.py
@@ -9,8 +9,9 @@
from __future__ import print_function
import cx_Oracle
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
res = cur.callfunc('myfunc', int, ('abc', 2))
diff --git a/samples/tutorial/plsql_func.sql b/samples/tutorial/plsql_func.sql
index 69f653a..1c5c24f 100644
--- a/samples/tutorial/plsql_func.sql
+++ b/samples/tutorial/plsql_func.sql
@@ -8,7 +8,18 @@
set echo on
-connect pythonhol/welcome@localhost/orclpdb
+@@db_config.sql
+connect &user/&pw@&connect_string
+
+begin
+ execute immediate 'drop table ptab';
+exception
+when others then
+ if sqlcode not in (-00942) then
+ raise;
+ end if;
+end;
+/
create table ptab (mydata varchar(20), myid number);
diff --git a/samples/tutorial/plsql_proc.py b/samples/tutorial/plsql_proc.py
index a378fca..58c3a36 100644
--- a/samples/tutorial/plsql_proc.py
+++ b/samples/tutorial/plsql_proc.py
@@ -9,8 +9,9 @@
from __future__ import print_function
import cx_Oracle
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
myvar = cur.var(int)
diff --git a/samples/tutorial/plsql_proc.sql b/samples/tutorial/plsql_proc.sql
index ff6da9d..34b19cf 100644
--- a/samples/tutorial/plsql_proc.sql
+++ b/samples/tutorial/plsql_proc.sql
@@ -8,7 +8,8 @@
set echo on
-connect pythonhol/welcome@localhost/orclpdb
+@@db_config.sql
+connect &user/&pw@&connect_string
create or replace procedure myproc(v1_p in number, v2_p out number) as
begin
diff --git a/samples/tutorial/query.py b/samples/tutorial/query.py
index ce6eb0f..344c2da 100644
--- a/samples/tutorial/query.py
+++ b/samples/tutorial/query.py
@@ -9,5 +9,6 @@
from __future__ import print_function
import cx_Oracle
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
diff --git a/samples/tutorial/query2.py b/samples/tutorial/query2.py
index c74bfa5..60695d9 100644
--- a/samples/tutorial/query2.py
+++ b/samples/tutorial/query2.py
@@ -9,8 +9,9 @@
from __future__ import print_function
import cx_Oracle
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
cur.execute('select * from dept order by deptno')
diff --git a/samples/tutorial/query_arraysize.py b/samples/tutorial/query_arraysize.py
index 9a36ba0..c8ff24b 100644
--- a/samples/tutorial/query_arraysize.py
+++ b/samples/tutorial/query_arraysize.py
@@ -10,8 +10,9 @@ from __future__ import print_function
import cx_Oracle
import time
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
start = time.time()
diff --git a/samples/tutorial/query_arraysize.sql b/samples/tutorial/query_arraysize.sql
index da64a53..b470214 100644
--- a/samples/tutorial/query_arraysize.sql
+++ b/samples/tutorial/query_arraysize.sql
@@ -8,9 +8,18 @@
set echo on
-connect pythonhol/welcome@localhost/orclpdb
+@@db_config.sql
+connect &user/&pw@&connect_string
-drop table bigtab;
+begin
+ execute immediate 'drop table bigtab';
+exception
+when others then
+ if sqlcode not in (-00942) then
+ raise;
+ end if;
+end;
+/
create table bigtab (mycol varchar2(20));
begin
diff --git a/samples/tutorial/query_many.py b/samples/tutorial/query_many.py
index e842e85..beb0b09 100644
--- a/samples/tutorial/query_many.py
+++ b/samples/tutorial/query_many.py
@@ -9,8 +9,9 @@
from __future__ import print_function
import cx_Oracle
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
cur.execute("select * from dept order by deptno")
diff --git a/samples/tutorial/query_one.py b/samples/tutorial/query_one.py
index 094c773..978fbaf 100644
--- a/samples/tutorial/query_one.py
+++ b/samples/tutorial/query_one.py
@@ -9,8 +9,9 @@
from __future__ import print_function
import cx_Oracle
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
cur.execute("select * from dept order by deptno")
diff --git a/samples/tutorial/query_scroll.py b/samples/tutorial/query_scroll.py
index d304e55..b0630f9 100644
--- a/samples/tutorial/query_scroll.py
+++ b/samples/tutorial/query_scroll.py
@@ -9,8 +9,9 @@
from __future__ import print_function
import cx_Oracle
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+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")
diff --git a/samples/tutorial/rowfactory.py b/samples/tutorial/rowfactory.py
index d7e0e17..9dad94d 100644
--- a/samples/tutorial/rowfactory.py
+++ b/samples/tutorial/rowfactory.py
@@ -10,8 +10,9 @@ from __future__ import print_function
import collections
import cx_Oracle
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
cur.execute("select deptno, dname from dept")
diff --git a/samples/tutorial/subclass.py b/samples/tutorial/subclass.py
index e429c7f..22cd976 100644
--- a/samples/tutorial/subclass.py
+++ b/samples/tutorial/subclass.py
@@ -9,12 +9,13 @@
from __future__ import print_function
import cx_Oracle
+import db_config
class MyConnection(cx_Oracle.Connection):
def __init__(self):
print("Connecting to database")
- return super(MyConnection, self).__init__("pythonhol", "welcome", "localhost/orclpdb")
+ return super(MyConnection, self).__init__(db_config.user, db_config.pw, db_config.dsn)
con = MyConnection()
cur = con.cursor()
diff --git a/samples/tutorial/type_converter.py b/samples/tutorial/type_converter.py
index b928666..db0d3b6 100644
--- a/samples/tutorial/type_converter.py
+++ b/samples/tutorial/type_converter.py
@@ -9,8 +9,9 @@
from __future__ import print_function
import cx_Oracle
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
for value, in cur.execute("select 0.1 from dual"):
diff --git a/samples/tutorial/type_input.py b/samples/tutorial/type_input.py
index e22ed81..a3731e1 100644
--- a/samples/tutorial/type_input.py
+++ b/samples/tutorial/type_input.py
@@ -9,8 +9,9 @@
from __future__ import print_function
import cx_Oracle
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
# Create table
diff --git a/samples/tutorial/type_output.py b/samples/tutorial/type_output.py
index b7b5cc6..9e4e2e6 100644
--- a/samples/tutorial/type_output.py
+++ b/samples/tutorial/type_output.py
@@ -9,8 +9,9 @@
from __future__ import print_function
import cx_Oracle
+import db_config
-con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
cur = con.cursor()
print("Standard output...")
diff --git a/samples/tutorial/versions.py b/samples/tutorial/versions.py
index 599d8de..f8344c2 100644
--- a/samples/tutorial/versions.py
+++ b/samples/tutorial/versions.py
@@ -9,7 +9,8 @@
from __future__ import print_function
import cx_Oracle
+import db_config
-con = cx_Oracle.connect('pythonhol/welcome@localhost/orclpdb')
+con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
print(cx_Oracle.version)