Skip to main content

Parse Property values from Oracle Profile Provider Schema

Recently we had the need to pull user profile information independent of the Microsoft provider framework. The property values are stored in a table that contains a "PropertyNames" field with meta information on the start position and length of the property value being stored.
Image and video hosting by TinyPic
This self-describing storage method is pretty slick but attempting to use the built in wrapped function for retrieving the property values proved to be more challenging than simply writing our own parser.
There are two SQL functions. They are used in this way:
 
SELECT p.USERID, m.EMAIL,
	GETPROFILEELEMENT('FirstName', PropertyNames, PropertyValuesString) AS FirstName, 
	GETPROFILEELEMENT('LastName', PropertyNames, PropertyValuesString) AS LastName 
FROM ora_aspnet_profile p, ora_aspnet_membership m
WHERE p.USERID = m.USERID

Here are the functions:
 
CREATE OR REPLACE FUNCTION ASPNET_DB_USER."GETPROFILEELEMENT"
    (
                fieldName IN VARCHAR2,
                fields IN NCLOB,
                valuess IN NCLOB)
RETURN VARCHAR2
            AS
            fieldNameToken VARCHAR2(1000);
            fieldNameStart INT;
            valueStart INT;
            valueLength INT;
    BEGIN
    IF fieldName IS NULL
                OR LENGTH(fieldName) = 0
            OR fields IS NULL
            OR LENGTH(fields) = 0
            OR valuess IS NULL
            OR LENGTH(valuess) = 0
                THEN
    RETURN NULL;
    ELSE
                fieldNameStart := INSTR(fields,fieldName || ':S',1);
    END
IF;
    IF fieldNameStart = 0
                THEN
    RETURN NULL;
ELSE
            fieldNameStart := fieldNameStart + LENGTH(fieldName) + 3;
            fieldNameToken := SUBSTR(Fields,fieldNameStart,LENGTH(Fields)-fieldNameStart);
            valueStart := getelement(1,fieldNameToken,':');
            valueLength := getelement(2,fieldNameToken,':');
END
IF;
    IF valueLength = 0
                THEN
    RETURN '';
END
IF;
    RETURN SUBSTR(valuess, valueStart+1, valueLength);
END GETPROFILEELEMENT;

 
CREATE OR REPLACE FUNCTION ASPNET_DB_USER."GETELEMENT"
    (
                ord IN INT,
                STR IN VARCHAR2,
                delim IN VARCHAR2)
RETURN INT
            IS
            pos INT;
            curord INT;
    BEGIN
    IF STR IS NULL
                OR LENGTH(STR) = 0
            OR ord IS NULL
            OR ord < 1
            OR ord > LENGTH(STR) - LENGTH(REPLACE(STR, delim, '')) + 1
                THEN
    RETURN NULL;
    END
IF;
                pos := 1;
                curord := 1;
    WHILE curord < ord
                LOOP
                pos := INSTR(STR,delim,pos)+1;
                curord := curord + 1;
    END LOOP;
    RETURN TO_NUMBER(SUBSTR(STR, pos, INSTR(STR || delim,delim,pos) - pos));
END GetElement;

Comments

Popular posts from this blog

Sorting an ICollection

Have you ever wanted to sort an ICollection? It took me awhile to figure this one out so I thought I should blog it. I originally posted this quite awhile ago. Since then I have discovered a much easier way to sort a collection. Here's an update on sorting collections using LINQ. Much simpler: var orderedList = customer.Users .OrderBy(x => x.UserType) .ToList(); And here is my original post on the subject. You decide which one looks easier. private IList<EventReqFormSection> GetSections() { ICollection<EventReqFormSection> sections = EventReqFormSection.GetByEventReqFormId(_businessObject.Id, ObjectManager); // sort by Display Sequence List<EventReqFormSection> sortedValues = new List<EventReqFormSection>(sections); sortedValues.Sort(new EventReqFormSection.DisplaySequenceSort()); return sortedValues; } The above function retrieves an ICollection puts it into a List object and calls the sort method usin...
This blog is complete rubbish. Who knew the blogger release was going to fubar my blog so badly? Sigh... Well. I did kind of ignore this for about the last 4 years so it's my fault. I don't know if I have the energy to try repair my previous posts, or if I should just delete them all and start fresh?

Viewing the contents of an Oracle cursor in Toad

Prefix your cursor variable with a colon ":" begin event_api.get_activity_data(1, null,'2013', null, null, null,:pResultSet); end; Toad will prompt you for the type. Select CURSOR And voila! You will have the cursor dumped into a data grid within Toad!