Skip to content

Commit

Permalink
Move Oracle Database 21 and higher objects to its own schema file for
Browse files Browse the repository at this point in the history
ease of maintenance.
  • Loading branch information
anthony-tuininga committed Apr 21, 2023
1 parent 1c0f626 commit 325f108
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 20 deletions.
5 changes: 4 additions & 1 deletion samples/create_schema.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#------------------------------------------------------------------------------
# Copyright (c) 2020, 2022, Oracle and/or its affiliates.
# Copyright (c) 2020, 2023, Oracle and/or its affiliates.
#
# This software is dual-licensed to you under the Universal Permissive License
# (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
Expand Down Expand Up @@ -49,4 +49,7 @@
edition_user=sample_env.get_edition_user(),
edition_password=sample_env.get_edition_password(),
edition_name=sample_env.get_edition_name())
if sample_env.get_server_version() >= (21, 0):
sample_env.run_sql_script(conn, "create_schema_21",
main_user=sample_env.get_main_user())
print("Done.")
13 changes: 13 additions & 0 deletions samples/sample_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@
import platform
import sys

import oracledb

# default values
DEFAULT_MAIN_USER = "pythondemo"
DEFAULT_EDITION_USER = "pythoneditions"
Expand Down Expand Up @@ -170,6 +172,17 @@ def get_oracle_client():
return get_value("PYO_SAMPLES_ORACLE_CLIENT_PATH",
"Oracle Instant Client Path")

def get_server_version():
name = "SERVER_VERSION"
value = PARAMETERS.get(name)
if value is None:
conn = oracledb.connect(user=get_main_user(),
password=get_main_password(),
dsn=get_connect_string())
value = tuple(int(s) for s in conn.version.split("."))[:2]
PARAMETERS[name] = value
return value

def run_sql_script(conn, script_name, **kwargs):
statement_parts = []
cursor = conn.cursor()
Expand Down
19 changes: 0 additions & 19 deletions samples/sql/create_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -251,25 +251,6 @@ create table &main_user..TestGeometry (
)
/

declare
t_Version number;
begin

select to_number(substr(version, 1, instr(version, '.') - 1))
into t_Version
from product_component_version
where product like 'Oracle Database%';

if t_Version >= 21 then
execute immediate 'create table &main_user..CustomersAsJson (' ||
' id number(9) not null primary key,' ||
' json_data json' ||
')';
end if;

end;
/

-- create queue table, queues and subscribers for demonstrating Advanced Queuing
begin

Expand Down
38 changes: 38 additions & 0 deletions samples/sql/create_schema_21.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*-----------------------------------------------------------------------------
* Copyright 2023, Oracle and/or its affiliates.
*
* This software is dual-licensed to you under the Universal Permissive License
* (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
* 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose
* either license.*
*
* If you elect to accept the software under the Apache License, Version 2.0,
* the following applies:
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*---------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------
* create_schema.sql
*
* Performs the actual work of creating and populating the schemas with the
* database objects used by the python-oracledb samples. An edition is also
* created for the demonstration of PL/SQL editioning. It is executed by the
* Python script create_schema.py.
*---------------------------------------------------------------------------*/

create table &main_user..CustomersAsJson (
id number(9) not null primary key,
json_data json
)
/

0 comments on commit 325f108

Please sign in to comment.