in

System.Data.SQLite

An open source ADO.NET provider for the SQLite database engine

DataType Mappings

Last post 08-19-2010 3:20 PM by RHhardmoney. 41 replies.
Page 1 of 3 (42 items) 1 2 3 Next >
Sort Posts: Previous Next
  • 09-21-2005 7:51 AM

    DataType Mappings

    Locked Reply Contact

    Since the SQLite engine is inherently typeless and ADO.NET is much more strongly typed, the ADO.NET wrapper must make certain decisions about the columns returned in any given SQL query.  One of the deciding factors is the underlying datatype declared in the CREATE TABLE statement.

    The following lists the datatypes and mappings the SQLite ADO.NET wrapper understands.  If there is anything missing, wrong, or needs adding, please let me know:

    COUNTER DbType.Int64
    AUTOINCREMENT DbType.Int64
    IDENTITY DbType.Int64
    LONG DbType.Int64
    TINYINT DbType.Byte
    INTEGER DbType.Int64
    INT DbType.Int32
    VARCHAR DbType.String
    NVARCHAR DbType.String
    CHAR DbType.String
    NCHAR DbType.String
    TEXT DbType.String
    NTEXT DbType.String
    STRING DbType.String
    DOUBLE DbType.Double
    FLOAT DbType.Double
    REAL DbType.Single
    BIT DbType.Boolean
    YESNO DbType.Boolean
    LOGICAL DbType.Boolean
    BOOL DbType.Boolean
    NUMERIC DbType.Decimal
    DECIMAL DbType.Decimal
    MONEY DbType.Decimal
    CURRENCY DbType.Decimal
    TIME DbType.DateTime
    DATE DbType.DateTime
    TIMESTAMP DbType.DateTime
    DATETIME DbType.DateTime
    BLOB DbType.Binary
    BINARY DbType.Binary
    VARBINARY DbType.Binary
    IMAGE DbType.Binary
    GENERAL DbType.Binary
    OLEOBJECT DbType.Binary
    GUID DbType.Guid
    UNIQUEIDENTIFIER DbType.Guid
    MEMO DbType.String
    NOTE DbType.String
    LONGTEXT DbType.String
    LONGCHAR DbType.String
    SMALLINT DbType.Int16
    BIGINT DbType.Int64
    LONGVARCHAR DbType.String
    SMALLDATE DbType.DateTime
    SMALLDATETIME DbType.DateTime
  • 09-21-2005 8:02 AM In reply to

    Re: DataType Mappings

    One more thing regarding the difference in mapping between INT and INTEGER:

    The reason INT maps to Int32 and INTEGER maps to Int64 is compatibility.  Access databases use the INT keyword, which is (in Access) 32-bits.  Since one of the main reasons I wrote this wrapper was to allow people to replace their Access databases with SQLite, I figured people would have less bugs and problems porting this way.  However, there are people replacing their Access databases with SQLite because they want to break free of the 2gb database size limitation of Access and therefore need Int64 keys.  If that's a design goal then all you really need to do is change the SQLite table definition to use INTEGER instead of INT.

    Robert

     

  • 11-18-2005 5:28 AM In reply to

    • Robert Foster
    • Top 75 Contributor
    • Joined on 11-18-2005
    • Hoppers Crossing, Melbourne, Victoria, Australia
    • Posts 16

    Re: DataType Mappings

    How about DATETIME?  And how are Dates and Times stored? as String? in the ISO8601 format?  This is a big issue for me trying to port my app from  Finisar.SQLite :(
  • 11-18-2005 7:36 AM In reply to

    Re: DataType Mappings

    Now that I look at the code, it appears that "Datetime" will properly map to System.DateTime.

    DateTime's are stored in one of two formats.  The default datetime format is ISO8601, and you specify the format in the connection string like Finisar does.  The varying ISO8601 strings that this class uses to convert are:

    "yyyy-MM-dd HH:mm:ss",
    "yyyyMMddHHmmss",
    "yyyyMMddTHHmmssfffffff",
    "yyyy-MM-dd",
    "yy-MM-dd",
    "yyyyMMdd",
    "HH:mm:ss",
    "THHmmss"

    The other format is Ticks.  In the SQLiteConnection class in the helpfile is a description of all the connectionstring options.

    Robert

     

  • 04-08-2006 5:26 PM In reply to

    Re: DataType Mappings

    NTEXT isn't on the above list. Is TEXT a good subsitute?

    I'm getting a GetFieldType() returning null as a result.  

    The NTEXT was in my table definition because it was just the opposite with SQLServerCE. It supports NTEXT but not TEXT.

     

  • 04-11-2006 2:11 PM In reply to

    Re: DataType Mappings

    This is fixed in the upcoming 1.0.28.0 release due out the end of this week or early next.

    Robert

     

  • 04-25-2006 9:09 PM In reply to

    Re: DataType Mappings

    GetFieldType() still seems to return null for an NTEXT field in version 1.28.

    Is there something I am doing wrong?

     

  • 04-26-2006 8:24 AM In reply to

    Re: DataType Mappings

    Hard to say.  I'll see if I can duplicate this.

    Robert

     

  • 04-27-2006 10:03 AM In reply to

    Re: DataType Mappings

    This happens creating a dataset and dataadpater from a database table with NText.

    It would be acceptable to use TEXT if it handles UNICODE characters okay. I don't know if that is the case.

    Nathan 

  • 04-27-2006 10:14 AM In reply to

    Re: DataType Mappings

    I created a new table with an ntext column and it worked just fine for me.  Also, SQLite treats text, ntext, varchar, nvarchar and all other string types as all being equal.  If you open the database with UseUTF16Encoding=True in the connectionstring, then the entire database will be UNICODE.  Otherwise it'll be UTF-8.

    Robert

     

  • 04-27-2006 11:59 AM In reply to

    Re: DataType Mappings

    I've resolved that. The program was still picking up 1.27.1 by mistake. I think I failed to save the project file when I changed it.

    UTF-8 is just fine.

    Nathan

  • 08-31-2006 5:12 AM In reply to

    • zapov
    • Top 500 Contributor
    • Joined on 06-27-2006
    • Posts 4

    Re: DataType Mappings

    I think it would be good if you changed scope of Type to DbType mapping in SQLConverter.cs
    from internal static to public static.

    Or is there some other prefered way to set parameter type dynamically?
  • 08-31-2006 7:38 AM In reply to

    Re: DataType Mappings

    The preferred method is to not set it at all.  Just create a new parameter, set the Value, and go.  The provider will call TypeToDbType() internally and set the DbType for you.

    Robert

     

  • 09-04-2006 5:41 PM In reply to

    • Cisien
    • Top 200 Contributor
    • Joined on 09-04-2006
    • Posts 7

    Re: DataType Mappings

    Support for unsigned integers using the UNSIGNED column definition.
  • 09-04-2006 8:48 PM In reply to

    Re: DataType Mappings

    Yep I think I need to add unsigned support :)

     

Page 1 of 3 (42 items) 1 2 3 Next >
Powered by Community Server (Commercial Edition), by Telligent Systems