Question

I was basically following this example : http://www.youtube.com/watch?v=B4uxLLIUddg

New -> Other ->Datasnap Server -> VCL Forms Application (All default settings,Port 211 working, TDSServerModule).

Then created a table in SQLite :

CREATE TABLE [T1] (
  [ID] INTEGER PRIMARY KEY AUTOINCREMENT, 
  [DATE] DATE, 
  [TIME] TIME);

On my ServerMethodsUnit1 I dropped a TSQLConnection. Changed the Driver to Sqlite. Removed LoginPrompt. Connection connected OK. Added TSQLDataset and connected it to my SQLITECONNECTION. Set CommandText to my T1 (the table name). Made it active without a problem. Added a datasetprovider1 and lined it to my dataset (The table T1). Saved all. Run the server without a problem.With the server running,I constructed the client side:

To my project I added a new project (vcl forms application). Added a SQLConnection component. Set its driver name to Datasnap. Removed loginprompt. On the form I dropped DSProviderConnection1. Connected it to my sqlconnection. Set its ServerClassname to TServerMethods1. Tested the connection - both work OK. Dropped a Clientdataset. Connected its RemoteServer property to that of DSProviderConnection1. ProviderName to DataSetProvider1. Connection succeeded. Clientdataset is active. Added a DataSource.Linked it to my Clientdataset. All connections work. So I added a little GUI. Dropped a TDBGrid and a TDBNavigator. Linked them to Datasource1. The first strange thing I noticed is that all fields displayed Widememo. Why is this when fields are completely different,I dont know. Went to the fields editor,added the fields and when checking the BlobType all displayed ftWideMemo.

enter image description here

I tried to insert todays date directly in the grid and somehow in my DB it ended up : 1899-12-30. Checking the table (T! on the server side), the DATE,and TIME field also displays widememo.

What am I missing here ?

Was it helpful?

Solution

SQlite has very loose typing. DATE and TIME are not part of SQLite. And DBGrids don't know what to do with SQLite TEXT.

The way I got around this problem was to use VARCHAR(length) instead of TEXT when defining the fields. Then those will display OK in a DBGrid. And I did dates also as VARCHAR().

See Also

Displaying and editing MEMO fields in Delphi's TDBGrid http://delphi.about.com/library/weekly/aa030105a.htm

OTHER TIPS

There is no such native DATE nor TIME type in SQlite3:

SQLite does not have a storage class set aside for storing dates and/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values:

  • TEXT as ISO8601 strings ("YYYY-MM-DD HH:MM:SS.SSS").
  • REAL as Julian day numbers, the number of days since noon in Greenwich on November 24, 4714 B.C. according to the proleptic Gregorian calendar.
  • INTEGER as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC.

Applications can chose to store dates and times in any of these formats and freely convert between formats using the built-in date and time functions.

Also ensure that you understood the "type affinity" feature of SQlite3 columns - which is pretty powerful, but may be confusing if you come from a "strongly typed" RDBMS.

What you can do is

  • Either uses Unix time and an INTEGER column - see UnixToDateTime function for instance in DateUtils.pas unit;
  • Or a TEXT column and ISO-8601 encoding (my preferred).

Then you will have to map this value in DataSnap - I know that our mORMot units allow this, and I do not know exactly for DataSnap.

Also take a look at all integrated date/time functions in SQlite3 which are pretty complete.

I had the same issue as all my SQLite fields were showing up as WideMemo fields in the DBGrid.

One simple solution is to populate the corresponding sqlite table with at least one (1) row of 'proper' data (no empty fields). When VCL components are connecting (for the first time), they seem to be able to create fields with the right type.That is, if you right click on a TSQLDataSet component and select the Fields Editor -> Create fields, with a table that has at least one row of data, the fields will be correctly mapped.

I have not checked if that works for the DATE type, but it does work for integers, doubles and text.

For some reason, if the table is empty, all fields are created as WideMemo blobs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top