Need help with bytea data type from PostgreSQL.

Garrick via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Apr 12 14:48:25 PDT 2016


On Tuesday, 12 April 2016 at 13:01:12 UTC, Suliman wrote:
> With:
> x = row[0].as!(ubyte[]);
>
> I am getting error:
>
> core.exception.AssertError at C:\D\dmd2\windows\bin\..\..\src\phobos\std\typecons.d(1920): Called `get' on null Nullable!ubyte[].

I'm the author of the specific dpq library you're using. I've 
already answered you on GitHub, but just in case anyone stumbles 
upon this thread in the future.

All the results returned by row[index] will be of type 
Nullable!Value, you must check if they're not NULL using the 
isNull method of Nullable, if the result can ever be NULL.

What I suggest you do, whenever you are fetching a whole column, 
like for instance an user, is to use a User struct, which you can 
then fetch, in whole, using connection.findOne!User(<userId>), 
which will return a Nullabe!User that will only be null if no 
rows were selected.

A bunch of examples of that are in the project's README. 
Specifically, I am talking about ensureSchema and 
findOne/findMany/... methods on Connection struct.

Currently, the plan is to add a way to fetch scalar values from 
tables too.



More information about the Digitalmars-d-learn mailing list