Skip to content

Commit 18ae81a

Browse files
Usage updates for Flask demos.
1 parent 7f3c938 commit 18ae81a

File tree

2 files changed

+46
-11
lines changed

2 files changed

+46
-11
lines changed

samples/connection_pool.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,19 @@
3333
# features help protect against dead connections, and also aid use of Oracle
3434
# Database features such as FAN and Application Continuity.
3535
#
36-
# To run this sample, install Flask with:
37-
# pip install --upgrade Flask
36+
# To run this sample:
37+
#
38+
# 1. Install Flask, for example like:
39+
#
40+
# python -m pip install Flask
41+
#
42+
# 2. (Optional) Set environment variables referenced in sample_env.py
43+
#
44+
# 3. Run:
45+
#
46+
# python connection_pool.py
47+
#
48+
# 4. In a browser load a URL as shown below.
3849
#
3950
# The default route will display a welcome message:
4051
# http://127.0.0.1:8080/
@@ -48,12 +59,15 @@
4859
#------------------------------------------------------------------------------
4960

5061
import os
51-
import oracledb
62+
import sys
63+
5264
from flask import Flask
65+
66+
import oracledb
5367
import sample_env
5468

5569
# Port to listen on
56-
port=int(os.environ.get('PORT', '8080'))
70+
port = int(os.environ.get('PORT', '8080'))
5771

5872
# determine whether to use python-oracledb thin mode or thick mode
5973
if not sample_env.get_is_thin():
@@ -167,5 +181,8 @@ def show_username(id):
167181
# Create a demo table
168182
create_schema()
169183

184+
m = f"\nTry loading http://127.0.0.1:{port}/user/1 in a browser\n"
185+
sys.modules['flask.cli'].show_server_banner = lambda *x: print(m)
186+
170187
# Start a webserver
171188
app.run(port=port)

samples/drcp_pool.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
# established.
4343
#
4444
# To use DRCP, the connection string should request the database use a pooled
45-
# server. For example, "localhost/orclpdb:pool". It is best practice for
45+
# server. For example, "localhost/orclpdb:pooled". It is best practice for
4646
# connections to specify a connection class and server purity when creating
4747
# a pool
4848
#
@@ -63,8 +63,19 @@
6363
#
6464
# See the python-oracledb documentation for more information on DRCP.
6565
#
66-
# To run this sample, install Flask with:
67-
# pip install --upgrade Flask
66+
# To run this sample:
67+
#
68+
# 1. Install Flask, for example like:
69+
#
70+
# python -m pip install Flask
71+
#
72+
# 2. (Optional) Set environment variables referenced in sample_env.py
73+
#
74+
# 3. Run:
75+
#
76+
# python drcp_pool.py
77+
#
78+
# 4. In a browser load a URL as shown below.
6879
#
6980
# The default route will display a welcome message:
7081
# http://127.0.0.1:8080/
@@ -87,14 +98,18 @@
8798
#
8899
# Output will be like:
89100
#
90-
# CCLASS_NAME NUM_REQUESTS NUM_HITS NUM_MISSES NUM_WAITS NUM_AUTHENTICATIONS
91-
# ---------------- ------------ -------- ---------- --------- -------------------
92-
# PYTHONDEMO.MYAPP 1001 997 4 0 4
101+
# CCLASS_NAME NUM_REQUESTS NUM_HITS NUM_MISSES NUM_WAITS NUM_AUTHENTICATIONS
102+
# ---------------- ------------ -------- ---------- --------- -------------------
103+
# PYTHONDEMO.MYAPP 1001 997 4 0 4
104+
#
105+
# With ADB-S databases, query V$CPOOL_CONN_INFO instead.
93106
#
94107
#------------------------------------------------------------------------------
95108

96-
from flask import Flask
97109
import os
110+
import sys
111+
112+
from flask import Flask
98113

99114
import oracledb
100115
import sample_env
@@ -214,5 +229,8 @@ def show_username(id):
214229
# Create a demo table
215230
create_schema()
216231

232+
m = f"\nTry loading http://127.0.0.1:{port}/user/1 in a browser\n"
233+
sys.modules['flask.cli'].show_server_banner = lambda *x: print(m)
234+
217235
# Start a webserver
218236
app.run(port=port)

0 commit comments

Comments
 (0)