Page 1 of 1
Firebird, unicode insert into
Posted: 18.03.2009, 16:03
by SlavoF
firebird-2.1 , RAD 2009
svn://zeos.firmos.at/zeos/trunk from 11.2.2009
Edit1.Text := 'ľščťžý';
ZTable1.FieldByName('Text1').AsString := Edit1.Text;
stored value is OK
ZSQLProcessor1.Params.CreateParam(FtString, 'T1', ptUnknown);
ZSQLProcessor1.ParamByName('T1').Value := Edit1.Text;
ZSQLProcessor1.Script.Text := 'INSERT INTO ZTable1 Values(:T1)';
ZSQLProcessor1.Execute;
stored value is OK
....
ZSQLProcessor1.Script.Text := 'INSERT INTO ZTable1 Values('+QuotedStr(Edit1.Text)+')';
....
stored value is NOT OK
Posted: 18.03.2009, 16:11
by seawolf
Posted: 18.03.2009, 16:13
by SlavoF
ee, no
Posted: 18.03.2009, 16:14
by SlavoF
pardon, sorry
yes tried
is NOT solve this
Posted: 18.03.2009, 16:23
by SlavoF
I have Unit ZdbcInterbase6Utils.pas in:
svn://zeos.firmos.at/zeos/trunk from 11.2.2009
with ..... UTF8String(SQL) ....
Posted: 18.03.2009, 16:38
by SlavoF
IBC component:
IBCSQL1.SQL.Text := 'insert into Table1 values('+QuotedStr(Edit1.Text)+')';
IBCSQL1.Execute;
in THE SAME DB, SAME PROJECT IS OK
Posted: 18.03.2009, 19:00
by seawolf
Open ZVariant.pas
go to
function TZSoftVariantManager.Convert(const Value: TZVariant;
NewType: TZVariantType): TZVariant;
begin
Result.VType := NewType;
case NewType of
vtBoolean:
case Value.VType of
vtNull:
Result.VBoolean := False;
vtBoolean:
Result.VBoolean := Value.VBoolean;
vtInteger:
Result.VBoolean := Value.VInteger <> 0;
vtFloat:
Result.VBoolean := Value.VFloat <> 0;
vtString:
Result.VBoolean := StrToBoolEx(Value.VString);
vtUnicodeString:
Result.VBoolean := StrToBoolEx(Value.VUnicodeString);
vtDateTime:
Result.VBoolean := Value.VDateTime <> 0;
vtPointer:
RaiseTypeMismatchError;
vtInterface:
RaiseTypeMismatchError;
end;
vtInteger:
case Value.VType of
vtNull:
Result.VInteger := 0;
vtBoolean:
if Value.VBoolean then
Result.VInteger := 1
else
Result.VInteger := 0;
vtInteger:
Result.VInteger := Value.VInteger;
vtFloat:
Result.VInteger := Trunc(Value.VFloat);
vtString:
Result.VInteger := StrToIntDef(Value.VString, 0);
vtUnicodeString:
Result.VInteger := StrToIntDef(Value.VUnicodeString, 0);
vtDateTime:
Result.VInteger := Trunc(Value.VDateTime);
vtPointer:
Result.VInteger := Integer(Value.VPointer);
vtInterface:
RaiseTypeMismatchError;
end;
vtFloat:
case Value.VType of
vtNull:
Result.VFloat := 0;
vtBoolean:
if Value.VBoolean then
Result.VFloat := 1
else
Result.VFloat := 0;
vtInteger:
Result.VFloat := Value.VInteger;
vtFloat:
Result.VFloat := Value.VFloat;
vtString:
Result.VFloat := SqlStrToFloatDef(Value.VString, 0);
vtUnicodeString:
Result.VFloat := SqlStrToFloatDef(Value.VUnicodeString, 0);
vtDateTime:
Result.VFloat := Value.VDateTime;
vtPointer:
RaiseTypeMismatchError;
vtInterface:
RaiseTypeMismatchError;
end;
vtString:
case Value.VType of
vtNull:
Result.VString := '';
vtBoolean:
if Value.VBoolean then
Result.VString := 'TRUE'
else
Result.VString := 'FALSE';
vtInteger:
Result.VString := IntToStr(Value.VInteger);
// gto: Not a real threat, as it's converting numbers (unicode safe)
vtFloat:
Result.VString := FloatToSqlStr(Value.VFloat);
// gto: Not a real threat, as it's converting numbers (unicode safe)
vtString:
{$IFDEF DELPHI12_UP}
Result.VString := UTF8String(Value.VString);
{$ELSE}
Result.VString := Value.VString;
{$ENDIF}
vtUnicodeString:
{$IFDEF DELPHI12_UP}
Result.VString := UTF8String(Value.VUnicodeString);
{$ELSE}
Result.VString := Value.VUnicodeString;
{$ENDIF}
vtDateTime:
Result.VString := DateTimeToAnsiSQLDate(Value.VDateTime);
// gto: Not a real threat, as it's converting dates (unicode safe)
vtPointer:
RaiseTypeMismatchError;
vtInterface:
RaiseTypeMismatchError;
end;
vtUnicodeString:
case Value.VType of
vtNull:
Result.VUnicodeString := '';
vtBoolean:
if Value.VBoolean then
Result.VUnicodeString := 'True'
else
Result.VUnicodeString := 'False';
vtInteger:
Result.VUnicodeString := IntToStr(Value.VInteger);
vtFloat:
Result.VUnicodeString := FloatToSqlStr(Value.VFloat);
vtString:
Result.VUnicodeString := Value.VString;
vtUnicodeString:
Result.VUnicodeString := Value.VUnicodeString;
vtDateTime:
Result.VUnicodeString := DateTimeToAnsiSQLDate(Value.VDateTime);
vtPointer:
RaiseTypeMismatchError;
vtInterface:
RaiseTypeMismatchError;
end;
vtDateTime:
case Value.VType of
vtNull:
Result.VDateTime := 0;
vtBoolean:
RaiseTypeMismatchError;
vtInteger:
Result.VDateTime := Value.VInteger;
vtFloat:
Result.VDateTime := Value.VFloat;
vtString:
Result.VDateTime := AnsiSQLDateToDateTime(Value.VString);
vtUnicodeString:
Result.VDateTime := AnsiSQLDateToDateTime(Value.VUnicodeString);
vtDateTime:
Result.VDateTime := Value.VDateTime;
vtPointer:
RaiseTypeMismatchError;
vtInterface:
RaiseTypeMismatchError;
end;
vtPointer:
case Value.VType of
vtNull:
Result.VPointer := nil;
vtBoolean:
RaiseTypeMismatchError;
vtInteger:
Result.VPointer := Pointer(Value.VInteger);
vtFloat:
RaiseTypeMismatchError;
vtString:
RaiseTypeMismatchError;
vtUnicodeString:
RaiseTypeMismatchError;
vtDateTime:
RaiseTypeMismatchError;
vtPointer:
Result.VPointer := Value.VPointer;
vtInterface:
RaiseTypeMismatchError;
end;
vtInterface:
case Value.VType of
vtNull:
Result.VInterface := nil;
vtBoolean:
RaiseTypeMismatchError;
vtInteger:
RaiseTypeMismatchError;
vtFloat:
RaiseTypeMismatchError;
vtString:
RaiseTypeMismatchError;
vtUnicodeString:
RaiseTypeMismatchError;
vtDateTime:
RaiseTypeMismatchError;
vtPointer:
RaiseTypeMismatchError;
vtInterface:
Result.VInterface := Value.VInterface;
end;
end;
end;
Posted: 18.03.2009, 19:55
by SlavoF
not solved
still bad
Posted: 18.03.2009, 20:05
by seawolf
Can you download lastest snapshot (601) and apply that change?
It works as expected to me
Posted: 19.03.2009, 15:44
by SlavoF
downloaded, applied, instaled - 100% ok
not work
TEST.zip from mscherr:
http://zeos.firmos.at/viewtopic.php?t=2266
not work
http://www.davidplus.sk/test/test.jpg
Posted: 19.03.2009, 22:25
by seawolf
I had you same error .. comparing Zeos trunk and my changes I found that:
Unit ZdbcInterbase6Utils.pas
function PrepareStatement(PlainDriver: IZInterbasePlainDriver;
Handle: PISC_DB_HANDLE; TrHandle: PISC_TR_HANDLE; Dialect: Word;
SQL: string; var StmtHandle: TISC_STMT_HANDLE):
TZIbSqlStatementType;
var
StatusVector: TARRAY_ISC_STATUS;
begin
{ Allocate an sql statement }
PlainDriver.isc_dsql_alloc_statement2(@StatusVector, Handle, @StmtHandle);
CheckInterbase6Error(PlainDriver, StatusVector, lcExecute, Sql);
{ Prepare an sql statement }
{$IFDEF DELPHI12_UP}
PlainDriver.isc_dsql_prepare(@StatusVector, TrHandle, @StmtHandle,
0, PAnsiChar(AnsiString(SQL)), Dialect, nil);
{$ELSE}
PlainDriver.isc_dsql_prepare(@StatusVector, TrHandle, @StmtHandle,
0, PAnsiChar(SQL), Dialect, nil);
{$ENDIF}
CheckInterbase6Error(PlainDriver, StatusVector, lcExecute, SQL);
Posted: 20.03.2009, 09:19
by SlavoF
bingo !!!!!!!
same bug as here:
http://zeos.firmos.at/viewtopic.php?t=2259
this solve also this problem:
http://zeos.firmos.at/viewtopic.php?t=2266
but,
NOT Try this:
... 0, PAnsiChar(UTF8String(SQL)), Dialect, nil); ....
Try this:
... 0, PAnsiChar(AnsiString(SQL)), Dialect, nil); ....
thanks seawolf, good work