The list of questions and answers related to sorting, searching, locating, filtering datasets.
A: To fix the issue, do the following:
{$define AnyDAC_NOLOCALE_DATA} // define, to use binary data comparision
{$define AnyDAC_NOLOCALE_META} // define, to use binary metadata comparison
Note: if you are only working with English (ASCII) texts, then ensure that the above lines are uncommented. That speedups sort and locate operations considerably.
A: You does not need to define Indexes, if you just need to order data. IndexFieldNames will work for you. Indexes allows to define the views, which are mix or filtering and ordering. Note, Indexes and IndexDefs are mutually exclusive for all AnyDAC datasets. That means - either you should fill Indexes or IndexDefs, but not both.
A: No, you cannot. But you can use in indexes internal calculated fields. For that add persistent fields, then add fkInternalCalc field, create OnCalcFields event handlers and calculate this field in event handler. For example:
procedure TForm21.ADTable1CalcFields(DataSet: TDataSet); begin DataSet.FieldByName('f_calc').AsString := ADMemTable2.Lookup('code', DataSet.FieldByName('f_code').AsInteger, 'name'); end;
A: Current AnyDAC release does not support fields with FieldKind = fkCalculated in Locate, Lookup, IndexFieldNames, etc. The workaround is to use fkInternalCalc fields.
A: The index must be selected, not just active. For that:
- set Indexes[i].Selected := True
- or set ADTable1.IndexFieldName := <name of your index>
A: In general there are 3 options:
In future we will implement custom collations. That will be usefull as for SQLite driver as for cases, like yours.
A: IndexFieldNames := 'col_1:D;col_2';
Also, check help file, chapter "TADDataSet.IndexFieldNames property".
A: It looks like ADQuery was opened after an explicit transaction start, then a transaction was commited. And then you are calling ADQuery.Locate. But not yet all records were fetched from ADQuery, but Locate imlicitly calls FetchAll. And it gives this error on SQL Server.
To avoid it do:
This is SQL Server behaviour - invalidate open cursors after Commit / Rollback.
A: If you does not need all records on the client, then use TADQuery with SELECT ... WHERE ....
A: Then set TADQuery.IndexFieldNames to LookupKeyFields, then AnyDAC will use client index to locate record in a lookup dataset.
If the number of unique key values in not high, then set LookupCache to True.
Q: I am using Delphi 2007 with AnyDac 2.0.11.895 on a Postgres database. When I try to filter on a DateTime field I can't seem to get an exact match with a value passed to it like this:
created_date = '8/10/2009 14:42:14' // or even... created_date = '8/10/2009 14:42:14.247' // ... the exact time with milisec
Instead I have to end up using something like this:
created_date >= '8/10/2009 14:42:14' AND created_date < '8/10/2009 14:42:15' or created_date >= '8/10/2009 14:42:14.000' AND created_date <= '8/10/2009 14:42:14.999'
But isn't pretty code.
A: The problem is that DBMS or DBMS API may round the time value. While a programmer expects to see the .247 as a fractional part, it may be .246 or how else. That is not AnyDAC failure, but it is how a DBMS is working.
You can round the time value to the seconds and compare that value with a constant without a fractional part:
uses
uADStanExprFuncs
...
ADQuery1.Filter = 'TimeStampDiff(''second'', created_date,
convert(''timestamp'', ''8/10/2009 14:42:14'')) = 0';|
What do you think about this topic? Send feedback!
|