I'm using Delphi XE2 with AnyDac Components and Advantage Database 10. In my code I'm using parametrized querys like this:
q.SQL.Text := 'SELECT * FROM Table1 ' +
'LEFT JOIN Table2 ON (Table1.ID = Table1 .ID_Table2) ' +
'WHERE ' +
':0 BETWEEN Table1.StartAm AND Table1.EndeAm ' +
'AND Table2 = :1';
q.Params[0].Value := AStartDateTime;
q.Params[1].Value := AIDRessourcenGruppe;
q.Open;
this ends up in an exception:
Exception der Klasse EADSNativeException mit der Meldung '[AnyDAC][Phys][ADS] Error 7200: AQE Error: State = 22018;
NativeError = 2112; [iAnywhere Solutions][Advantage SQL Engine]Assignment error' aufgetreten.
of course AStartDateTime is a valid delphi TDateTime value, AIDRessourcenGruppe is a integer value.
interestingly, these two variants work:
q.SQL.Text := 'SELECT * FROM Table1 ' +
'LEFT JOIN Table2 ON (Table1.ID = Table1 .ID_Table2) ' +
'WHERE ' +
':0 BETWEEN Table1.StartAm AND Table1.EndeAm ' +
'AND Table2 = :1';
q.Params[0].AsDateTime:= AStartDateTime;
q.Params[1].AsInteger:= AIDRessourcenGruppe;
q.Open;
-
q.SQL.Text := 'SELECT * FROM Table1 ' +
'LEFT JOIN Table2 ON (Table1.ID = Table1 .ID_Table2) ' +
'WHERE ' +
':SomeDate BETWEEN Table1.StartAm AND Table1.EndeAm ' +
'AND Table2 = :ID_PT_Ressourcengruppe';
q.ParamByName('SomeDate').Value := AStartDateTime;
q.ParamByName('ID_PT_Ressourcengruppe').Value := AIDRessourcenGruppe;
q.Open;
Do I miss something? Thanks for any help!
AsTypecasting ? It's better readable and you can be sure the internal mechanism of query parameter builder will handle the values properly. I don't know AnyDAC, but if they take this from Delphi, then theValueis of typeVariantwhat doesn't bring you nothing safe in my view...qcoming from? Your last variant usesdm1.qCustom, your other two useq. How isqdeclared? Can you show us the declaration of both parameters. When you say it is a valid datetime, for all we know, AStartDateTime is declared as string with '01-01-2012' as value. Why the change from:0as parameter to:SomeDate?Varianttype to the query at all. The same probably happens also to indexed access to parameters, because, I think, it doesn't internally determine the data type of the parameters, whilst the named access does. And, I can't see anything professional usingValuein this case, using indexed way yes (because it's faster), but using directAsTypetypecast beforeVariantalways wins for me (you can't mismatch parameters).