Access network ressources / database

Re: Access network ressources / database

by Stephan Kochauf -
Number of replies: 0

Finally, it's working ... and I can run Oracle queries via Coderunner. Maybe it helps someone too:

Solution:
I took jobeinabox docker image from https://github.com/trampgeek/jobeinabox and installed oracle client there.

These are the necessary steps:
sudo -H python3 -m pip install cx_Oracle

apt-get update
sudo apt-get install wget
mkdir -p /opt/oracle
cd /opt/oracle
wget https://download.oracle.com/otn_software/linux/instantclient/211000/instantclient-basic-linux.x64-21.1.0.0.0.zip

unzip instantclient-basic-linux.x64-21.1.0.0.0.zip
sudo apt-get install libaio1
sudo sh -c "echo /opt/oracle/instantclient_21_1 > /etc/ld.so.conf.d/oracle-instantclient.conf"
sudo ldconfig

Then I'm using a python script to validate the test case:

import subprocess, sys
import cx_Oracle as oracledb

db_connection_string = '... connection string ...'

con = oracledb.connect(db_connection_string)

cursor1 = con.cursor()  

student_answer = """{{ STUDENT_ANSWER | e('py') }}"""
cursor1.execute(student_answer)   
cursor1.fetchall()

col_names = []
for i in range(0, len(cursor1.description)):
    col_names.append(cursor1.description[i][0])

print("Expected ROWS: " + str(cursor1.rowcount))
print("Expected COLUMNS: ")
print(col_names)
print("Expected DATA (first 3 rows as example):")
number = 0
cursor1.execute(student_answer)   
while True:
    row = cursor1.fetchone()
    if row is None:
        break
    print(row)
    number = number + 1
    if number >= 3:
        break