Skip to content

Commit bae5cbe

Browse files
OsBlaineOraanthony-tuininga
authored andcommitted
Modified the HoL for Collaborate (#169)
Modified samples and instructions to import common connection information from db_config.py or db_config.sql in order to make setup a bit more generic.
1 parent 4d37c85 commit bae5cbe

31 files changed

+234
-94
lines changed

samples/tutorial/Python-and-Oracle-Database-12c-Scripting-for-the-Future.html

Lines changed: 144 additions & 64 deletions
Large diffs are not rendered by default.

samples/tutorial/aq.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010

1111
import cx_Oracle
1212
import decimal
13+
import db_config
1314

14-
con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
15+
con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
1516
cur = con.cursor()
1617

1718
BOOK_TYPE_NAME = "UDT_BOOK"

samples/tutorial/bind_insert.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
from __future__ import print_function
1010

1111
import cx_Oracle
12+
import db_config
1213

13-
con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
14+
con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
1415
cur = con.cursor()
1516

1617
rows = [ (1, "First" ), (2, "Second" ),

samples/tutorial/bind_insert.sql

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,18 @@
88

99
set echo on
1010

11-
connect pythonhol/welcome@localhost/orclpdb
11+
@@db_config.sql
12+
connect &user/&pw@&connect_string
1213

13-
drop table mytab;
14+
begin
15+
execute immediate 'drop table mytab';
16+
exception
17+
when others then
18+
if sqlcode not in (-00942) then
19+
raise;
20+
end if;
21+
end;
22+
/
1423

1524
create table mytab (id number, data varchar2(20), constraint my_pk primary key (id));
1625

samples/tutorial/bind_query.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
from __future__ import print_function
1010

1111
import cx_Oracle
12+
import db_config
1213

13-
con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
14+
con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
1415
cur = con.cursor()
1516

1617
cur.prepare("select * from dept where deptno = :id order by deptno")

samples/tutorial/bind_sdo.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
from __future__ import print_function
1010

1111
import cx_Oracle
12-
con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
12+
import db_config
1313

14+
con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
1415
cur = con.cursor()
1516

1617
# Create table

samples/tutorial/clob.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
from __future__ import print_function
1010

1111
import cx_Oracle
12+
import db_config
1213

13-
con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
14+
con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
1415
cur = con.cursor()
1516

1617
print("Inserting data...")

samples/tutorial/clob_string.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
from __future__ import print_function
1010

1111
import cx_Oracle
12+
import db_config
1213

13-
con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
14+
con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
1415
cur = con.cursor()
1516

1617
print("Inserting data...")

samples/tutorial/connect.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from __future__ import print_function
1010

1111
import cx_Oracle
12+
import db_config
1213

13-
con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
14+
con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
1415
print("Database version:", con.version)

samples/tutorial/connect_drcp.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
from __future__ import print_function
1010

1111
import cx_Oracle
12+
import db_config
1213

13-
con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb:pooled",
14+
con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn + ":pooled",
1415
cclass="PYTHONHOL", purity=cx_Oracle.ATTR_PURITY_SELF)
1516
print("Database version:", con.version)

samples/tutorial/connect_pool.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010

1111
import cx_Oracle
1212
import threading
13+
import db_config
1314

14-
pool = cx_Oracle.SessionPool("pythonhol", "welcome", "localhost/orclpdb",
15+
pool = cx_Oracle.SessionPool(db_config.user, db_config.pw, db_config.dsn,
1516
min = 2, max = 5, increment = 1, threaded = True)
1617

1718
def Query():

samples/tutorial/connect_pool2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010

1111
import cx_Oracle
1212
import threading
13+
import db_config
1314

14-
pool = cx_Oracle.SessionPool("pythonhol", "welcome", "localhost/orclpdb",
15+
pool = cx_Oracle.SessionPool(db_config.user, db_config.pw, db_config.dsn,
1516
min = 2, max = 5, increment = 1, threaded = True)
1617

1718
def Query():

samples/tutorial/db_config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
user = "pythonhol"
2+
pw = "welcome"
3+
dsn = "localhost/orclpdb"

samples/tutorial/db_config.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def user = "pythonhol"
2+
def pw = "welcome"
3+
def connect_string = "localhost/orclpdb"

samples/tutorial/plsql_func.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
from __future__ import print_function
1010

1111
import cx_Oracle
12+
import db_config
1213

13-
con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
14+
con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
1415
cur = con.cursor()
1516

1617
res = cur.callfunc('myfunc', int, ('abc', 2))

samples/tutorial/plsql_func.sql

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,18 @@
88

99
set echo on
1010

11-
connect pythonhol/welcome@localhost/orclpdb
11+
@@db_config.sql
12+
connect &user/&pw@&connect_string
13+
14+
begin
15+
execute immediate 'drop table ptab';
16+
exception
17+
when others then
18+
if sqlcode not in (-00942) then
19+
raise;
20+
end if;
21+
end;
22+
/
1223

1324
create table ptab (mydata varchar(20), myid number);
1425

samples/tutorial/plsql_proc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
from __future__ import print_function
1010

1111
import cx_Oracle
12+
import db_config
1213

13-
con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
14+
con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
1415
cur = con.cursor()
1516

1617
myvar = cur.var(int)

samples/tutorial/plsql_proc.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
set echo on
1010

11-
connect pythonhol/welcome@localhost/orclpdb
11+
@@db_config.sql
12+
connect &user/&pw@&connect_string
1213

1314
create or replace procedure myproc(v1_p in number, v2_p out number) as
1415
begin

samples/tutorial/query.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
from __future__ import print_function
1010

1111
import cx_Oracle
12+
import db_config
1213

13-
con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
14+
con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)

samples/tutorial/query2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
from __future__ import print_function
1010

1111
import cx_Oracle
12+
import db_config
1213

13-
con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
14+
con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
1415

1516
cur = con.cursor()
1617
cur.execute('select * from dept order by deptno')

samples/tutorial/query_arraysize.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010

1111
import cx_Oracle
1212
import time
13+
import db_config
1314

14-
con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
15+
con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
1516

1617
start = time.time()
1718

samples/tutorial/query_arraysize.sql

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,18 @@
88

99
set echo on
1010

11-
connect pythonhol/welcome@localhost/orclpdb
11+
@@db_config.sql
12+
connect &user/&pw@&connect_string
1213

13-
drop table bigtab;
14+
begin
15+
execute immediate 'drop table bigtab';
16+
exception
17+
when others then
18+
if sqlcode not in (-00942) then
19+
raise;
20+
end if;
21+
end;
22+
/
1423

1524
create table bigtab (mycol varchar2(20));
1625
begin

samples/tutorial/query_many.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
from __future__ import print_function
1010

1111
import cx_Oracle
12+
import db_config
1213

13-
con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
14+
con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
1415
cur = con.cursor()
1516

1617
cur.execute("select * from dept order by deptno")

samples/tutorial/query_one.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
from __future__ import print_function
1010

1111
import cx_Oracle
12+
import db_config
1213

13-
con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
14+
con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
1415
cur = con.cursor()
1516

1617
cur.execute("select * from dept order by deptno")

samples/tutorial/query_scroll.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
from __future__ import print_function
1010

1111
import cx_Oracle
12+
import db_config
1213

13-
con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
14+
con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
1415
cur = con.cursor(scrollable = True)
1516

1617
cur.execute("select * from dept order by deptno")

samples/tutorial/rowfactory.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010

1111
import collections
1212
import cx_Oracle
13+
import db_config
1314

14-
con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
15+
con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
1516
cur = con.cursor()
1617

1718
cur.execute("select deptno, dname from dept")

samples/tutorial/subclass.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
from __future__ import print_function
1010

1111
import cx_Oracle
12+
import db_config
1213

1314
class MyConnection(cx_Oracle.Connection):
1415

1516
def __init__(self):
1617
print("Connecting to database")
17-
return super(MyConnection, self).__init__("pythonhol", "welcome", "localhost/orclpdb")
18+
return super(MyConnection, self).__init__(db_config.user, db_config.pw, db_config.dsn)
1819

1920
con = MyConnection()
2021
cur = con.cursor()

samples/tutorial/type_converter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
from __future__ import print_function
1010

1111
import cx_Oracle
12+
import db_config
1213

13-
con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
14+
con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
1415
cur = con.cursor()
1516

1617
for value, in cur.execute("select 0.1 from dual"):

samples/tutorial/type_input.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
from __future__ import print_function
1010

1111
import cx_Oracle
12+
import db_config
1213

13-
con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
14+
con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
1415
cur = con.cursor()
1516

1617
# Create table

samples/tutorial/type_output.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
from __future__ import print_function
1010

1111
import cx_Oracle
12+
import db_config
1213

13-
con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
14+
con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
1415
cur = con.cursor()
1516

1617
print("Standard output...")

samples/tutorial/versions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
from __future__ import print_function
1010

1111
import cx_Oracle
12+
import db_config
1213

13-
con = cx_Oracle.connect('pythonhol/welcome@localhost/orclpdb')
14+
con = cx_Oracle.connect(db_config.user, db_config.pw, db_config.dsn)
1415

1516
print(cx_Oracle.version)

0 commit comments

Comments
 (0)