Filtering Dates in FireDac TTable - mysql

I'm having a problem using TTable in FireDac to filter on a date field.
The database in MySQL/InnoDB. The field is of type Date.
The code I am using to set the filter is
Filter := 'date = ' + QuotedStr(FormatDateTime('mm/dd/yyyy', Date));
Filtered := True;
Every time I either get an error when setting the filter: "EConvertError with message 'Could not parse SQL TimeStamp string'" or the filter fails to find any records.
The above format is for my current regional settings. I've also tried 'yyyy-mm-dd'. And I've tried both both with and without quotes.

So, I spend three hours on this and immediately after I ask the question I find an answer. Use Preprocessor Commands:
Filter := 'date = {d ' + (FormatDateTime('yyyy-mm-dd', Date))+'}';

Related

Set timestamp column in DB2 table using SSIS

I am trying to create an update command expression in expression builder to update the timestamp field.
#[User::FinalSQLPolicy] = "UPDATE ZDBA.ACE_POLICY_XREF SET APX_ACE_POLICY_NBR= '"+ #[User::CNTRCTID] +"',APX_LAST_MAINT_TMSP=' GETDATE() ' where APX_PRS_POLICY_NBR='"+ #[User::APXPRSPOLICYNBR] +"'"
APX_LAST_MAINT_TMSP is the field i want to store the current timestamp.
I am getting error like below
Expression cannot be evaluated.
Attempt to parse the expression " "UPDATE ZDBA.ACE_POLICY_XREF SET
APX_ACE_POLICY_NBR= '"+ #[User::CNTRCTID] +"',APX_LAST_MAINT_TMSP='"
GETDATE()" ' where APX_PRS_POLICY_NBR='"+ #[User::APXPRSPOLICYNBR]
+"'"" failed. The expression might contain an invalid token, an incomplete token, or an invalid element. It might not be well-formed,
or might be missing part of a required element such as a parenthesis.
Can anyone help me to correct the above expression?
Use the CURRENT_TIMESTAMP function, which is equivalent of the datetime date type of GETDATE(). DB2 also has CURRENT_DATE and CURRENT_TIME functions, which return the current date (YYYYMMDD) and time (HHMMSS) respectively. More details on these can be found in the documentation here.

Delphi XE7 MultiDevice SQL Error TIMESTAMP Ret. Field

I've an SQLTIMESTAMP binded (SQL output of query from datamodule)
(On live bindings) -> BindVIsually TTMFSMXGRID.
When I open the query, the field is correctly filled in the grid (EX: 06/05/2016, etc)
But when I try to take the Cell[x,y] as StringToSqltimestamp it come back in a different format (WRONG FORMAT). And I am trying to use field for a query so it make me an error (EOF) because don't find anything in that date.
dm1.UpdMsg.ParamByName('data').AsSQLTimeStamp:=StrToSQLTimeStamp(GrRec.Cells[1,GrRec.FocusedCell.Row]);
Any idea about how to solve it?
Like other date/time formatting functions, StrToSqlTimeStamp() by default uses formatting criteria based on the current system locale. If that does not match what you need (for example, maybe the day and month are swapped), you can use the overloaded version that accepts a TFormatSettings as input so you can customize it.
var
Fmt: TFormatSettings;
begin
// Get default settings first...
Fmt := TFormatSettings.Create;
// customize Fmt as needed...
Fmt.ShortDateFormat := 'dd/mm/yyyy';
Fmt.DateSeparator := '/';
// not convert...
dm1.UpdMsg.ParamByName('data').AsSQLTimeStamp := StrToSQLTimeStamp(GrRec.Cells[1,GrRec.FocusedCell.Row], Fmt);
end;

Node.js Updating MySql timestamp

