#Calling PLSQL from Django

3 messages · Page 1 of 1 (latest)

wet tulip
#

Can someone kindly tell me where/how i am to use PLSQL in a Django app.

For example. I have a basic Django project set up using ALLAUTH for signing in and i want to update my first and last name in the AUTH_USER table.

I have a PLSQL procedure created in the database.

CREATE OR REPLACE PACKAGE BODY PKG_PERSON
AS

PROCEDURE UPDATE_PERSON(P_ID AUTH_USER.ID%type,
    P_FIRST_NAME AUTH_USER.FIRST_NAME%type,
    P_LAST_NAME AUTH_USER.LAST_NAME%type,
    P_EMAIL AUTH_USER.EMAIL%type)
IS
BEGIN
    UPDATE
        AUTH_USER
    SET
        FIRST_NAME=P_FIRST_NAME,
        LAST_NAME=P_LAST_NAME,
        EMAIL=P_EMAIL
    WHERE
        ID=P_ID;
    COMMIT;
END UPDATE_PERSON;

END PKG_PERSON;

But i am unsure where/how to call this and then to show the newly updated data on the profile page. Also, if i have multiple stored procedure to be rendered on a page how would i retrieve and display data from the database to the HTML page and how do i submit data to be updated.

views.py

import os
import oracledb
from django.views.generic import TemplateView
from dotenv import load_dotenv
from .models import AuthUser

load_dotenv()

connection = oracledb.connect(
    user=os.environ.get('DB_USER'),
    password=os.environ.get('DB_PASSWORD'),
    dsn=os.environ.get('DB_DSN'))

class Profile(TemplateView):
    template_name = 'profile.html'
    cursor = connection.cursor()
    cursor.callproc('PKG_PERSON.UPDATE_PERSON', [2, 'John', 'Doe', 'john@doe.com'])

Any assistance with this would be greatly appreciated!!

echo tapir
#

so generally, Django's ORM should take care of that for you, provided you're using a properly set up psql connector in your settings.py

#

that said, I don't see a connector specifically for plsql