Skip to content

Commit 325f108

Browse files
Move Oracle Database 21 and higher objects to its own schema file for
ease of maintenance.
1 parent 1c0f626 commit 325f108

File tree

4 files changed

+55
-20
lines changed

4 files changed

+55
-20
lines changed

samples/create_schema.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#------------------------------------------------------------------------------
2-
# Copyright (c) 2020, 2022, Oracle and/or its affiliates.
2+
# Copyright (c) 2020, 2023, Oracle and/or its affiliates.
33
#
44
# This software is dual-licensed to you under the Universal Permissive License
55
# (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
@@ -49,4 +49,7 @@
4949
edition_user=sample_env.get_edition_user(),
5050
edition_password=sample_env.get_edition_password(),
5151
edition_name=sample_env.get_edition_name())
52+
if sample_env.get_server_version() >= (21, 0):
53+
sample_env.run_sql_script(conn, "create_schema_21",
54+
main_user=sample_env.get_main_user())
5255
print("Done.")

samples/sample_env.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@
8888
import platform
8989
import sys
9090

91+
import oracledb
92+
9193
# default values
9294
DEFAULT_MAIN_USER = "pythondemo"
9395
DEFAULT_EDITION_USER = "pythoneditions"
@@ -170,6 +172,17 @@ def get_oracle_client():
170172
return get_value("PYO_SAMPLES_ORACLE_CLIENT_PATH",
171173
"Oracle Instant Client Path")
172174

175+
def get_server_version():
176+
name = "SERVER_VERSION"
177+
value = PARAMETERS.get(name)
178+
if value is None:
179+
conn = oracledb.connect(user=get_main_user(),
180+
password=get_main_password(),
181+
dsn=get_connect_string())
182+
value = tuple(int(s) for s in conn.version.split("."))[:2]
183+
PARAMETERS[name] = value
184+
return value
185+
173186
def run_sql_script(conn, script_name, **kwargs):
174187
statement_parts = []
175188
cursor = conn.cursor()

samples/sql/create_schema.sql

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -251,25 +251,6 @@ create table &main_user..TestGeometry (
251251
)
252252
/
253253

254-
declare
255-
t_Version number;
256-
begin
257-
258-
select to_number(substr(version, 1, instr(version, '.') - 1))
259-
into t_Version
260-
from product_component_version
261-
where product like 'Oracle Database%';
262-
263-
if t_Version >= 21 then
264-
execute immediate 'create table &main_user..CustomersAsJson (' ||
265-
' id number(9) not null primary key,' ||
266-
' json_data json' ||
267-
')';
268-
end if;
269-
270-
end;
271-
/
272-
273254
-- create queue table, queues and subscribers for demonstrating Advanced Queuing
274255
begin
275256

samples/sql/create_schema_21.sql

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*-----------------------------------------------------------------------------
2+
* Copyright 2023, Oracle and/or its affiliates.
3+
*
4+
* This software is dual-licensed to you under the Universal Permissive License
5+
* (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
6+
* 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose
7+
* either license.*
8+
*
9+
* If you elect to accept the software under the Apache License, Version 2.0,
10+
* the following applies:
11+
*
12+
* Licensed under the Apache License, Version 2.0 (the "License");
13+
* you may not use this file except in compliance with the License.
14+
* You may obtain a copy of the License at
15+
*
16+
* https://www.apache.org/licenses/LICENSE-2.0
17+
*
18+
* Unless required by applicable law or agreed to in writing, software
19+
* distributed under the License is distributed on an "AS IS" BASIS,
20+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21+
* See the License for the specific language governing permissions and
22+
* limitations under the License.
23+
*---------------------------------------------------------------------------*/
24+
25+
/*-----------------------------------------------------------------------------
26+
* create_schema.sql
27+
*
28+
* Performs the actual work of creating and populating the schemas with the
29+
* database objects used by the python-oracledb samples. An edition is also
30+
* created for the demonstration of PL/SQL editioning. It is executed by the
31+
* Python script create_schema.py.
32+
*---------------------------------------------------------------------------*/
33+
34+
create table &main_user..CustomersAsJson (
35+
id number(9) not null primary key,
36+
json_data json
37+
)
38+
/

0 commit comments

Comments
 (0)