TFDQuery and SQLite: Type mismatch for field, expecting: LargeInt actual: WideString

前端 未结 1 443
一生所求
一生所求 2020-12-12 02:42

Using Delphi 10.2, SQLite and Teecharts. My SQLite database has two fields, created with:

CREATE TABLE HistoryRuntime         


        
相关标签:
1条回答
  • 2020-12-12 02:49

    This behavior is described in Adjusting FireDAC Mapping chapter of the FireDAC's SQLite manual:

    For an expression in a SELECT list, SQLite avoids type name information. When the result set is not empty, FireDAC uses the value data types from the first record. When empty, FireDAC describes those columns as dtWideString. To explicitly specify the column data type, append ::<type name> to the column alias:

    SELECT count(*) as "cnt::INT" FROM mytab

    So modify your command e.g. this way (I used BIGINT, but you can use any pseudo data type that maps to a 64-bit signed integer data type and is not auto incrementing, which corresponds to your persistent TLargeIntField field):

    SELECT
       DayTime AS "TheDate",
       Sum(Device1) AS "DeviceTotal::BIGINT"
    FROM
       HistoryRuntime 
    WHERE
       DayTime BETWEEN {d 2017-06-01} AND {d 2017-06-26}
    GROUP BY
       Date(DayTime)
    

    P.S. I did a small optimization by using BETWEEN operator (which evaluates the column value only once), and used an escape sequence for date constants (which, in real you replace by parameter, I guess; so just for curiosity).


    This data type hinting is parsed by the FDSQLiteTypeName2ADDataType procedure that takes and parses column name in format <column name>::<type name> in its AColName parameter.

    0 讨论(0)
提交回复
热议问题