Recent

Author Topic: SQLite date problem  (Read 6850 times)

IndianaJones

  • Hero Member
  • *****
  • Posts: 509
SQLite date problem
« on: January 12, 2013, 01:29:41 pm »
Hi forum people,

I have encountered a date problem in SQLite3 which if I create a date field in the table it restricts the data entry in the DBGrid as YYYY-MM-DD format.
Can I change this format to DD.MM.YYYY?
Any help would be appreciated, thanks.

e.g. CREATE TABLE Example(x integer primary key, adate date)

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: SQLite date problem
« Reply #1 on: January 12, 2013, 04:48:45 pm »
I would think the "problem" lies in the way the datagrid displays/accepts dates - i.e. the dates are stored as date fields in your db (as evidenced in your create table snippet) and treated as dates by FPC/Lazarus.

I would expect the dbgrid date format to follow operating system current language/locale settings (i.e. date format/currency format) (note: you haven't specified Lazarus or FPC version or OS, right?).
Following the user interface settings would be a good idea in general, IMO.

Perhaps there is a way to tell the grid to use a different display format/validation format for dates... don't know though.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

IndianaJones

  • Hero Member
  • *****
  • Posts: 509
Re: SQLite date problem
« Reply #2 on: January 12, 2013, 07:59:00 pm »

Sorry, here is my specifications:
FPC 2.6.1
Lazarus 1.1 SVN 39697
Windows 7
At this point, I would expect the dbgrid date format to follow system current settings too but it doesnt. I also checked my windows settings and it says dd.mm.yyyy. Another interesting thing is now I changed the data format with SQLiteStudio application as dd.mm.yyyy and that data comes blank in DBGrid.  :-[

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: SQLite date problem
« Reply #3 on: January 13, 2013, 12:24:27 pm »
1. I wonder whether the dbgrid (really FPC SQLDB) picks up the date field as a date given your remark about your local settings.
2. "change the date format to dd.mm.yyyy" sounds to me not like changing the date format but using a varchar/text field with a display format.
sqlite is of course tricky because apparently it does not do field type checking (you can put a string in an integer field) as opposed to other more traditional RDBMS.

Perhaps it's time for a small sample project with included sqlite db...? Alternatively, perhaps there are others who have more experience with sqlite who can shed some light here.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

JanRoza

  • Hero Member
  • *****
  • Posts: 672
    • http://www.silentwings.nl
Re: SQLite date problem
« Reply #4 on: January 13, 2013, 03:07:10 pm »
Have you taken a look on the SQLite website http://www.sqlite.org/lang_datefunc.html
It gives some info about how to manipulate the date in SQL.

It's worth to experiment a bit with this info.
OS: Windows 10 (64 bit) / Linux Mint (64 bit)
       Lazarus 3.2 FPC 3.2.2
       CodeTyphon 8.40 FPC 3.3.1

IndianaJones

  • Hero Member
  • *****
  • Posts: 509
Re: SQLite date problem
« Reply #5 on: January 14, 2013, 02:46:28 pm »

I have created a simple example, and everything works fine. DBGrid gets the data as defined in system environment setting. And in the database it is sotred as YYYY-MM-DD.
So it seems that the main app. suffer some difficulties and have to check.
One more thing What is the best way to check date exception? I attached a simple app.
Thanks.

 

TinyPortal © 2005-2018