Why is Delphi (Zeos) giving me widestring fields in SQLite when I ask for unsigned big int?

前端 未结 3 879
走了就别回头了
走了就别回头了 2020-12-22 05:29

I am using the latest Zeos with SQLite 3. It is generally going well, converting from MySQL, once we made all the persistent integer field TLargeInt.

Bu

3条回答
  •  遥遥无期
    2020-12-22 06:33

    Zeos uses the following code (in ZDbcSqLiteUtils.pas) to determine a column's type:

    Result := stString;
    ...
    if StartsWith(TypeName, 'BOOL') then
      Result := stBoolean
    else if TypeName = 'TINYINT' then
      Result := stShort
    else if TypeName = 'SMALLINT' then
      Result := stShort
    else if TypeName = 'MEDIUMINT' then
      Result := stInteger
    else if TypeName = {$IFDEF UNICODE}RawByteString{$ENDIF}('INTEGER') then
      Result := stLong //http://www.sqlite.org/autoinc.html
    else if StartsWith(TypeName, {$IFDEF UNICODE}RawByteString{$ENDIF}('INT')) then
      Result := stInteger
    else if TypeName = 'BIGINT' then
      Result := stLong
    else if StartsWith(TypeName, 'REAL') then
      Result := stDouble
    else if StartsWith(TypeName, 'FLOAT') then
      Result := stDouble
    else if (TypeName = 'NUMERIC') or (TypeName = 'DECIMAL')
      or (TypeName = 'NUMBER') then
    begin
     { if Decimals = 0 then
        Result := stInteger
      else} Result := stDouble;
    end
    else if StartsWith(TypeName, 'DOUB') then
      Result := stDouble
    else if TypeName = 'MONEY' then
      Result := stBigDecimal
    else if StartsWith(TypeName, 'CHAR') then
      Result := stString
    else if TypeName = 'VARCHAR' then
      Result := stString
    else if TypeName = 'VARBINARY' then
      Result := stBytes
    else if TypeName = 'BINARY' then
      Result := stBytes
    else if TypeName = 'DATE' then
      Result := stDate
    else if TypeName = 'TIME' then
      Result := stTime
    else if TypeName = 'TIMESTAMP' then
      Result := stTimestamp
    else if TypeName = 'DATETIME' then
      Result := stTimestamp
    else if Pos('BLOB', TypeName) > 0 then
      Result := stBinaryStream
    else if Pos('CLOB', TypeName) > 0 then
      Result := stAsciiStream
    else if Pos('TEXT', TypeName) > 0 then
      Result := stAsciiStream;
    

    If your table uses any other type name, or if the SELECT output column is not a table column, then Zeos falls back to stString. There's nothing you can do about that; you'd have to read the values from the string field (and hope that the conversion to string and back does not lose any information).

    It might be a better idea to use some other library that does not assume that every database has fixed column types.

提交回复
热议问题