Re: [sqlite] Preferred cast in C#

2014-07-15 Thread Edward Ned Harvey (sqlite)
> From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-
> boun...@sqlite.org] On Behalf Of Simon Slavin
> 
> Which does /not/ describe it as "The official SQLite database engine", which
> is the point I was making.

I used NuGet.
http://www.nuget.org/packages/System.Data.SQLite.Core/
"The official SQLite database engine" published by "SQLite Development Team"

Anyway, thanks for the answers everyone.  I'm happy to move on from this 
topic...
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Preferred cast in C#

2014-07-15 Thread Edward Ned Harvey (sqlite)
> From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-
> boun...@sqlite.org] On Behalf Of RSmith
> 
> 
> System.DBNull is not a native SQLite construct, it is probably one of the 
> third
> party connectors. 

In C#, using the System.Data.Sqlite.Core package, which is described as "The 
official SQLite database engine" and published by "SQLite Development Team"...  
The results of a Select statement are returned as an Object().  If the database 
contents were Null, then the result is an instance of System.DBNull() class, 
rather than returning null.

If this is not using the API directly, I don't know what is.


> I am not sure which development
> environment you are using, I am guessing some C or scripting

The subject line says C#


> none of which is a standard or used in a wide
> variety of systems - which is why the other poster did not even know what
> you meant with "long?".  

The official sqlite C# packages, if only counting the ones distributed by NuGet 
(not counting those who download direct from www.sqlite.org or build from 
source) has over 425,000 downloads, and is among the most popular packages 
deployed.


> Maybe ask the designers of your connector for such functionality?

That's why I came to post here.

I thought, since there is a direct analogous native type in C# for each of the 
native storage types in SQLite, there was likely a native way to interoperate 
them seamlessly.  It seems I was wrong - but it's ok - the workaround was not 
terribly difficult.  I just felt like I was hacking and kludging my way through 
something that surely there must be a better way.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Preferred cast in C#

2014-07-15 Thread Edward Ned Harvey (sqlite)
> From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-
> boun...@sqlite.org] On Behalf Of Edward Ned Harvey (sqlite)
> 
> I would really love to have an easy way of putting a long? into the database,
> and then getting a long? back out.  Maybe it exists and I'm just doing it the
> hard way right now...

I guess what I'm really getting at is this:  The 5 data types in sqlite are 
Null, Integer, Real, Text, and Blob.  These all have native counterparts in C#, 
specifically:  null, long? (or Nullable), double? (or Nullable), 
string, and byte[].

If I have something like a long? or a double?, and I want to natively store it 
and retrieve it, I am surprised such a thing doesn't exist.  Instead, I have to 
check for null and if so, then store System.DBNull, and when I retrieve it, I 
have to check for System.DBNull and if so, then return null...
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Preferred cast in C#

2014-07-15 Thread Edward Ned Harvey (sqlite)
> From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-
> boun...@sqlite.org] On Behalf Of Hick Gunter
> 
> Why is the column nullable if you require a default value to be returned?

The default value for long? or string or byte[] is null.  Which makes perfect 
sense.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Preferred cast in C#

2014-07-15 Thread Edward Ned Harvey (sqlite)
> From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-
> boun...@sqlite.org] On Behalf Of Random Coder
> 
> Could you not do something like this to handle the nullable types?
> 
> T GetValue(string field)
> {
> object obj = reader[field];
> 
> if (obj is System.DBNull)
> return default(T);
> else
> return (T)obj;
> }
> 
> Assuming the type is nullable, it should do the right thing, and if it's an
> unexpected type, it'll throw an exception when casting to T.

In fact, that's what I'm doing now - except I decided to make it specifically 
long, string, and byte[], rather than generic.  Because I wanted to discourage 
any sort of belief of actual support for things like int, uint16, uint64, etc.  
All of which would technically work except ulong (uint64)...

If this is the way people use it, so be it.  I just thought there would 
probably exist something more natural, that I couldn't find...
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Preferred cast in C#

2014-07-15 Thread Edward Ned Harvey (sqlite)
> From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-
> boun...@sqlite.org] On Behalf Of Joseph L. Casale
> 
> > I would really love to have an easy way of putting a long? into the 
> > database,
> and then getting a long? back out.
> 
> What do you want to happen when the column is null as in your string
> example?

I would like the long? to be null.  

Based on your response, it seems you didn't notice the ? mark.  This is a 
shorthand for Nullable which means it may be either null, or a long. 
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] Preferred cast in C#

2014-07-14 Thread Edward Ned Harvey (sqlite)
I understand there are only 5 data types in Sqlite, and that the column type 
isn't necessarily the type of object returned in a query.  Is there a more 
seamless way to cast responses than this?

I would really love to have an easy way of putting a long? into the database, 
and then getting a long? back out.  Maybe it exists and I'm just doing it the 
hard way right now...

string employeeName;

object myObj = reader["employeeName"];
if (myObj is System.DBNull)
employeeName = null;
else if (myObj is string)
employeeName = (string)myObj;
else
throw new Exception("Unexpected object type");
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users