ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/branches/udr/client/FBSQLData.pas
(Generate patch)

Comparing ibx/trunk/fbintf/client/FBSQLData.pas (file contents):
Revision 47 by tony, Mon Jan 9 15:31:51 2017 UTC vs.
Revision 287 by tony, Thu Apr 11 08:51:23 2019 UTC

# Line 60 | Line 60
60   {                                                                        }
61   {************************************************************************}
62   unit FBSQLData;
63 + {$IFDEF MSWINDOWS}
64 + {$DEFINE WINDOWS}
65 + {$ENDIF}
66  
67   {$IFDEF FPC}
68 < {$mode objfpc}{$H+}
68 > {$mode delphi}
69   {$codepage UTF8}
70   {$interfaces COM}
71   {$ENDIF}
# Line 73 | Line 76 | unit FBSQLData;
76    methods are needed for SQL parameters only. The string getters and setters
77    are virtual as SQLVar and Array encodings of string data is different.}
78  
76 { $define ALLOWDIALECT3PARAMNAMES}
77
78 {$ifndef ALLOWDIALECT3PARAMNAMES}
79
80 { Note on SQL Dialects and SQL Parameter Names
81  --------------------------------------------
82
83  Even when dialect 3 quoted format parameter names are not supported, IBX still processes
84  parameter names case insensitive. This does result in some additional overhead
85  due to a call to "AnsiUpperCase". This can be avoided by undefining
86  "UseCaseInSensitiveParamName" below.
87
88  Note: do not define "UseCaseSensitiveParamName" when "ALLOWDIALECT3PARAMNAMES"
89  is defined. This will not give a useful result.
90 }
91 {$define UseCaseInSensitiveParamName}
92 {$endif}
79  
80   interface
81  
82   uses
83 <  Classes, SysUtils, IBExternals, IBHeader, IB,  FBActivityMonitor;
83 >  Classes, SysUtils, IBExternals, IBHeader, IB,  FBActivityMonitor, FBClientAPI;
84  
85   type
86  
# Line 102 | Line 88 | type
88  
89    TSQLDataItem = class(TFBInterfacedObject)
90    private
91 +     FFirebirdClientAPI: TFBClientAPI;
92       function AdjustScale(Value: Int64; aScale: Integer): Double;
93       function AdjustScaleToInt64(Value: Int64; aScale: Integer): Int64;
94       function AdjustScaleToCurrency(Value: Int64; aScale: Integer): Currency;
95 +     function GetTimestampFormatStr: AnsiString;
96 +     function GetDateFormatStr(IncludeTime: boolean): AnsiString;
97 +     function GetTimeFormatStr: AnsiString;
98       procedure SetAsInteger(AValue: Integer);
99    protected
100       function AdjustScaleFromCurrency(Value: Currency; aScale: Integer): Int64;
# Line 113 | Line 103 | type
103       function GetSQLDialect: integer; virtual; abstract;
104       procedure Changed; virtual;
105       procedure Changing; virtual;
106 <     procedure InternalSetAsString(Value: String); virtual;
107 <     function SQLData: PChar; virtual; abstract;
106 >     procedure InternalSetAsString(Value: AnsiString); virtual;
107 >     function SQLData: PByte; virtual; abstract;
108       function GetDataLength: cardinal; virtual; abstract;
109       function GetCodePage: TSystemCodePage; virtual; abstract;
110       function getCharSetID: cardinal; virtual; abstract;
111 <     function Transliterate(s: string; CodePage: TSystemCodePage): RawByteString;
111 >     function Transliterate(s: AnsiString; CodePage: TSystemCodePage): RawByteString;
112       procedure SetScale(aValue: integer); virtual;
113       procedure SetDataLength(len: cardinal); virtual;
114       procedure SetSQLType(aValue: cardinal); virtual;
115       property DataLength: cardinal read GetDataLength write SetDataLength;
116  
117    public
118 +     constructor Create(api: TFBClientAPI);
119       function GetSQLType: cardinal; virtual; abstract;
120 <     function GetSQLTypeName: string; overload;
121 <     class function GetSQLTypeName(SQLType: short): string; overload;
122 <     function GetName: string; virtual; abstract;
120 >     function GetSQLTypeName: AnsiString; overload;
121 >     class function GetSQLTypeName(SQLType: short): AnsiString; overload;
122 >     function GetName: AnsiString; virtual; abstract;
123       function GetScale: integer; virtual; abstract;
124       function GetAsBoolean: boolean;
125       function GetAsCurrency: Currency;
# Line 140 | Line 131 | type
131       function GetAsPointer: Pointer;
132       function GetAsQuad: TISC_QUAD;
133       function GetAsShort: short;
134 <     function GetAsString: String; virtual;
134 >     function GetAsString: AnsiString; virtual;
135       function GetIsNull: Boolean; virtual;
136 <     function getIsNullable: boolean; virtual;
136 >     function GetIsNullable: boolean; virtual;
137       function GetAsVariant: Variant;
138       function GetModified: boolean; virtual;
139 +     function GetDateTimeStrLength(DateTimeFormat: TIBDateTimeFormats): integer;
140       procedure SetAsBoolean(AValue: boolean); virtual;
141       procedure SetAsCurrency(Value: Currency); virtual;
142       procedure SetAsInt64(Value: Int64); virtual;
# Line 157 | Line 149 | type
149       procedure SetAsPointer(Value: Pointer);
150       procedure SetAsQuad(Value: TISC_QUAD);
151       procedure SetAsShort(Value: short); virtual;
152 <     procedure SetAsString(Value: String); virtual;
152 >     procedure SetAsString(Value: AnsiString); virtual;
153       procedure SetAsVariant(Value: Variant);
154 +     procedure SetAsNumeric(Value: Int64; aScale: integer);
155       procedure SetIsNull(Value: Boolean); virtual;
156       procedure SetIsNullable(Value: Boolean); virtual;
157 <     procedure SetName(aValue: string); virtual;
157 >     procedure SetName(aValue: AnsiString); virtual;
158       property AsDate: TDateTime read GetAsDateTime write SetAsDate;
159       property AsBoolean:boolean read GetAsBoolean write SetAsBoolean;
160       property AsTime: TDateTime read GetAsDateTime write SetAsTime;
# Line 175 | Line 168 | type
168       property AsPointer: Pointer read GetAsPointer write SetAsPointer;
169       property AsQuad: TISC_QUAD read GetAsQuad write SetAsQuad;
170       property AsShort: short read GetAsShort write SetAsShort;
171 <     property AsString: String read GetAsString write SetAsString;
171 >     property AsString: AnsiString read GetAsString write SetAsString;
172       property AsVariant: Variant read GetAsVariant write SetAsVariant;
173       property Modified: Boolean read getModified;
174       property IsNull: Boolean read GetIsNull write SetIsNull;
# Line 192 | Line 185 | type
185  
186    TSQLDataArea = class
187    private
188 +    FCaseSensitiveParams: boolean;
189      function GetColumn(index: integer): TSQLVarData;
190      function GetCount: integer;
191    protected
192 <    FUniqueRelationName: string;
192 >    FUniqueRelationName: AnsiString;
193      FColumnList: array of TSQLVarData;
194      function GetStatement: IStatement; virtual; abstract;
195      function GetPrepareSeqNo: integer; virtual; abstract;
# Line 205 | Line 199 | type
199    public
200      procedure Initialize; virtual;
201      function IsInputDataArea: boolean; virtual; abstract; {Input to Database}
202 <    procedure PreprocessSQL(sSQL: string; GenerateParamNames: boolean;
203 <      var sProcessedSQL: string);
202 >    procedure PreprocessSQL(sSQL: AnsiString; GenerateParamNames: boolean;
203 >      var sProcessedSQL: AnsiString);
204      function ColumnsInUseCount: integer; virtual;
205 <    function ColumnByName(Idx: string): TSQLVarData;
205 >    function ColumnByName(Idx: AnsiString): TSQLVarData;
206      function CheckStatementStatus(Request: TStatementStatus): boolean; virtual; abstract;
207      procedure GetData(index: integer; var IsNull: boolean; var len: short;
208 <      var data: PChar); virtual;
208 >      var data: PByte); virtual;
209      procedure RowChange;
210      function StateChanged(var ChangeSeqNo: integer): boolean; virtual; abstract;
211 +    property CaseSensitiveParams: boolean read FCaseSensitiveParams
212 +                                            write FCaseSensitiveParams; {Only used when IsInputDataArea true}
213      property Count: integer read GetCount;
214      property Column[index: integer]: TSQLVarData read GetColumn;
215 <    property UniqueRelationName: string read FUniqueRelationName;
215 >    property UniqueRelationName: AnsiString read FUniqueRelationName;
216      property Statement: IStatement read GetStatement;
217      property PrepareSeqNo: integer read GetPrepareSeqNo;
218      property TransactionSeqNo: integer read GetTransactionSeqNo;
# Line 227 | Line 223 | type
223    TSQLVarData = class
224    private
225      FParent: TSQLDataArea;
226 <    FName: string;
226 >    FName: AnsiString;
227      FIndex: integer;
228      FModified: boolean;
229      FUniqueName: boolean;
230      FVarString: RawByteString;
231      function GetStatement: IStatement;
232 <    procedure SetName(AValue: string);
232 >    procedure SetName(AValue: AnsiString);
233    protected
234      function GetSQLType: cardinal; virtual; abstract;
235      function GetSubtype: integer; virtual; abstract;
236 <    function GetAliasName: string;  virtual; abstract;
237 <    function GetFieldName: string; virtual; abstract;
238 <    function GetOwnerName: string;  virtual; abstract;
239 <    function GetRelationName: string;  virtual; abstract;
236 >    function GetAliasName: AnsiString;  virtual; abstract;
237 >    function GetFieldName: AnsiString; virtual; abstract;
238 >    function GetOwnerName: AnsiString;  virtual; abstract;
239 >    function GetRelationName: AnsiString;  virtual; abstract;
240      function GetScale: integer; virtual; abstract;
241      function GetCharSetID: cardinal; virtual; abstract;
242      function GetCodePage: TSystemCodePage; virtual; abstract;
243      function GetIsNull: Boolean;   virtual; abstract;
244      function GetIsNullable: boolean; virtual; abstract;
245 <    function GetSQLData: PChar;  virtual; abstract;
245 >    function GetSQLData: PByte;  virtual; abstract;
246      function GetDataLength: cardinal; virtual; abstract;
247      procedure SetIsNull(Value: Boolean); virtual; abstract;
248      procedure SetIsNullable(Value: Boolean);  virtual; abstract;
249 <    procedure SetSQLData(AValue: PChar; len: cardinal); virtual; abstract;
249 >    procedure SetSQLData(AValue: PByte; len: cardinal); virtual; abstract;
250      procedure SetScale(aValue: integer); virtual; abstract;
251      procedure SetDataLength(len: cardinal); virtual; abstract;
252      procedure SetSQLType(aValue: cardinal); virtual; abstract;
253      procedure SetCharSetID(aValue: cardinal); virtual; abstract;
254    public
255      constructor Create(aParent: TSQLDataArea; aIndex: integer);
256 <    procedure SetString(aValue: string);
256 >    procedure SetString(aValue: AnsiString);
257      procedure Changed; virtual;
258      procedure RowChange; virtual;
259      function GetAsArray(Array_ID: TISC_QUAD): IArray; virtual; abstract;
# Line 268 | Line 264 | type
264      procedure Initialize; virtual;
265  
266    public
267 <    property AliasName: string read GetAliasName;
268 <    property FieldName: string read GetFieldName;
269 <    property OwnerName: string read GetOwnerName;
270 <    property RelationName: string read GetRelationName;
267 >    property AliasName: AnsiString read GetAliasName;
268 >    property FieldName: AnsiString read GetFieldName;
269 >    property OwnerName: AnsiString read GetOwnerName;
270 >    property RelationName: AnsiString read GetRelationName;
271      property Parent: TSQLDataArea read FParent;
272      property Index: integer read FIndex;
273 <    property Name: string read FName write SetName;
273 >    property Name: AnsiString read FName write SetName;
274      property CharSetID: cardinal read GetCharSetID write SetCharSetID;
275      property SQLType: cardinal read GetSQLType write SetSQLType;
276      property SQLSubtype: integer read GetSubtype;
277 <    property SQLData: PChar read GetSQLData;
277 >    property SQLData: PByte read GetSQLData;
278      property DataLength: cardinal read GetDataLength write SetDataLength;
279      property IsNull: Boolean read GetIsNull write SetIsNull;
280      property IsNullable: Boolean read GetIsNullable write SetIsNullable;
# Line 300 | Line 296 | type
296      FChangeSeqNo: integer;
297    protected
298      procedure CheckActive; override;
299 <    function SQLData: PChar; override;
299 >    function SQLData: PByte; override;
300      function GetDataLength: cardinal; override;
301      function GetCodePage: TSystemCodePage; override;
302  
# Line 315 | Line 311 | type
311      function GetIndex: integer;
312      function GetSQLType: cardinal; override;
313      function getSubtype: integer;
314 <    function getRelationName: string;
315 <    function getOwnerName: string;
316 <    function getSQLName: string;    {Name of the column}
317 <    function getAliasName: string;  {Alias Name of column or Column Name if not alias}
318 <    function GetName: string; override;      {Disambiguated uppercase Field Name}
314 >    function getRelationName: AnsiString;
315 >    function getOwnerName: AnsiString;
316 >    function getSQLName: AnsiString;    {Name of the column}
317 >    function getAliasName: AnsiString;  {Alias Name of column or Column Name if not alias}
318 >    function GetName: AnsiString; override;      {Disambiguated uppercase Field Name}
319      function GetScale: integer; override;
320      function getCharSetID: cardinal; override;
321      function GetIsNullable: boolean; override;
322      function GetSize: cardinal;
323      function GetArrayMetaData: IArrayMetaData;
324      function GetBlobMetaData: IBlobMetaData;
325 <    property Name: string read GetName;
325 >    property Name: AnsiString read GetName;
326      property Size: cardinal read GetSize;
327      property CharSetID: cardinal read getCharSetID;
328      property SQLSubtype: integer read getSubtype;
# Line 343 | Line 339 | type
339      function GetAsArray: IArray;
340      function GetAsBlob: IBlob; overload;
341      function GetAsBlob(BPB: IBPB): IBlob; overload;
342 <    function GetAsString: String; override;
342 >    function GetAsString: AnsiString; override;
343      property AsBlob: IBlob read GetAsBlob;
344   end;
345  
# Line 353 | Line 349 | type
349    protected
350      procedure CheckActive; override;
351      procedure Changed; override;
352 <    procedure InternalSetAsString(Value: String); override;
352 >    procedure InternalSetAsString(Value: AnsiString); override;
353      procedure SetScale(aValue: integer); override;
354      procedure SetDataLength(len: cardinal); override;
355      procedure SetSQLType(aValue: cardinal); override;
# Line 361 | Line 357 | type
357      procedure Clear;
358      function GetModified: boolean; override;
359      function GetAsPointer: Pointer;
360 <    procedure SetName(Value: string); override;
360 >    procedure SetName(Value: AnsiString); override;
361      procedure SetIsNull(Value: Boolean);  override;
362      procedure SetIsNullable(Value: Boolean); override;
363      procedure SetAsArray(anArray: IArray);
# Line 378 | Line 374 | type
374      procedure SetAsFloat(AValue: Float);
375      procedure SetAsPointer(AValue: Pointer);
376      procedure SetAsShort(AValue: Short);
377 <    procedure SetAsString(AValue: String); override;
377 >    procedure SetAsString(AValue: AnsiString); override;
378      procedure SetAsVariant(AValue: Variant);
379      procedure SetAsBlob(aValue: IBlob);
380      procedure SetAsQuad(AValue: TISC_QUAD);
# Line 401 | Line 397 | type
397      destructor Destroy; override;
398    public
399      {IMetaData}
400 <    function GetUniqueRelationName: string;
400 >    function GetUniqueRelationName: AnsiString;
401      function getCount: integer;
402      function getColumnMetaData(index: integer): IColumnMetaData;
403 <    function ByName(Idx: String): IColumnMetaData;
403 >    function ByName(Idx: AnsiString): IColumnMetaData;
404    end;
405  
406    { TSQLParams }
# Line 423 | Line 419 | type
419      {ISQLParams}
420      function getCount: integer;
421      function getSQLParam(index: integer): ISQLParam;
422 <    function ByName(Idx: String): ISQLParam ;
422 >    function ByName(Idx: AnsiString): ISQLParam ;
423      function GetModified: Boolean;
424 +    function GetHasCaseSensitiveParams: Boolean;
425    end;
426  
427    { TResults }
# Line 443 | Line 440 | type
440       constructor Create(aResults: TSQLDataArea);
441        {IResults}
442       function getCount: integer;
443 <     function ByName(Idx: String): ISQLData;
443 >     function ByName(Idx: AnsiString): ISQLData;
444       function getSQLData(index: integer): ISQLData;
445 <     procedure GetData(index: integer; var IsNull:boolean; var len: short; var data: PChar);
445 >     procedure GetData(index: integer; var IsNull:boolean; var len: short; var data: PByte);
446       function GetTransaction: ITransaction; virtual;
447       procedure SetRetainInterfaces(aValue: boolean);
448   end;
449  
450   implementation
451  
452 < uses FBMessages, FBClientAPI, variants, IBUtils, FBTransaction;
452 > uses FBMessages, variants, IBUtils, FBTransaction, DateUtils;
453  
454   { TSQLDataArea }
455  
# Line 472 | Line 469 | procedure TSQLDataArea.SetUniqueRelation
469   var
470    i: Integer;
471    bUnique: Boolean;
472 <  RelationName: string;
472 >  RelationName: AnsiString;
473   begin
474    bUnique := True;
475    for i := 0 to ColumnsInUseCount - 1 do
# Line 503 | Line 500 | begin
500      Column[i].Initialize;
501   end;
502  
503 < procedure TSQLDataArea.PreprocessSQL(sSQL: string; GenerateParamNames: boolean;
504 <  var sProcessedSQL: string);
508 < var
509 <  cCurChar, cNextChar, cQuoteChar: Char;
510 <  sParamName: String;
511 <  j, i, iLenSQL, iSQLPos: Integer;
512 <  iCurState {$ifdef ALLOWDIALECT3PARAMNAMES}, iCurParamState {$endif}: Integer;
513 <  iParamSuffix: Integer;
514 <  slNames: TStrings;
515 <  StrBuffer: PChar;
516 <  found: boolean;
517 <
518 < const
519 <  DefaultState = 0;
520 <  CommentState = 1;
521 <  QuoteState = 2;
522 <  ParamState = 3;
523 <  ArrayDimState = 4;
524 < {$ifdef ALLOWDIALECT3PARAMNAMES}
525 <  ParamDefaultState = 0;
526 <  ParamQuoteState = 1;
527 <  {$endif}
528 <
529 <  procedure AddToProcessedSQL(cChar: Char);
530 <  begin
531 <    StrBuffer[iSQLPos] := cChar;
532 <    Inc(iSQLPos);
533 <  end;
534 <
535 < begin
536 <  if not IsInputDataArea then
537 <    IBError(ibxeNotPermitted,[nil]);
538 <
539 <  sParamName := '';
540 <  iLenSQL := Length(sSQL);
541 <  GetMem(StrBuffer,iLenSQL + 1);
542 <  slNames := TStringList.Create;
543 <  try
544 <    { Do some initializations of variables }
545 <    iParamSuffix := 0;
546 <    cQuoteChar := '''';
547 <    i := 1;
548 <    iSQLPos := 0;
549 <    iCurState := DefaultState;
550 <    {$ifdef ALLOWDIALECT3PARAMNAMES}
551 <    iCurParamState := ParamDefaultState;
552 <    {$endif}
553 <    { Now, traverse through the SQL string, character by character,
554 <     picking out the parameters and formatting correctly for InterBase }
555 <    while (i <= iLenSQL) do begin
556 <      { Get the current token and a look-ahead }
557 <      cCurChar := sSQL[i];
558 <      if i = iLenSQL then
559 <        cNextChar := #0
560 <      else
561 <        cNextChar := sSQL[i + 1];
562 <      { Now act based on the current state }
563 <      case iCurState of
564 <        DefaultState:
565 <        begin
566 <          case cCurChar of
567 <            '''', '"':
568 <            begin
569 <              cQuoteChar := cCurChar;
570 <              iCurState := QuoteState;
571 <            end;
572 <            '?', ':':
573 <            begin
574 <              iCurState := ParamState;
575 <              AddToProcessedSQL('?');
576 <            end;
577 <            '/': if (cNextChar = '*') then
578 <            begin
579 <              AddToProcessedSQL(cCurChar);
580 <              Inc(i);
581 <              iCurState := CommentState;
582 <            end;
583 <            '[':
584 <            begin
585 <              AddToProcessedSQL(cCurChar);
586 <              Inc(i);
587 <              iCurState := ArrayDimState;
588 <            end;
589 <          end;
590 <        end;
503 > procedure TSQLDataArea.PreprocessSQL(sSQL: AnsiString; GenerateParamNames: boolean;
504 >  var sProcessedSQL: AnsiString);
505  
506 <        ArrayDimState:
593 <        begin
594 <          case cCurChar of
595 <          ':',',','0'..'9',' ',#9,#10,#13:
596 <            begin
597 <              AddToProcessedSQL(cCurChar);
598 <              Inc(i);
599 <            end;
600 <          else
601 <            begin
602 <              AddToProcessedSQL(cCurChar);
603 <              Inc(i);
604 <              iCurState := DefaultState;
605 <            end;
606 <          end;
607 <        end;
506 > var slNames: TStrings;
507  
508 <        CommentState:
509 <        begin
510 <          if (cNextChar = #0) then
511 <            IBError(ibxeSQLParseError, [SEOFInComment])
512 <          else if (cCurChar = '*') then begin
614 <            if (cNextChar = '/') then
615 <              iCurState := DefaultState;
616 <          end;
617 <        end;
618 <        QuoteState: begin
619 <          if cNextChar = #0 then
620 <            IBError(ibxeSQLParseError, [SEOFInString])
621 <          else if (cCurChar = cQuoteChar) then begin
622 <            if (cNextChar = cQuoteChar) then begin
623 <              AddToProcessedSQL(cCurChar);
624 <              Inc(i);
625 <            end else
626 <              iCurState := DefaultState;
627 <          end;
628 <        end;
629 <        ParamState:
630 <        begin
631 <          { collect the name of the parameter }
632 <          {$ifdef ALLOWDIALECT3PARAMNAMES}
633 <          if iCurParamState = ParamDefaultState then
634 <          begin
635 <            if cCurChar = '"' then
636 <              iCurParamState := ParamQuoteState
637 <            else
638 <            {$endif}
639 <            if (cCurChar in ['A'..'Z', 'a'..'z', '0'..'9', '_', '$']) then
640 <                sParamName := sParamName + cCurChar
641 <            else if GenerateParamNames then
642 <            begin
643 <              sParamName := 'IBXParam' + IntToStr(iParamSuffix); {do not localize}
644 <              Inc(iParamSuffix);
645 <              iCurState := DefaultState;
646 <              slNames.AddObject(sParamName,self); //Note local convention
647 <                                                  //add pointer to self to mark entry
648 <              sParamName := '';
649 <            end
650 <            else
651 <              IBError(ibxeSQLParseError, [SParamNameExpected]);
652 <          {$ifdef ALLOWDIALECT3PARAMNAMES}
653 <          end
654 <          else begin
655 <            { determine if Quoted parameter name is finished }
656 <            if cCurChar = '"' then
657 <            begin
658 <              Inc(i);
659 <              slNames.Add(sParamName);
660 <              SParamName := '';
661 <              iCurParamState := ParamDefaultState;
662 <              iCurState := DefaultState;
663 <            end
664 <            else
665 <              sParamName := sParamName + cCurChar
666 <          end;
667 <          {$endif}
668 <          { determine if the unquoted parameter name is finished }
669 <          if {$ifdef ALLOWDIALECT3PARAMNAMES}(iCurParamState <> ParamQuoteState) and {$endif}
670 <            (iCurState <> DefaultState) then
671 <          begin
672 <            if not (cNextChar in ['A'..'Z', 'a'..'z',
673 <                                  '0'..'9', '_', '$']) then begin
674 <              Inc(i);
675 <              iCurState := DefaultState;
676 <              slNames.Add(sParamName);
677 <              sParamName := '';
678 <            end;
679 <          end;
680 <        end;
681 <      end;
682 <      if (iCurState <> ParamState) and (i <= iLenSQL) then
683 <        AddToProcessedSQL(sSQL[i]);
684 <      Inc(i);
685 <    end;
686 <    AddToProcessedSQL(#0);
687 <    sProcessedSQL := strpas(StrBuffer);
508 >  procedure SetColumnNames(slNames: TStrings);
509 >  var i, j: integer;
510 >      found: boolean;
511 >  begin
512 >    found := false;
513      SetCount(slNames.Count);
514      for i := 0 to slNames.Count - 1 do
515      begin
# Line 705 | Line 530 | begin
530          Column[i].UniqueName := not found;
531        end;
532      end;
533 +  end;
534 +
535 + begin
536 +  if not IsInputDataArea then
537 +    IBError(ibxeNotPermitted,[nil]);
538 +
539 +  slNames := TStringList.Create;
540 +  try
541 +    sProcessedSQL := TSQLParamProcessor.Execute(sSQL,GenerateParamNames,slNames);
542 +    SetColumnNames(slNames);
543    finally
544      slNames.Free;
710    FreeMem(StrBuffer);
545    end;
546   end;
547  
# Line 716 | Line 550 | begin
550    Result := Count;
551   end;
552  
553 < function TSQLDataArea.ColumnByName(Idx: string): TSQLVarData;
553 > function TSQLDataArea.ColumnByName(Idx: AnsiString): TSQLVarData;
554   var
555 <  s: String;
555 >  s: AnsiString;
556    i: Integer;
557   begin
558 <  {$ifdef UseCaseInSensitiveParamName}
559 <   s := AnsiUpperCase(Idx);
560 <  {$else}
558 >  if not IsInputDataArea or not CaseSensitiveParams then
559 >   s := AnsiUpperCase(Idx)
560 >  else
561     s := Idx;
562 <  {$endif}
562 >
563    for i := 0 to Count - 1 do
564      if Column[i].Name = s then
565      begin
# Line 736 | Line 570 | begin
570   end;
571  
572   procedure TSQLDataArea.GetData(index: integer; var IsNull: boolean;
573 <  var len: short; var data: PChar);
573 >  var len: short; var data: PByte);
574   begin
575    //Do Nothing
576   end;
# Line 755 | Line 589 | begin
589    Result := FParent.Statement;
590   end;
591  
592 < procedure TSQLVarData.SetName(AValue: string);
592 > procedure TSQLVarData.SetName(AValue: AnsiString);
593   begin
594 <  if FName = AValue then Exit;
761 <  {$ifdef UseCaseInSensitiveParamName}
762 <  if Parent.IsInputDataArea then
594 >  if not Parent.IsInputDataArea or not Parent.CaseSensitiveParams then
595      FName := AnsiUpperCase(AValue)
596    else
765  {$endif}
597      FName := AValue;
598   end;
599  
# Line 774 | Line 605 | begin
605    FUniqueName := true;
606   end;
607  
608 < procedure TSQLVarData.SetString(aValue: string);
608 > procedure TSQLVarData.SetString(aValue: AnsiString);
609   begin
610    {we take full advantage here of reference counted strings. When setting a string
611     value, a reference is kept in FVarString and a pointer to it placed in the
612 <   SQLVar. This avoids string copies. Note that PChar is guaranteed to point to
612 >   SQLVar. This avoids string copies. Note that PAnsiChar is guaranteed to point to
613     a zero byte when the string is empty, neatly avoiding a nil pointer error.}
614  
615    FVarString := aValue;
616    SQLType := SQL_TEXT;
617 <  SetSQLData(PChar(FVarString),Length(aValue));
617 >  Scale := 0;
618 >  SetSQLData(PByte(PAnsiChar(FVarString)),Length(aValue));
619   end;
620  
621   procedure TSQLVarData.Changed;
# Line 799 | Line 631 | end;
631  
632   procedure TSQLVarData.Initialize;
633  
634 <  function FindVarByName(idx: string; limit: integer): TSQLVarData;
634 >  function FindVarByName(idx: AnsiString; limit: integer): TSQLVarData;
635    var
636      k: integer;
637    begin
# Line 814 | Line 646 | procedure TSQLVarData.Initialize;
646  
647   var
648    j, j_len: Integer;
649 <  st: String;
650 <  sBaseName: string;
649 >  st: AnsiString;
650 >  sBaseName: AnsiString;
651   begin
652    RowChange;
653  
# Line 902 | Line 734 | function TSQLDataItem.AdjustScaleToCurre
734   var
735    Scaling : Int64;
736    i : Integer;
737 <  FractionText, PadText, CurrText: string;
737 >  FractionText, PadText, CurrText: AnsiString;
738   begin
739    Result := 0;
740    Scaling := 1;
# Line 921 | Line 753 | begin
753        FractionText := IntToStr(abs(Value mod Scaling));
754        for i := Length(FractionText) to -aScale -1 do
755          PadText := '0' + PadText;
756 +      {$IF declared(DefaultFormatSettings)}
757 +      with DefaultFormatSettings do
758 +      {$ELSE}
759 +      {$IF declared(FormatSettings)}
760 +      with FormatSettings do
761 +      {$IFEND}
762 +      {$IFEND}
763        if Value < 0 then
764 <        CurrText := '-' + IntToStr(Abs(Value div Scaling)) + DefaultFormatSettings.DecimalSeparator + PadText + FractionText
764 >        CurrText := '-' + IntToStr(Abs(Value div Scaling)) + DecimalSeparator + PadText + FractionText
765        else
766 <        CurrText := IntToStr(Abs(Value div Scaling)) + DefaultFormatSettings.DecimalSeparator + PadText + FractionText;
766 >        CurrText := IntToStr(Abs(Value div Scaling)) + DecimalSeparator + PadText + FractionText;
767        try
768          result := StrToCurr(CurrText);
769        except
# Line 936 | Line 775 | begin
775        result := Value;
776   end;
777  
778 + function TSQLDataItem.GetDateFormatStr(IncludeTime: boolean): AnsiString;
779 + begin
780 +  {$IF declared(DefaultFormatSettings)}
781 +  with DefaultFormatSettings do
782 +  {$ELSE}
783 +  {$IF declared(FormatSettings)}
784 +  with FormatSettings do
785 +  {$IFEND}
786 +  {$IFEND}
787 +  case GetSQLDialect of
788 +    1:
789 +      if IncludeTime then
790 +        result := ShortDateFormat + ' ' + LongTimeFormat
791 +      else
792 +        result := ShortDateFormat;
793 +    3:
794 +      result := ShortDateFormat;
795 +  end;
796 + end;
797 +
798 + function TSQLDataItem.GetTimeFormatStr: AnsiString;
799 + begin
800 +  {$IF declared(DefaultFormatSettings)}
801 +  with DefaultFormatSettings do
802 +  {$ELSE}
803 +  {$IF declared(FormatSettings)}
804 +  with FormatSettings do
805 +  {$IFEND}
806 +  {$IFEND}
807 +    Result := LongTimeFormat;
808 + end;
809 +
810 + function TSQLDataItem.GetTimestampFormatStr: AnsiString;
811 + begin
812 +  {$IF declared(DefaultFormatSettings)}
813 +  with DefaultFormatSettings do
814 +  {$ELSE}
815 +  {$IF declared(FormatSettings)}
816 +  with FormatSettings do
817 +  {$IFEND}
818 +  {$IFEND}
819 +    Result := ShortDateFormat + ' ' +  LongTimeFormat + '.zzz';
820 + end;
821 +
822   procedure TSQLDataItem.SetAsInteger(AValue: Integer);
823   begin
824    SetAsLong(aValue);
# Line 1006 | Line 889 | begin
889    //Do nothing by default
890   end;
891  
892 < procedure TSQLDataItem.InternalSetAsString(Value: String);
892 > procedure TSQLDataItem.InternalSetAsString(Value: AnsiString);
893   begin
894    //Do nothing by default
895   end;
896  
897 < function TSQLDataItem.Transliterate(s: string; CodePage: TSystemCodePage
897 > function TSQLDataItem.Transliterate(s: AnsiString; CodePage: TSystemCodePage
898    ): RawByteString;
899   begin
900    Result := s;
# Line 1034 | Line 917 | begin
917     //Do nothing by default
918   end;
919  
920 < function TSQLDataItem.GetSQLTypeName: string;
920 > constructor TSQLDataItem.Create(api: TFBClientAPI);
921 > begin
922 >  inherited Create;
923 >  FFirebirdClientAPI := api;
924 > end;
925 >
926 > function TSQLDataItem.GetSQLTypeName: AnsiString;
927   begin
928    Result := GetSQLTypeName(GetSQLType);
929   end;
930  
931 < class function TSQLDataItem.GetSQLTypeName(SQLType: short): string;
931 > class function TSQLDataItem.GetSQLTypeName(SQLType: short): AnsiString;
932   begin
933    Result := 'Unknown';
934    case SQLType of
# Line 1140 | Line 1029 | begin
1029    CheckActive;
1030    result := 0;
1031    if not IsNull then
1032 <    with FirebirdClientAPI do
1032 >    with FFirebirdClientAPI do
1033      case SQLType of
1034        SQL_TEXT, SQL_VARYING: begin
1035          try
# Line 1270 | Line 1159 | begin
1159   end;
1160  
1161  
1162 < function TSQLDataItem.GetAsString: String;
1162 > function TSQLDataItem.GetAsString: AnsiString;
1163   var
1164 <  sz: PChar;
1164 >  sz: PByte;
1165    str_len: Integer;
1166    rs: RawByteString;
1167   begin
# Line 1280 | Line 1169 | begin
1169    result := '';
1170    { Check null, if so return a default string }
1171    if not IsNull then
1172 <  with FirebirdClientAPI do
1172 >  with FFirebirdClientAPI do
1173      case SQLType of
1174        SQL_BOOLEAN:
1175          if AsBoolean then
# Line 1297 | Line 1186 | begin
1186            str_len := DecodeInteger(SQLData, 2);
1187            Inc(sz, 2);
1188          end;
1189 <        SetString(rs, sz, str_len);
1189 >        SetString(rs, PAnsiChar(sz), str_len);
1190          SetCodePage(rs,GetCodePage,false);
1191          if (SQLType = SQL_TEXT) and (GetCharSetID <> 1) then
1192            Result := TrimRight(rs)
# Line 1305 | Line 1194 | begin
1194            Result := rs
1195        end;
1196        SQL_TYPE_DATE:
1197 <        case GetSQLDialect of
1309 <          1 : result := DateTimeToStr(AsDateTime);
1310 <          3 : result := DateToStr(AsDateTime);
1311 <        end;
1197 >        result := FormatDateTime(GetDateFormatStr(TimeOf(AsDateTime)<>0),AsDateTime);
1198        SQL_TYPE_TIME :
1199 <        result := TimeToStr(AsDateTime);
1199 >        result := FormatDateTime(GetTimeFormatStr,AsDateTime);
1200        SQL_TIMESTAMP:
1201 <        result := FormatDateTime(FormatSettings.ShortDateFormat + ' ' +
1316 <                            FormatSettings.LongTimeFormat+'.zzz',AsDateTime);
1201 >        result := FormatDateTime(GetTimestampFormatStr,AsDateTime);
1202        SQL_SHORT, SQL_LONG:
1203          if Scale = 0 then
1204            result := IntToStr(AsLong)
# Line 1341 | Line 1226 | begin
1226    Result := false;
1227   end;
1228  
1229 < function TSQLDataItem.getIsNullable: boolean;
1229 > function TSQLDataItem.GetIsNullable: boolean;
1230   begin
1231    CheckActive;
1232    Result := false;
# Line 1389 | Line 1274 | begin
1274    Result := false;
1275   end;
1276  
1277 + function TSQLDataItem.GetDateTimeStrLength(DateTimeFormat: TIBDateTimeFormats
1278 +  ): integer;
1279 + begin
1280 +  case DateTimeFormat of
1281 +  dfTimestamp:
1282 +    Result := Length(GetTimestampFormatStr);
1283 +  dfDateTime:
1284 +    Result := Length(GetDateFormatStr(true));
1285 +  dfTime:
1286 +    Result := Length(GetTimeFormatStr);
1287 +  else
1288 +    Result := 0;
1289 +  end;
1290 + end;
1291 +
1292  
1293   procedure TSQLDataItem.SetIsNull(Value: Boolean);
1294   begin
# Line 1400 | Line 1300 | begin
1300    //ignore unless overridden
1301   end;
1302  
1303 < procedure TSQLDataItem.SetName(aValue: string);
1303 > procedure TSQLDataItem.SetName(aValue: AnsiString);
1304   begin
1305    //ignore unless overridden
1306   end;
# Line 1452 | Line 1352 | begin
1352  
1353    SQLType := SQL_TYPE_DATE;
1354    DataLength := SizeOf(ISC_DATE);
1355 <  with FirebirdClientAPI do
1355 >  with FFirebirdClientAPI do
1356      SQLEncodeDate(Value,SQLData);
1357    Changed;
1358   end;
# Line 1472 | Line 1372 | begin
1372  
1373    SQLType := SQL_TYPE_TIME;
1374    DataLength := SizeOf(ISC_TIME);
1375 <  with FirebirdClientAPI do
1375 >  with FFirebirdClientAPI do
1376      SQLEncodeTime(Value,SQLData);
1377    Changed;
1378   end;
# Line 1486 | Line 1386 | begin
1386    Changing;
1387    SQLType := SQL_TIMESTAMP;
1388    DataLength := SizeOf(ISC_TIME) + sizeof(ISC_DATE);
1389 <  with FirebirdClientAPI do
1389 >  with FFirebirdClientAPI do
1390      SQLEncodeDateTime(Value,SQLData);
1391    Changed;
1392   end;
# Line 1576 | Line 1476 | begin
1476    Changed;
1477   end;
1478  
1479 < procedure TSQLDataItem.SetAsString(Value: String);
1479 > procedure TSQLDataItem.SetAsString(Value: AnsiString);
1480   begin
1481    InternalSetAsString(Value);
1482   end;
# Line 1611 | Line 1511 | begin
1511    end;
1512   end;
1513  
1514 + procedure TSQLDataItem.SetAsNumeric(Value: Int64; aScale: integer);
1515 + begin
1516 +  CheckActive;
1517 +  Changing;
1518 +  if IsNullable then
1519 +    IsNull := False;
1520 +
1521 +  SQLType := SQL_INT64;
1522 +  Scale := aScale;
1523 +  DataLength := SizeOf(Int64);
1524 +  PInt64(SQLData)^ := Value;
1525 +  Changed;
1526 + end;
1527 +
1528   procedure TSQLDataItem.SetAsBoolean(AValue: boolean);
1529   begin
1530    CheckActive;
# Line 1641 | Line 1555 | begin
1555      IBError(ibxeStatementNotPrepared, [nil]);
1556   end;
1557  
1558 < function TColumnMetaData.SQLData: PChar;
1558 > function TColumnMetaData.SQLData: PByte;
1559   begin
1560    Result := FIBXSQLVAR.SQLData;
1561   end;
# Line 1658 | Line 1572 | end;
1572  
1573   constructor TColumnMetaData.Create(aOwner: IUnknown; aIBXSQLVAR: TSQLVarData);
1574   begin
1575 <  inherited Create;
1575 >  inherited Create(aIBXSQLVAR.GetStatement.GetAttachment.getFirebirdAPI as TFBClientAPI);
1576    FIBXSQLVAR := aIBXSQLVAR;
1577    FOwner := aOwner;
1578    FPrepareSeqNo := FIBXSQLVAR.Parent.PrepareSeqNo;
# Line 1694 | Line 1608 | begin
1608    result := FIBXSQLVAR.SQLSubtype;
1609   end;
1610  
1611 < function TColumnMetaData.getRelationName: string;
1611 > function TColumnMetaData.getRelationName: AnsiString;
1612   begin
1613    CheckActive;
1614     result :=  FIBXSQLVAR.RelationName;
1615   end;
1616  
1617 < function TColumnMetaData.getOwnerName: string;
1617 > function TColumnMetaData.getOwnerName: AnsiString;
1618   begin
1619    CheckActive;
1620    result :=  FIBXSQLVAR.OwnerName;
1621   end;
1622  
1623 < function TColumnMetaData.getSQLName: string;
1623 > function TColumnMetaData.getSQLName: AnsiString;
1624   begin
1625    CheckActive;
1626    result :=  FIBXSQLVAR.FieldName;
1627   end;
1628  
1629 < function TColumnMetaData.getAliasName: string;
1629 > function TColumnMetaData.getAliasName: AnsiString;
1630   begin
1631    CheckActive;
1632    result := FIBXSQLVAR.AliasName;
1633   end;
1634  
1635 < function TColumnMetaData.GetName: string;
1635 > function TColumnMetaData.GetName: AnsiString;
1636   begin
1637    CheckActive;
1638    Result := FIBXSQLVAR. Name;
# Line 1803 | Line 1717 | begin
1717    result := FIBXSQLVAR.GetAsBlob(AsQuad,BPB);
1718   end;
1719  
1720 < function TIBSQLData.GetAsString: String;
1720 > function TIBSQLData.GetAsString: AnsiString;
1721   begin
1722    CheckActive;
1723    Result := '';
# Line 1821 | Line 1735 | end;
1735  
1736   { TSQLParam }
1737  
1738 < procedure TSQLParam.InternalSetAsString(Value: String);
1738 > procedure TSQLParam.InternalSetAsString(Value: AnsiString);
1739 >
1740 > procedure DoSetString;
1741 > begin
1742 >  Changing;
1743 >  FIBXSQLVar.SetString(Transliterate(Value,GetCodePage));
1744 >  Changed;
1745 > end;
1746 >
1747   var b: IBlob;
1748 +    dt: TDateTime;
1749 +    CurrValue: Currency;
1750 +    FloatValue: single;
1751   begin
1752    CheckActive;
1753    if IsNullable then
1754      IsNull := False;
1755    case SQLTYPE of
1756    SQL_BOOLEAN:
1757 <    if CompareText(Value,STrue) = 0 then
1757 >    if AnsiCompareText(Value,STrue) = 0 then
1758        AsBoolean := true
1759      else
1760 <    if CompareText(Value,SFalse) = 0 then
1760 >    if AnsiCompareText(Value,SFalse) = 0 then
1761        AsBoolean := false
1762      else
1763        IBError(ibxeInvalidDataConversion,[nil]);
# Line 1848 | Line 1773 | begin
1773  
1774    SQL_VARYING,
1775    SQL_TEXT:
1776 <    begin
1852 <      Changing;
1853 <      FIBXSQLVar.SetString(Transliterate(Value,GetCodePage));
1854 <      Changed;
1855 <    end;
1776 >    DoSetString;
1777  
1778      SQL_SHORT,
1779      SQL_LONG,
1780      SQL_INT64:
1781 <      SetAsInt64(StrToInt(Value));
1781 >      if TryStrToCurr(Value,CurrValue) then
1782 >        SetAsNumeric(AdjustScaleFromCurrency(CurrValue,GetScale),GetScale)
1783 >      else
1784 >        DoSetString;
1785  
1786      SQL_D_FLOAT,
1787      SQL_DOUBLE,
1788      SQL_FLOAT:
1789 <      SetAsDouble(StrToFloat(Value));
1789 >      if TryStrToFloat(Value,FloatValue) then
1790 >        SetAsDouble(FloatValue)
1791 >      else
1792 >        DoSetString;
1793  
1794      SQL_TIMESTAMP:
1795 <      SetAsDateTime(StrToDateTime(Value));
1795 >      if TryStrToDateTime(Value,dt) then
1796 >        SetAsDateTime(dt)
1797 >      else
1798 >        DoSetString;
1799  
1800      SQL_TYPE_DATE:
1801 <      SetAsDate(StrToDateTime(Value));
1801 >      if TryStrToDateTime(Value,dt) then
1802 >        SetAsDate(dt)
1803 >      else
1804 >        DoSetString;
1805  
1806      SQL_TYPE_TIME:
1807 <      SetAsTime(StrToDateTime(Value));
1807 >      if TryStrToDateTime(Value,dt) then
1808 >        SetAsTime(dt)
1809 >      else
1810 >        DoSetString;
1811  
1812      else
1813        IBError(ibxeInvalidDataConversion,[nil]);
# Line 1925 | Line 1861 | begin
1861    Result := inherited GetAsPointer;
1862   end;
1863  
1864 < procedure TSQLParam.SetName(Value: string);
1864 > procedure TSQLParam.SetName(Value: AnsiString);
1865   begin
1866    CheckActive;
1867    FIBXSQLVAR.Name := Value;
# Line 2231 | Line 2167 | begin
2167    end;
2168   end;
2169  
2170 < procedure TSQLParam.SetAsString(AValue: String);
2170 > procedure TSQLParam.SetAsString(AValue: AnsiString);
2171   var i: integer;
2172      OldSQLVar: TSQLVarData;
2173   begin
# Line 2344 | Line 2280 | begin
2280    inherited Destroy;
2281   end;
2282  
2283 < function TMetaData.GetUniqueRelationName: string;
2283 > function TMetaData.GetUniqueRelationName: AnsiString;
2284   begin
2285    CheckActive;
2286    Result := FMetaData.UniqueRelationName;
# Line 2372 | Line 2308 | begin
2308    end;
2309   end;
2310  
2311 < function TMetaData.ByName(Idx: String): IColumnMetaData;
2311 > function TMetaData.ByName(Idx: AnsiString): IColumnMetaData;
2312   var aIBXSQLVAR: TSQLVarData;
2313   begin
2314    CheckActive;
# Line 2432 | Line 2368 | begin
2368    end;
2369   end;
2370  
2371 < function TSQLParams.ByName(Idx: String): ISQLParam;
2371 > function TSQLParams.ByName(Idx: AnsiString): ISQLParam;
2372   var aIBXSQLVAR: TSQLVarData;
2373   begin
2374    CheckActive;
# Line 2457 | Line 2393 | begin
2393      end;
2394   end;
2395  
2396 + function TSQLParams.GetHasCaseSensitiveParams: Boolean;
2397 + begin
2398 +  Result := FSQLParams.CaseSensitiveParams;
2399 + end;
2400 +
2401   { TResults }
2402  
2403   procedure TResults.CheckActive;
# Line 2500 | Line 2441 | begin
2441    Result := FResults.Count;
2442   end;
2443  
2444 < function TResults.ByName(Idx: String): ISQLData;
2444 > function TResults.ByName(Idx: AnsiString): ISQLData;
2445   var col: TSQLVarData;
2446   begin
2447    Result := nil;
# Line 2532 | Line 2473 | begin
2473   end;
2474  
2475   procedure TResults.GetData(index: integer; var IsNull: boolean; var len: short;
2476 <  var data: PChar);
2476 >  var data: PByte);
2477   begin
2478    CheckActive;
2479    FResults.GetData(index,IsNull, len,data);
# Line 2548 | Line 2489 | begin
2489    RetainInterfaces := aValue;
2490   end;
2491  
2551
2492   end.
2493  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines