PageRenderTime 17ms CodeModel.GetById 12ms app.highlight 1ms RepoModel.GetById 2ms app.codeStats 0ms

/components/lazreport/source/lr_dbrel.pas

http://github.com/graemeg/lazarus
Pascal | 139 lines | 103 code | 23 blank | 13 comment | 9 complexity | 55f2a252c14d91182cd510892fce201f MD5 | raw file
  1
  2{*****************************************}
  3{                                         }
  4{             FastReport v2.3             }
  5{             DB related stuff            }
  6{                                         }
  7{  Copyright (c) 1998-99 by Tzyganenko A. }
  8{                                         }
  9{*****************************************}
 10
 11unit LR_DBRel;
 12
 13interface
 14
 15{$I LR_Vers.inc}
 16
 17uses
 18  SysUtils, Classes, DB;
 19
 20const
 21  frEmptyBookmark = nil;
 22
 23type
 24  { TODO -oalexs : Remove this }
 25  TfrBookmark = TBookmark;
 26  TfrTDataSet =class(TDataSet);
 27  TfrTField = class(TField);
 28  TfrTBlobField = class(TBlobField);
 29
 30function frIsBlob(Field: TfrTField): Boolean;
 31function frIsBookmarksEqual(DataSet: TfrTDataSet; b1, b2: TfrBookmark): Boolean;
 32procedure frGetFieldNames(DataSet: TfrTDataSet; List: TStrings);
 33function frGetBookmark(DataSet: TfrTDataSet): TfrBookmark;
 34procedure frFreeBookmark(DataSet: TfrTDataSet; Bookmark: TfrBookmark);
 35procedure frGotoBookmark(DataSet: TfrTDataSet; Bookmark: TfrBookmark);
 36function frGetDataSource(Owner: TComponent; d: TDataSet): TDataSource;
 37
 38function lrGetFieldValue(F:TField):Variant;
 39
 40const
 41  TypeStringField = [ftString, ftMemo, ftFmtMemo, ftFixedChar, ftWideString,
 42    ftFixedWideChar, ftWideMemo];
 43
 44  TypeNumericField = [ftFloat, ftCurrency, ftBCD, ftDate,  ftTime, ftDateTime,
 45    ftTimeStamp];
 46
 47  TypeIntegerField = [ftSmallint, ftInteger, ftWord, ftAutoInc, ftLargeint];
 48
 49  TypeBooleanField = [ftBoolean];
 50
 51implementation
 52uses LR_Utils;
 53
 54function frIsBlob(Field: TfrTField): Boolean;
 55begin
 56  Result := (Field <> nil) and (Field.DataType in [ftBlob..ftTypedBinary]);
 57end;
 58
 59procedure frGetFieldNames(DataSet: TfrTDataSet; List: TStrings);
 60begin
 61  if not Assigned(DataSet) then exit;
 62  if DataSet.FieldCount > 0 then
 63    DataSet.GetFieldNames(List)
 64  else
 65  begin
 66{    DataSet.Open;
 67    DataSet.GetFieldNames(List);
 68    DataSet.Close;}
 69    DataSet.FieldDefs.Update;
 70    DataSet.FieldDefs.GetItemNames(List);
 71  end;
 72end;
 73
 74function frGetBookmark(DataSet: TfrTDataSet): TfrBookmark;
 75begin
 76  Result := DataSet.GetBookmark;
 77end;
 78
 79procedure frGotoBookmark(DataSet: TfrTDataSet; Bookmark: TfrBookmark);
 80begin
 81  DataSet.GotoBookmark(BookMark);
 82end;
 83
 84function frGetDataSource(Owner: TComponent; d: TDataSet): TDataSource;
 85var
 86  i: Integer;
 87  sl: TStringList;
 88  ds: TDataSource;
 89begin
 90  sl := TStringList.Create;
 91  Result := nil;
 92  frGetComponents(Owner, TDataSource, sl, nil);
 93  for i := 0 to sl.Count - 1 do
 94  begin
 95    ds := frFindComponent(Owner, sl[i]) as TDataSource;
 96    if (ds <> nil) and (ds.DataSet = d) then
 97    begin
 98      Result := ds;
 99      break;
100    end;
101  end;
102  sl.Free;
103end;
104
105function lrGetFieldValue(F: TField): Variant;
106begin
107  if Assigned(F) then
108  begin
109    if F.IsNull then
110    begin
111      if F.DataType in TypeStringField then
112        Result:=''
113      else
114      if F.DataType in (TypeIntegerField + TypeNumericField) then
115        Result:=0
116      else
117      if F.DataType in TypeBooleanField then
118        Result:=false
119      else
120        Result:=null
121    end
122    else
123      Result:=F.Value;
124  end
125  else
126    Result:=null;
127end;
128
129procedure frFreeBookmark(DataSet: TfrTDataSet; Bookmark: TfrBookmark);
130begin
131  DataSet.FreeBookmark(BookMark);
132end;
133
134function frIsBookmarksEqual(DataSet: TfrTDataSet; b1, b2: TfrBookmark): Boolean;
135begin
136  Result := DataSet.CompareBookmarks(b1, b2) = 0;
137end;
138
139end.