ghkweon / dwscript

Automatically exported from code.google.com/p/dwscript
0 stars 0 forks source link

Unhandled varInteger in dwsUIBDatabase.AssignParameters #415

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
In the script

var parQ : array of Variant := [algD, lopD+1];
parQ.Add(someVar);
var query := db.Query(sqlQ, parQ);

this results in error "Unsupported VarType 3". The items (variables algD, lopD 
and someVar) in parQ array are all integers returned from the host via an 
function which returns Variant. The fix is to add

      case p.VType of
         varInteger: rq.Params.AsInt64[i] := p.VInteger;

to AssignParameters in dwsUIBDatabase.pas but it seems that the Variants passed 
around should only contain one of the four base types, so the fact that 
varInteger "escaped into the wild" here is actually bug in somewhere else? If 
that's not the case then the AssignParameters should be updated to handle all 
the other var* types as well.

Original issue reported on code.google.com by ain.val...@gmail.com on 4 Jun 2013 at 2:20

GoogleCodeExporter commented 8 years ago
The four base types are for typed variables, if your variables are typed as 
Variant, other subtypes are allowed.

How are your variables defined?

Original comment by zar...@gmail.com on 4 Jun 2013 at 2:53

GoogleCodeExporter commented 8 years ago
Note that if you want to pass integers/floats/etc. specifically to the script, 
rather than explicitly a Variant, there are typed properties for assigning the 
values on the Delphi side (.ResultAsInteger, .ValueAsInteger[], etc.)

Original comment by zar...@gmail.com on 4 Jun 2013 at 2:56

GoogleCodeExporter commented 8 years ago
All three like this

var algD := Report.GetParamValue('Alates');

The Report.GetParamValue has ResultType := SYS_VARIANT (it is defined in an 
custom TdwsUnit descendant). And for these particular cases result is returned 
via Info.ResultAsVariant so thats from where the varInteger subtype "sneaks 
into script side". So the AssignParameters in dwsUIBDatabase.pas needs to be 
updated to hanlde more subtupes that the four "base types" it currently 
handles...

Original comment by ain.val...@gmail.com on 4 Jun 2013 at 3:04

GoogleCodeExporter commented 8 years ago
I've just noticed there is a Params.AsVariant[] in UIB and used it as fallback.

So the core types will have direct assignment, and other types will fallback to 
UIB's resolution mechanism.

Original comment by zar...@gmail.com on 5 Jun 2013 at 6:39