zeos7 xe dbgrid sqlite 中文 新输入中文widestring正常. 但原来输入的中文ansistring 显示乱码 原因在于ZCompatibility中的ZDbcString进行了不恰当的编码,暂时注释掉即可浏览原来输入的中文ansistring, 但可能造成新的问题. function TZCachedResultSet.Fetch: Boolean; L1837 stString: RowAccessor.SetString(I, ResultSet.GetString(I)); unit ZDbcResultSet; function TZAbstractResultSet.GetString(ColumnIndex: Integer): String; begin Result := ZDbcString(InternalGetString(ColumnIndex));L637 改为Result :=(InternalGetString(ColumnIndex));正常 end; TZSQLiteResultSet.InternalGetString unit ZCompatibility; function TZCodePagedObject.ZDbcString(const Ansi: ZAnsiString; const Encoding: TZCharEncoding = ceDefault): String; var TempEncoding, UseEncoding: TZCharEncoding; begin if Encoding = ceDefault then if not Assigned(FConSettings.ClientCodePage) then raise Exception.Create('CodePage-Informations not Assigned!') else UseEncoding := FConSettings.ClientCodePage^.Encoding else UseEncoding := Encoding; {$IFNDEF UNICODE} if not FConSettings.AutoEncode and ( FConSettings.ClientCodePage^.Encoding = UseEncoding ) then Result := Ansi else {$ENDIF} begin TempEncoding := FConSettings.ClientCodePage^.Encoding; FConSettings.ClientCodePage^.Encoding := UseEncoding; Result := ZDbcString(Ansi, FConSettings);///////!!!!!!!!!!!!!! L534 修改了字符串 FConSettings.ClientCodePage^.Encoding := TempEncoding; end; end; function TZAbstractDatabaseMetadata.GetTypeInfo: IZResultSet; var Key: string; begin if not GetConnection.UseMetadata then begin Result := ConstructVirtualResultSet(TypeInfoColumnsDynArray); exit; end; Key := GetTypeInfoCacheKey; Result := GetResultSetFromCache(Key); if Result = nil then begin Result := UncachedGetTypeInfo; AddResultSetToCache(Key, Result); end; end; function TZSQLiteDatabaseMetadata.UncachedGetTypeInfo: IZResultSet; const MaxTypeCount = 22; TypeNames: array[1..MaxTypeCount] of string = ( 'BOOLEAN', 'TINYINT', 'SMALLINT', 'MEDIUMINT', 'INTEGER', 'BIGINT', 'REAL', 'FLOAT', 'NUMERIC', 'DECIMAL', 'NUMBER', 'DOUBLE', 'CHAR', 'VARCHAR', 'BINARY', 'VARBINARY', 'DATE', 'TIME', 'DATETIME', 'TIMESTAMP', 'BLOB', 'TEXT'); TypeCodes: array[1..MaxTypeCount] of TZSQLType = ( stBoolean, stByte, stShort, stInteger, stInteger, stLong, stFloat, stFloat, stDouble, stDouble, stDouble, stDouble, stString, {$IFDEF UNICODE}stUnicodeString{$ELSE}stString{$ENDIF}, stBytes, stBytes, stDate, stTime, stTimestamp, stTimestamp, stBinaryStream, {$IFDEF UNICODE}stUnicodeStream{$ELSE}stAsciiStream{$ENDIF}); TypePrecision: array[1..MaxTypeCount] of Integer = ( -1, 2, 4, 9, 9, 16, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, function TZAbstractRODataset.GetFieldData(Field: TField; {$IFDEF WITH_VAR_TVALUEBUFFER}var{$ENDIF}Buffer: {$IFDEF WITH_TVALUEBUFFER}TValueBuffer{$ELSE}Pointer{$ENDIF}; NativeFormat: Boolean): Boolean; begin if Field.DataType in [ftWideString] then NativeFormat := True; Result := inherited GetFieldData(Field, Buffer, NativeFormat); end; {** Retrieves the column value and stores it into the field buffer. @param Field an field object to be retrieved. @param Buffer a field value buffer. @return <code>True</code> if non-null value was retrieved. } function TZAbstractRODataset.GetFieldData(Field: TField; {$IFDEF WITH_VAR_TVALUEBUFFER}var{$ENDIF}Buffer: {$IFDEF WITH_TVALUEBUFFER}TValueBuffer{$ELSE}Pointer{$ENDIF}): Boolean; var ColumnIndex: Integer; RowBuffer: PZRowBuffer; ACurrency: Currency; {$IFNDEF WITH_WIDESTRUTILS} WS: WideString; {$ENDIF} begin if GetActiveBuffer(RowBuffer) then begin ColumnIndex := DefineFieldIndex(FieldsLookupTable, Field); RowAccessor.RowBuffer := RowBuffer; if Buffer <> nil then begin case Field.DataType of { Processes DateTime fields. } ftDate, ftTime, ftDateTime: begin if Field.DataType <> ftTime then begin DateTimeToNative(Field.DataType, RowAccessor.GetTimestamp(ColumnIndex, Result), Buffer); Result := not Result; end else begin DateTimeToNative(Field.DataType, RowAccessor.GetTime(ColumnIndex, Result), Buffer); Result := not Result; end; end; { Processes binary array fields. } ftBytes: begin System.Move((PAnsiChar(RowAccessor.GetColumnData(ColumnIndex, Result)) + 2)^, PAnsiChar(Buffer)^, RowAccessor.GetColumnDataSize(ColumnIndex)-2); Result := not Result; end; { Processes blob fields. } ftBlob, ftMemo, ftGraphic, ftFmtMemo {$IFDEF WITH_WIDEMEMO},ftWideMemo{$ENDIF} : Result := not RowAccessor.GetBlob(ColumnIndex, Result).IsEmpty; ftWideString: begin {$IFDEF WITH_WIDESTRUTILS} WStrCopy(PWideChar(Buffer), PWideChar(RowAccessor.GetUnicodeString(ColumnIndex, Result))); {$ELSE} //FPC: WideStrings are COM managed fields WS:=RowAccessor.GetUnicodeString(ColumnIndex, Result); //include null terminator in copy System.Move(PWideChar(WS)^,buffer^,(length(WS)+1)*sizeof(WideChar)); {$ENDIF} Result := not Result; end; {$IFDEF DELPHI12_UP} ftString: begin StrCopy(PAnsiChar(Buffer), PAnsiChar(AnsiString(RowAccessor.GetString(ColumnIndex, Result)))); Result := not Result; end; {$ENDIF} { Processes all other fields. } ftCurrency: begin {SizeOf(curreny) = 8Byte but SizeOf(Extented) = 10 Byte, so i need to convert the value} ACurrency := RowAccessor.GetBigDecimal(ColumnIndex, Result); System.Move(Pointer(@ACurrency)^, Pointer(Buffer)^, SizeOf(Currency)); Result := not Result; end; else begin System.Move(RowAccessor.GetColumnData(ColumnIndex, Result)^, Pointer(Buffer)^, RowAccessor.GetColumnDataSize(ColumnIndex)); Result := not Result; end; end; end else begin if Field.DataType in [ftBlob, ftMemo, ftGraphic, ftFmtMemo {$IFDEF WITH_WIDEMEMO},ftWideMemo{$ENDIF}] then Result := not RowAccessor.GetBlob(ColumnIndex, Result).IsEmpty else Result := not RowAccessor.IsNull(ColumnIndex); end; end else Result := False; end; |
|