Search code examples
petapoco

Petapoco - Calling Oracle pipelined function results in "Unsupported column datatype" exception


I calling a pipelined function in Oracle, I'm getting an "Unsupported column datatype" error and not sure how to remedy this.

Here's the code, this is a little simpler than it is in reality but it works exactly the same:

CREATE OR REPLACE FUNCTION CIC3.F_SUG_PUBS_BY_DESIGS(p_desigs in VARCHAR2) 
    RETURN SUG_PUBS_TBL PIPELINED IS
BEGIN
    FOR r IN (
        SELECT invid, title, desc, price, fin, desig FROM v_sugpubs WHERE desig = p_desigs
    )
    LOOP
        PIPE ROW(SUG_PUBS_T(r.invid, r.title, r.desc, r.price, r.fin, r.desig));
    END LOOP;
    RETURN;
END F_SUG_PUBS_BY_DESIGS;
/

Here's the 2 types:

CREATE OR REPLACE TYPE SUG_PUBS_TBL AS TABLE OF SUG_PUBS_T
/

CREATE OR REPLACE TYPE CIC3.SUGGESTED_PUBS_T AS OBJECT
(
     invid VARCHAR2(15),
     title VARCHAR2(300),
     desc VARCHAR2(500),
     price VARCHAR2(5),
     fin NUMBER(15),
     desig VARCHAR2(5)
)
/

Here's my service call:

public object Get(SugPubsRequest request)
{
    if (QryPidFromLT(request.LT) == request.PID)
    {
        List<SugPubsResponse> p = GetSugPubs(request.Desigs);
        return p;
    }
    else
    {
        throw new AuthenticationException("Invalid LT");
    }
}

private List<SugPubsResponse> GetSugPubs(string Desigs)
{
    var db = new PetaPoco.Database("Settings.Oracle");
    var sql = "SELECT F_SUG_PUBS_BY_DESIGS('" + Desigs + "') FROM DUAL";
    List<SugPubsResponse> _sc = db.Fetch<SugPubsResponse>(sql);
    return _sc;
}

And here's the Models:

[Route("/SugPubs/{LT}/{PID}/{Desigs}")]
public class SugPubsRequest
{
    public string LT { get; set; }
    public int PID { get; set; }
    public string Desigs { get; set; }
}
public class SugPubsResponse
{
    [PetaPoco.Column("invid")]
    public string InvId { get; set; }
    [PetaPoco.Column("title")]
    public string Title { get; set; }
    [PetaPoco.Column("desc")]
    public string Desc { get; set; }
    [PetaPoco.Column("price")]
    public string Price { get; set; }
    [PetaPoco.Column("fin")]
    public int Fin { get; set; }
    [PetaPoco.Column("desig")]
    public string Desig { get; set; }
}

Solution

  • To allow others to make it work, I did this to get the results: All you have to do is change the SQL in your service call:

    var sql = "SELECT * FROM TABLE(F_SUG_PUBS_BY_DESIGS('" + Desigs + "'))";