So i do a simple query like so:
connection.query("UPDATE workers SET timestamp='"+thedate+"' WHERE id = " + id,function(err,upres){
connection.release();
if(!err) {
console.log('updated record')
console.log(upres);
}
})
console.log reveals the data format as: 2015-04-02 19:29:14
And if i debug the SQL statement, that turns out to be:
UPDATE workers SET timestamp='2015-04-02 21:31:16' WHERE id = 3;
However, when i list the data, the output is:
[{"id":3,"worker":"John Doe","timestamp":"2015-04-01T22:00:00.000Z","duration":30}]
This is way off compared to the time that is being reported?
What is causing this?
You do not know how MySQL is turning your VARCHAR into a date. There are a lot of configuration options. It would be better to use the STR_TO_DATE function to circumvent all of the assumptions. Here is a link to the docs for STR_TO_DATE().
As a side note, I would strongly recommend using prepared statements as a way to safeguard your application against errors and sql injection.
EDITS:
In regards to your questions, the column could be DATETIME, but your value you are assigning is a VARCHAR
'UPDATE workers SET timestamp = ? WHERE id = ?', ['4/2/2015 3:00:00 PM', 3'], [callBackFunction]
Based on what you said about the conversion not working, I am suspicious about the data type for the timestamp column.
SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE NAME = 'workers'
A statement like that should give you all of the information about that column. You could also find this in a GUI, if you have access. There are three different date types in MySQL date, datetime, or timestamp. This is most likely a DATE column, that will not be able to hold the time.

How to find out the changes happened for all objects

How I can find out the changes happened in database like modifying functions, table indexes, procedures and adding or removing columns.
Here in this query
select * from sys.objects
where type IS NOT NULL
and modify_date between '2013-07-21' and '2013-07-29'
but here I am getting created objects list and modifying list, but if I deleted any object it is not showing anything.
How can I get the all the changes happened in database between specific dates?
Try a source control solution for SQL. I've used RedGate's SQL Source Control before, and it records a history of changes like this, including who made the change, and what was changed.
http://www.red-gate.com/products/sql-development/sql-source-control/
It's a bit expensive, but it's good. I don't know if there's a way to do it (especially deletions) just with SQL itself.
Many of these incidents are recorded in the default trace.
DECLARE #path NVARCHAR(260);
SELECT
#path = REVERSE(SUBSTRING(REVERSE([path]),
CHARINDEX(CHAR(92), REVERSE([path])), 260)) + N'log.trc'
FROM sys.traces
WHERE is_default = 1;
SELECT
LoginName,
HostName,
StartTime,
ObjectName,
TextData -- may or may not be populated
FROM sys.fn_trace_gettable(#path, DEFAULT)
WHERE EventClass IN
(
164, -- object:altered
46, -- object:created
47 -- object:deleted
)
AND StartTime >= '20130721' AND StartTime < '20130730';
Why you should never use BETWEEN for date range queries.

DST to UTC append query creates a type conversion error in access

I have a table I'm using as a source for an append query that calls upon a table query, which calls upon a union query to effectively adjust the eastern prevailing time to spring forward and fall back while converting to utc. there are only three fields in the table but I keep getting "access did not import .... due to type conversion". Please Help Me out!!! Thank you in advance
below is the access sql:
{append query}
INSERT INTO somePrice ( price )
SELECT DTQuery.Price
FROM DTQuery
WHERE (((DTQuery.EPT)<>[2ndsunday]));
{DTQuery}
SELECT
TransposeQuery.Field3 AS [Zone]
, DateSerial(Left([field1],4),Left(Right([field1],4),2),Right([field1],2))+[TransposeQuery]![Hour]/24 AS EPT, Val([Field8]) AS Price
, DateValue(DateSerial(Year([EPT]),3,14))-(Weekday(DateValue(DateSerial(Year([EPT]),3,14)),1)-1)+3/24 AS 2ndSunday
, DateValue(DateSerial(Year([EPT]),11,7))-(Weekday(DateValue(DateSerial(Year([EPT]),11,7)),1)-1)+3/24 AS 1stSunday
FROM TransposeQuery
ORDER BY
TransposeQuery.Field3
, DateSerial(Left([field1],4),Left(Right([field1],4),2),Right([field1],2))+[TransposeQuery]![Hour]/24, Val([Field8]);
First some general stuff: If you want to convert between timezones, which involves adding or subtracting a number of hours you might want to use to DateAdd function.
DateAdd("h", -2, [SourceDateTime])
This simply takes two hours off the SourceDateTime field.
Also rather than using the Left(Right( combination you can use Mid(string, start, length)
Mid("1234567890", 2, 4)
Returns 2345, but if you are dealing with dates just use DatePart
DatePart("h", "17/12/2011 08:10")
Returns 8.
As for the type conversion error, it's hard to say as you haven't given us the types of the fields in the destination table.
If you run the append query without the first line this will rule out the destination table. If it still fails then it might be in the where clause, so move the fields into the results set and make sure they are the same type. If it still fails then it must be in the source query so check DTQuery opens without any problems.