Good evening group
I converted my Access database to SQLite.
I set up the connection and I was also able to connect to the SQlite database. I can read a simple text (name and weight), but when I go to the more complex ones I get errors that did not come out before, for example:
near “#2023” syntax error
or
Date string cannot be empty
Why is this because the date management changes between Access and SQLite?
Dates surrounded by # is an Access convention.
Dates in SQLite are usually held as strings (but could be ‘real’ or integer)
String dates would be ‘2016-01-01 10:20:05.123’
Assuming your dates went in as strings, you could perhaps filter
I think I need to study sqlite formatting for dates and its application in fields … where can I find this information?
I need to understand how to change the search from Access to SQlite.
In access:rows = db.SelectSQL(“SELECT * FROM Promemoria where Data=”#“+ FiltroData.SQLDate+”#“), in SQlite
rows = db.SelectSQL(“SELECT * FROM Promemoria where Data='”+ FiltroData.SQLDate+”'")
In Access: DataFormattata =rows.Column(“Data”).DateValue
in Sqlite ?
or
In Access: DataFormattata=rows2.Column(“Data”).DateTimeValue
in Sqlite ?
In Access: filtro=filtro+ " and (Month(data)=1 or Month(data)=2 or Month(data)=3)"
In SQlite ?
You are instantiating an old date (API) object, and you are passing a DateTimeVal ? (API2).
Create a small db with only say 10 Records and play with it / read the SQLiteDatabase documentation.
Add some break in your code to read how things are in the debugger…
dim DataFormatData as DateTime
DataFormatData = DateTime.FromString(rows.Column("Data").DateTimeValue.ToString)
dim s as string = DataFormatData.ToString("dd/MM/yyyy") //will give 21/04/2024
Ciao Federico,
the date as 21/04/2022 is a one of the many way you can view a date.
In Sqlite date are always in as sqlDate (IE yyyy-mm-ddd in your example: 2022-04-21), probably as sqlDateTime (2022-04-21 00:00:00 for example)
In SqLite they are always string (so you can find for substring or using the SqLite date functions)
If the user enter a date as string in your format you can use the Datetime fuction to have a DateTime object and then execute your query.
for your query, since you are learning this topic, use the proper way, don’t concatenate strings:
rows=db.SelectSql(“select * from promemoria where data=?”, myDateTime.toString)
I always convert date/time to seconds from 1970 and store them as doubles, thus making comparisons easy. I convert to/from seconds in Xojo, and handle the timezone at the same time. That way, too, the user can choose the date/time format the application gives them. IMO it is always best to separate the presentation layer from the data storage layer.
You are right, presentation is different from storage.
In any case date time in sqlite is a string natively and you have a lot of native functions.
Moreover Xojo can read them directly as datetime object without any conversion.
Hello group
I continue my attempts to read the date in the correct format that interests me.
If I read the date field with from my database, i’m read in my ListBox:
2022-05-08 00:00:00 from rows.Column(“Data”).StringValue
I wanted to set the format European/Italy/Rome and I tried to write:
Datetime.FromString(rows.Column(“Data”), Nil,New TimeZone(“Europe/Rome”))
and NOT WORK
i’m test this code:
Var d as DateTime = datetime.FromString(rows.Column(“Data”))
Var s As String = d.ToString(Locale.Current, DateTime.FormatStyles.Short, DateTime.FormatStyles.None) and works well. I get the format I’m interested in, the one I use here in Italy: dd-mm-yyyy
Is there another way to achieve the same result while spending fewer resources?
At the moment I was able to read the dates in the format that interests me.
In the Database they are stored as Ex: 2024-10-31 00:00:00
and I read them in the Italian format with the function that I created and that I will use throughout the program:
ReadDataFromDB(DataRead as string) as string
Var d as DateTime = datetime.FromString(DateRead)
Var s As String = d.ToString(Locale.Current, DateTime.FormatStyles.Short, DateTime.FormatStyles.None)
return s
and I would also like to store dates from a text field written as 12/31/2024 in the format 12/31/2024 00:00:00 and I tried to write another function:
StoreDateInDB(DateRead as string) as datetime
Var d As String = DataRead
Var s As DateTime = DatetIme.FromString(d)