db.pp 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Michael Van Canneyt, member of the
  5. Free Pascal development team
  6. DB header file with interface section.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. unit db;
  14. {$mode objfpc}
  15. {$h+}
  16. interface
  17. uses Classes,Sysutils,Variants;
  18. const
  19. dsMaxBufferCount = MAXINT div 8;
  20. dsMaxStringSize = 8192;
  21. // Used in AsBoolean for string fields to determine
  22. // whether it's true or false.
  23. YesNoChars : Array[Boolean] of char = ('Y','N');
  24. type
  25. {$ifdef ver1_0}
  26. PtrInt = Longint;
  27. PPtrInt = ^PtrInt;
  28. {$endif}
  29. {LargeInt}
  30. LargeInt = Int64;
  31. { Auxiliary type }
  32. TStringFieldBuffer = Array[0..dsMaxStringSize] of Char;
  33. { Misc Dataset types }
  34. TDataSetState = (dsInactive, dsBrowse, dsEdit, dsInsert, dsSetKey,
  35. dsCalcFields, dsFilter, dsNewValue, dsOldValue, dsCurValue);
  36. TDataEvent = (deFieldChange, deRecordChange, deDataSetChange,
  37. deDataSetScroll, deLayoutChange, deUpdateRecord, deUpdateState,
  38. deCheckBrowseMode, dePropertyChange, deFieldListChange, deFocusControl);
  39. TUpdateStatus = (usUnmodified, usModified, usInserted, usDeleted);
  40. TUpdateMode = (upWhereAll, upWhereChanged, upWhereKeyOnly);
  41. TProviderFlag = (pfInUpdate, pfInWhere, pfInKey, pfHidden);
  42. TProviderFlags = set of TProviderFlag;
  43. { Forward declarations }
  44. TFieldDef = class;
  45. TFieldDefs = class;
  46. TField = class;
  47. TFields = Class;
  48. TDataSet = class;
  49. TDataBase = Class;
  50. TDatasource = Class;
  51. TDatalink = Class;
  52. TDBTransaction = Class;
  53. { Exception classes }
  54. EDatabaseError = class(Exception);
  55. { TFieldDef }
  56. TFieldClass = class of TField;
  57. {
  58. TFieldType = (ftUnknown, ftString, ftSmallint, ftInteger, ftWord,
  59. ftBoolean, ftFloat, ftDate, ftTime, ftDateTime,
  60. ftBytes, ftVarBytes, ftAutoInc, ftBlob, ftMemo, ftGraphic,
  61. ftFmtMemo, ftParadoxOle, ftDBaseOle, ftTypedBinary, ftCursor);
  62. }
  63. TFieldType = (ftUnknown, ftString, ftSmallint, ftInteger, ftWord,
  64. ftBoolean, ftFloat, ftCurrency, ftBCD, ftDate, ftTime, ftDateTime,
  65. ftBytes, ftVarBytes, ftAutoInc, ftBlob, ftMemo, ftGraphic, ftFmtMemo,
  66. ftParadoxOle, ftDBaseOle, ftTypedBinary, ftCursor, ftFixedChar,
  67. ftWideString, ftLargeint, ftADT, ftArray, ftReference,
  68. ftDataSet, ftOraBlob, ftOraClob, ftVariant, ftInterface,
  69. ftIDispatch, ftGuid, ftTimeStamp, ftFMTBcd);
  70. { TDateTimeRec }
  71. TDateTimeAlias = type TDateTime;
  72. TDateTimeRec = record
  73. case TFieldType of
  74. ftDate: (Date: Longint);
  75. ftTime: (Time: Longint);
  76. ftDateTime: (DateTime: TDateTimeAlias);
  77. end;
  78. TFieldAttribute = (faHiddenCol, faReadonly, faRequired, faLink, faUnNamed, faFixed);
  79. TFieldAttributes = set of TFieldAttribute;
  80. TFieldDef = class(TComponent)
  81. Private
  82. FDataType : TFieldType;
  83. FFieldNo : Longint;
  84. FInternalCalcField : Boolean;
  85. FPrecision : Longint;
  86. FRequired : Boolean;
  87. FSize : Word;
  88. FName : String;
  89. FAttributes : TFieldAttributes;
  90. Function GetFieldClass : TFieldClass;
  91. public
  92. constructor Create(AOwner: TFieldDefs; const AName: string;
  93. ADataType: TFieldType; ASize: Word; ARequired: Boolean; AFieldNo: Longint);
  94. destructor Destroy; override;
  95. function CreateField(AOwner: TComponent): TField;
  96. property FieldClass: TFieldClass read GetFieldClass;
  97. property FieldNo: Longint read FFieldNo;
  98. property InternalCalcField: Boolean read FInternalCalcField write FInternalCalcField;
  99. property Required: Boolean read FRequired;
  100. Published
  101. property Attributes: TFieldAttributes read FAttributes write FAttributes default [];
  102. property Name: string read FName write FName; // Must move to TNamedItem
  103. property DataType: TFieldType read FDataType write FDataType;
  104. property Precision: Longint read FPrecision write FPrecision;
  105. property Size: Word read FSize write FSize;
  106. end;
  107. { TFieldDefs }
  108. TFieldDefs = class(TComponent)
  109. private
  110. FDataSet: TDataSet;
  111. FItems: TList;
  112. FUpdated: Boolean;
  113. FHiddenFields : Boolean;
  114. function GetCount: Longint;
  115. function GetItem(Index: Longint): TFieldDef;
  116. public
  117. constructor Create(ADataSet: TDataSet);
  118. destructor Destroy; override;
  119. procedure Add(const AName: string; ADataType: TFieldType; ASize: Word; ARequired: Boolean);
  120. procedure Add(const AName: string; ADataType: TFieldType; ASize: Word);
  121. procedure Add(const AName: string; ADataType: TFieldType);
  122. Function AddFieldDef : TFieldDef;
  123. procedure Assign(FieldDefs: TFieldDefs);
  124. procedure Clear;
  125. function Find(const AName: string): TFieldDef;
  126. function IndexOf(const AName: string): Longint;
  127. procedure Update;
  128. property Count: Longint read GetCount;
  129. Property HiddenFields : Boolean Read FHiddenFields Write FHiddenFields;
  130. property Items[Index: Longint]: TFieldDef read GetItem; default;
  131. end;
  132. { TField }
  133. TFieldKind = (fkData, fkCalculated, fkLookup, fkInternalCalc);
  134. TFieldKinds = Set of TFieldKind;
  135. TFieldNotifyEvent = procedure(Sender: TField) of object;
  136. TFieldGetTextEvent = procedure(Sender: TField; var Text: string;
  137. DisplayText: Boolean) of object;
  138. TFieldSetTextEvent = procedure(Sender: TField; const Text: string) of object;
  139. TFieldRef = ^TField;
  140. TFieldChars = set of Char;
  141. TField = class(TComponent)
  142. Private
  143. FAlignMent : TAlignment;
  144. FAttributeSet : String;
  145. FBuffers : ppchar;
  146. FCalculated : Boolean;
  147. FCanModify : Boolean;
  148. FConstraintErrorMessage : String;
  149. FCustomConstraint : String;
  150. FDataSet : TDataSet;
  151. // FDataSize : Word;
  152. FDataType : TFieldType;
  153. FDefaultExpression : String;
  154. FDisplayLabel : String;
  155. FDisplayWidth : Longint;
  156. FEditText : String;
  157. FFieldKind : TFieldKind;
  158. FFieldName : String;
  159. FFieldNo : Longint;
  160. FFields : TFields;
  161. FHasConstraints : Boolean;
  162. FImportedConstraint : String;
  163. FIsIndexField : Boolean;
  164. FKeyFields : String;
  165. FLookupCache : Boolean;
  166. FLookupDataSet : TDataSet;
  167. FLookupKeyfields : String;
  168. FLookupresultField : String;
  169. FOffset : Word;
  170. FOnChange : TFieldNotifyEvent;
  171. FOnGetText: TFieldGetTextEvent;
  172. FOnSetText: TFieldSetTextEvent;
  173. FOnValidate: TFieldNotifyEvent;
  174. FOrigin : String;
  175. FReadOnly : Boolean;
  176. FRequired : Boolean;
  177. FSize : Word;
  178. FValidChars : TFieldChars;
  179. FValueBuffer : Pointer;
  180. FValidating : Boolean;
  181. FVisible : Boolean;
  182. FProviderFlags : TProviderFlags;
  183. Function GetIndex : longint;
  184. procedure SetAlignment(const AValue: TAlignMent);
  185. Procedure SetDataset(Value : TDataset);
  186. function GetDisplayText: String;
  187. procedure SetDisplayLabel(const AValue: string);
  188. procedure SetDisplayWidth(const AValue: Longint);
  189. function GetDisplayWidth: integer;
  190. procedure SetReadOnly(const AValue: Boolean);
  191. procedure SetVisible(const AValue: Boolean);
  192. function IsDisplayStored : Boolean;
  193. protected
  194. function AccessError(const TypeName: string): EDatabaseError;
  195. procedure CheckInactive;
  196. class procedure CheckTypeSize(AValue: Longint); virtual;
  197. procedure Change; virtual;
  198. procedure DataChanged;
  199. procedure FreeBuffers; virtual;
  200. function GetAsBoolean: Boolean; virtual;
  201. function GetAsDateTime: TDateTime; virtual;
  202. function GetAsFloat: Double; virtual;
  203. function GetAsLongint: Longint; virtual;
  204. function GetAsInteger: Longint; virtual;
  205. function GetAsVariant: variant; virtual;
  206. function GetOldValue: variant; virtual;
  207. function GetAsString: string; virtual;
  208. function GetCanModify: Boolean; virtual;
  209. function GetDataSize: Word; virtual;
  210. function GetDefaultWidth: Longint; virtual;
  211. function GetDisplayName : String;
  212. function GetIsNull: Boolean; virtual;
  213. function GetParentComponent: TComponent; override;
  214. procedure GetText(var AText: string; ADisplayText: Boolean); virtual;
  215. function HasParent: Boolean; override;
  216. procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  217. procedure PropertyChanged(LayoutAffected: Boolean);
  218. procedure ReadState(Reader: TReader); override;
  219. procedure SetAsBoolean(AValue: Boolean); virtual;
  220. procedure SetAsDateTime(AValue: TDateTime); virtual;
  221. procedure SetAsFloat(AValue: Double); virtual;
  222. procedure SetAsLongint(AValue: Longint); virtual;
  223. procedure SetAsInteger(AValue: Integer); virtual;
  224. procedure SetAsVariant(AValue: variant); virtual;
  225. procedure SetAsString(const AValue: string); virtual;
  226. procedure SetDataType(AValue: TFieldType);
  227. procedure SetSize(AValue: Word); virtual;
  228. procedure SetParentComponent(AParent: TComponent); override;
  229. procedure SetText(const AValue: string); virtual;
  230. public
  231. constructor Create(AOwner: TComponent); override;
  232. destructor Destroy; override;
  233. procedure Assign(Source: TPersistent); override;
  234. procedure Clear; virtual;
  235. procedure FocusControl;
  236. function GetData(Buffer: Pointer): Boolean;
  237. class function IsBlob: Boolean; virtual;
  238. function IsValidChar(InputChar: Char): Boolean; virtual;
  239. procedure SetData(Buffer: Pointer);
  240. procedure SetFieldType(AValue: TFieldType); virtual;
  241. procedure Validate(Buffer: Pointer);
  242. property AsBoolean: Boolean read GetAsBoolean write SetAsBoolean;
  243. property AsDateTime: TDateTime read GetAsDateTime write SetAsDateTime;
  244. property AsFloat: Double read GetAsFloat write SetAsFloat;
  245. property AsLongint: Longint read GetAsLongint write SetAsLongint;
  246. property AsInteger: Integer read GetAsInteger write SetAsInteger;
  247. property AsString: string read GetAsString write SetAsString;
  248. property AttributeSet: string read FAttributeSet write FAttributeSet;
  249. property Calculated: Boolean read FCalculated write FCalculated;
  250. property CanModify: Boolean read FCanModify;
  251. property DataSet: TDataSet read FDataSet write SetDataSet;
  252. property DataSize: Word read GetDataSize;
  253. property DataType: TFieldType read FDataType;
  254. property DisplayName: String Read GetDisplayName;
  255. property DisplayText: String read GetDisplayText;
  256. property FieldNo: Longint read FFieldNo;
  257. property IsIndexField: Boolean read FIsIndexField;
  258. property IsNull: Boolean read GetIsNull;
  259. property Offset: word read FOffset;
  260. property Size: Word read FSize write FSize;
  261. property Text: string read FEditText write FEditText;
  262. property ValidChars : TFieldChars Read FValidChars;
  263. property Value: variant read GetAsVariant write SetAsVariant;
  264. property OldValue: variant read GetOldValue;
  265. property ProviderFlags : TProviderFlags read FProviderFlags write FProviderFlags;
  266. published
  267. property AlignMent : TAlignMent Read FAlignMent write SetAlignment;
  268. property CustomConstraint: string read FCustomConstraint write FCustomConstraint;
  269. property ConstraintErrorMessage: string read FConstraintErrorMessage write FConstraintErrorMessage;
  270. property DefaultExpression: string read FDefaultExpression write FDefaultExpression;
  271. property DisplayLabel : string read GetDisplayName write SetDisplayLabel stored IsDisplayStored;
  272. property DisplayWidth: Longint read GetDisplayWidth write SetDisplayWidth;
  273. property FieldKind: TFieldKind read FFieldKind write FFieldKind;
  274. property FieldName: string read FFieldName write FFieldName;
  275. property HasConstraints: Boolean read FHasConstraints;
  276. property Index: Longint read GetIndex;
  277. property ImportedConstraint: string read FImportedConstraint write FImportedConstraint;
  278. property LookupDataSet: TDataSet read FLookupDataSet write FLookupDataSet;
  279. property LookupKeyFields: string read FLookupKeyFields write FLookupKeyFields;
  280. property LookupResultField: string read FLookupResultField write FLookupResultField;
  281. property KeyFields: string read FKeyFields write FKeyFields;
  282. property LookupCache: Boolean read FLookupCache write FLookupCache;
  283. property Origin: string read FOrigin write FOrigin;
  284. property ReadOnly: Boolean read FReadOnly write SetReadOnly;
  285. property Required: Boolean read FRequired write FRequired;
  286. property Visible: Boolean read FVisible write SetVisible;
  287. property OnChange: TFieldNotifyEvent read FOnChange write FOnChange;
  288. property OnGetText: TFieldGetTextEvent read FOnGetText write FOnGetText;
  289. property OnSetText: TFieldSetTextEvent read FOnSetText write FOnSetText;
  290. property OnValidate: TFieldNotifyEvent read FOnValidate write FOnValidate;
  291. end;
  292. { TStringField }
  293. TStringField = class(TField)
  294. protected
  295. class procedure CheckTypeSize(AValue: Longint); override;
  296. function GetAsBoolean: Boolean; override;
  297. function GetAsDateTime: TDateTime; override;
  298. function GetAsFloat: Double; override;
  299. function GetAsLongint: Longint; override;
  300. function GetAsString: string; override;
  301. function GetAsVariant: variant; override;
  302. function GetDataSize: Word; override;
  303. function GetDefaultWidth: Longint; override;
  304. procedure GetText(var AText: string; ADisplayText: Boolean); override;
  305. function GetValue(var AValue: string): Boolean;
  306. procedure SetAsBoolean(AValue: Boolean); override;
  307. procedure SetAsDateTime(AValue: TDateTime); override;
  308. procedure SetAsFloat(AValue: Double); override;
  309. procedure SetAsLongint(AValue: Longint); override;
  310. procedure SetAsString(const AValue: string); override;
  311. public
  312. constructor Create(AOwner: TComponent); override;
  313. published
  314. property Size default 20;
  315. end;
  316. { TNumericField }
  317. TNumericField = class(TField)
  318. Private
  319. FDisplayFormat : String;
  320. FEditFormat : String;
  321. protected
  322. procedure RangeError(AValue, Min, Max: Double);
  323. procedure SetDisplayFormat(const AValue: string);
  324. procedure SetEditFormat(const AValue: string);
  325. public
  326. constructor Create(AOwner: TComponent); override;
  327. published
  328. property DisplayFormat: string read FDisplayFormat write SetDisplayFormat;
  329. property EditFormat: string read FEditFormat write SetEditFormat;
  330. end;
  331. { TLongintField }
  332. TLongintField = class(TNumericField)
  333. private
  334. FMinValue,
  335. FMaxValue,
  336. FMinRange,
  337. FMAxRange : Longint;
  338. Procedure SetMinValue (AValue : longint);
  339. Procedure SetMaxValue (AValue : longint);
  340. protected
  341. function GetAsFloat: Double; override;
  342. function GetAsLongint: Longint; override;
  343. function GetAsString: string; override;
  344. function GetAsVariant: variant; override;
  345. function GetDataSize: Word; override;
  346. procedure GetText(var AText: string; ADisplayText: Boolean); override;
  347. function GetValue(var AValue: Longint): Boolean;
  348. procedure SetAsFloat(AValue: Double); override;
  349. procedure SetAsLongint(AValue: Longint); override;
  350. procedure SetAsString(const AValue: string); override;
  351. procedure SetAsVariant(AValue: variant); override;
  352. public
  353. constructor Create(AOwner: TComponent); override;
  354. Function CheckRange(AValue : longint) : Boolean;
  355. property Value: Longint read GetAsLongint write SetAsLongint;
  356. published
  357. property MaxValue: Longint read FMaxValue write SetMaxValue default 0;
  358. property MinValue: Longint read FMinValue write SetMinValue default 0;
  359. end;
  360. TIntegerField = TLongintField;
  361. { TLargeintField }
  362. TLargeintField = class(TNumericField)
  363. private
  364. FMinValue,
  365. FMaxValue,
  366. FMinRange,
  367. FMAxRange : Largeint;
  368. Procedure SetMinValue (AValue : Largeint);
  369. Procedure SetMaxValue (AValue : Largeint);
  370. protected
  371. function GetAsFloat: Double; override;
  372. function GetAsLongint: Longint; override;
  373. function GetAsLargeint: Largeint; virtual;
  374. function GetAsString: string; override;
  375. function GetAsVariant: variant; override;
  376. function GetDataSize: Word; override;
  377. procedure GetText(var AText: string; ADisplayText: Boolean); override;
  378. function GetValue(var AValue: Largeint): Boolean;
  379. procedure SetAsFloat(AValue: Double); override;
  380. procedure SetAsLongint(AValue: Longint); override;
  381. procedure SetAsLargeint(AValue: Largeint); virtual;
  382. procedure SetAsString(const AValue: string); override;
  383. public
  384. constructor Create(AOwner: TComponent); override;
  385. Function CheckRange(AValue : largeint) : Boolean;
  386. property Value: Longint read GetAsLongint write SetAsLongint;
  387. published
  388. property MaxValue: Largeint read FMaxValue write SetMaxValue default 0;
  389. property MinValue: Largeint read FMinValue write SetMinValue default 0;
  390. end;
  391. { TSmallintField }
  392. TSmallintField = class(TLongintField)
  393. protected
  394. function GetDataSize: Word; override;
  395. public
  396. constructor Create(AOwner: TComponent); override;
  397. end;
  398. { TWordField }
  399. TWordField = class(TLongintField)
  400. protected
  401. function GetDataSize: Word; override;
  402. public
  403. constructor Create(AOwner: TComponent); override;
  404. end;
  405. { TAutoIncField }
  406. TAutoIncField = class(TLongintField)
  407. Protected
  408. Procedure SetAsLongInt(AValue : Longint); override;
  409. public
  410. constructor Create(AOwner: TComponent); override;
  411. end;
  412. { TFloatField }
  413. TFloatField = class(TNumericField)
  414. private
  415. FMaxValue : Double;
  416. FMinValue : Double;
  417. FPrecision : Longint;
  418. protected
  419. function GetAsFloat: Double; override;
  420. function GetAsLongint: Longint; override;
  421. function GetAsVariant: variant; override;
  422. function GetAsString: string; override;
  423. function GetDataSize: Word; override;
  424. procedure GetText(var theText: string; ADisplayText: Boolean); override;
  425. procedure SetAsFloat(AValue: Double); override;
  426. procedure SetAsLongint(AValue: Longint); override;
  427. procedure SetAsString(const AValue: string); override;
  428. public
  429. constructor Create(AOwner: TComponent); override;
  430. Function CheckRange(AValue : Double) : Boolean;
  431. property Value: Double read GetAsFloat write SetAsFloat;
  432. published
  433. property MaxValue: Double read FMaxValue write FMaxValue;
  434. property MinValue: Double read FMinValue write FMinValue;
  435. property Precision: Longint read FPrecision write FPrecision default 15;
  436. end;
  437. { TBooleanField }
  438. TBooleanField = class(TField)
  439. private
  440. FDisplayValues : String;
  441. // First byte indicates uppercase or not.
  442. FDisplays : Array[Boolean,Boolean] of string;
  443. Procedure SetDisplayValues(AValue : String);
  444. protected
  445. function GetAsBoolean: Boolean; override;
  446. function GetAsString: string; override;
  447. function GetAsVariant: variant; override;
  448. function GetDataSize: Word; override;
  449. function GetDefaultWidth: Longint; override;
  450. procedure SetAsBoolean(AValue: Boolean); override;
  451. procedure SetAsString(const AValue: string); override;
  452. public
  453. constructor Create(AOwner: TComponent); override;
  454. property Value: Boolean read GetAsBoolean write SetAsBoolean;
  455. published
  456. property DisplayValues: string read FDisplayValues write SetDisplayValues;
  457. end;
  458. { TDateTimeField }
  459. TDateTimeField = class(TField)
  460. private
  461. FDisplayFormat : String;
  462. protected
  463. function GetAsDateTime: TDateTime; override;
  464. function GetAsFloat: Double; override;
  465. function GetAsString: string; override;
  466. function GetAsVariant: variant; override;
  467. function GetDataSize: Word; override;
  468. procedure GetText(var theText: string; ADisplayText: Boolean); override;
  469. procedure SetAsDateTime(AValue: TDateTime); override;
  470. procedure SetAsFloat(AValue: Double); override;
  471. procedure SetAsString(const AValue: string); override;
  472. public
  473. constructor Create(AOwner: TComponent); override;
  474. property Value: TDateTime read GetAsDateTime write SetAsDateTime;
  475. published
  476. property DisplayFormat: string read FDisplayFormat write FDisplayFormat;
  477. end;
  478. { TDateField }
  479. TDateField = class(TDateTimeField)
  480. protected
  481. function GetDataSize: Word; override;
  482. public
  483. constructor Create(AOwner: TComponent); override;
  484. end;
  485. { TTimeField }
  486. TTimeField = class(TDateTimeField)
  487. protected
  488. function GetDataSize: Word; override;
  489. public
  490. constructor Create(AOwner: TComponent); override;
  491. end;
  492. { TBinaryField }
  493. TBinaryField = class(TField)
  494. protected
  495. class procedure CheckTypeSize(AValue: Longint); override;
  496. function GetAsString: string; override;
  497. procedure GetText(var TheText: string; ADisplayText: Boolean); override;
  498. procedure SetAsString(const AValue: string); override;
  499. procedure SetText(const AValue: string); override;
  500. public
  501. constructor Create(AOwner: TComponent); override;
  502. published
  503. property Size default 16;
  504. end;
  505. { TBytesField }
  506. TBytesField = class(TBinaryField)
  507. protected
  508. function GetDataSize: Word; override;
  509. public
  510. constructor Create(AOwner: TComponent); override;
  511. end;
  512. { TVarBytesField }
  513. TVarBytesField = class(TBytesField)
  514. protected
  515. function GetDataSize: Word; override;
  516. public
  517. constructor Create(AOwner: TComponent); override;
  518. end;
  519. { TBCDField }
  520. TBCDField = class(TNumericField)
  521. private
  522. FMinValue,
  523. FMaxValue : currency;
  524. FPrecision : Longint;
  525. FCurrency : boolean;
  526. protected
  527. class procedure CheckTypeSize(AValue: Longint); override;
  528. function GetAsCurrency: Currency; virtual;
  529. function GetAsFloat: Double; override;
  530. function GetAsLongint: Longint; override;
  531. function GetAsString: string; override;
  532. function GetAsVariant: variant; override;
  533. function GetDataSize: Word; override;
  534. function GetDefaultWidth: Longint; override;
  535. procedure GetText(var TheText: string; ADisplayText: Boolean); override;
  536. procedure SetAsFloat(AValue: Double); override;
  537. procedure SetAsLongint(AValue: Longint); override;
  538. procedure SetAsString(const AValue: string); override;
  539. procedure SetAsCurrency(AValue: Currency); virtual;
  540. public
  541. constructor Create(AOwner: TComponent); override;
  542. Function CheckRange(AValue : Currency) : Boolean;
  543. property Value: Longint read GetAsLongint write SetAsLongint;
  544. published
  545. property Precision: Longint read FPrecision write FPrecision;
  546. property Currency: Boolean read FCurrency write FCurrency;
  547. property MaxValue: Currency read FMaxValue write FMaxValue;
  548. property MinValue: Currency read FMinValue write FMinValue;
  549. property Size default 4;
  550. end;
  551. { TBlobField }
  552. TBlobStreamMode = (bmRead, bmWrite, bmReadWrite);
  553. TBlobType = ftBlob..ftTypedBinary;
  554. TBlobField = class(TField)
  555. private
  556. FBlobSize : Longint;
  557. FBlobType : TBlobType;
  558. FModified : Boolean;
  559. FTransliterate : Boolean;
  560. Function GetBlobStream (Mode : TBlobStreamMode) : TStream;
  561. protected
  562. procedure AssignTo(Dest: TPersistent); override;
  563. procedure FreeBuffers; override;
  564. function GetAsString: string; override;
  565. function GetBlobSize: Longint; virtual;
  566. function GetIsNull: Boolean; override;
  567. procedure GetText(var TheText: string; ADisplayText: Boolean); override;
  568. procedure SetAsString(const AValue: string); override;
  569. procedure SetText(const AValue: string); override;
  570. public
  571. constructor Create(AOwner: TComponent); override;
  572. procedure Assign(Source: TPersistent); override;
  573. procedure Clear; override;
  574. class function IsBlob: Boolean; override;
  575. procedure LoadFromFile(const FileName: string);
  576. procedure LoadFromStream(Stream: TStream);
  577. procedure SaveToFile(const FileName: string);
  578. procedure SaveToStream(Stream: TStream);
  579. procedure SetFieldType(AValue: TFieldType); override;
  580. property BlobSize: Longint read FBlobSize;
  581. property Modified: Boolean read FModified write FModified;
  582. property Value: string read GetAsString write SetAsString;
  583. property Transliterate: Boolean read FTransliterate write FTransliterate;
  584. published
  585. property BlobType: TBlobType read FBlobType write FBlobType;
  586. property Size default 0;
  587. end;
  588. { TMemoField }
  589. TMemoField = class(TBlobField)
  590. public
  591. constructor Create(AOwner: TComponent); override;
  592. published
  593. property Transliterate default True;
  594. end;
  595. { TGraphicField }
  596. TGraphicField = class(TBlobField)
  597. public
  598. constructor Create(AOwner: TComponent); override;
  599. end;
  600. { TIndexDef }
  601. TIndexDefs = class;
  602. TIndexOptions = set of (ixPrimary, ixUnique, ixDescending,
  603. ixCaseInsensitive, ixExpression);
  604. TIndexDef = class(TCollectionItem)
  605. Private
  606. FExpression : String;
  607. FFields : String;
  608. FName : String;
  609. FOptions : TIndexOptions;
  610. FSource : String;
  611. public
  612. constructor Create(Owner: TIndexDefs; const AName, TheFields: string;
  613. TheOptions: TIndexOptions);
  614. destructor Destroy; override;
  615. property Expression: string read FExpression;
  616. property Fields: string read FFields write FFields;
  617. property Name: string read FName write FName;
  618. property Options: TIndexOptions read FOptions write FOptions;
  619. property Source: string read FSource write FSource;
  620. end;
  621. { TIndexDefs }
  622. TIndexDefs = class(TOwnedCollection)
  623. Private
  624. FUpDated : Boolean;
  625. FDataset : Tdataset;
  626. Function GetItem(Index: Integer): TIndexDef;
  627. Procedure SetItem(Index: Integer; Value: TIndexDef);
  628. public
  629. constructor Create(DataSet: TDataSet); overload;
  630. destructor Destroy; override;
  631. procedure Add(const Name, Fields: string; Options: TIndexOptions);
  632. Function AddIndexDef: TIndexDef;
  633. procedure Assign(IndexDefs: TIndexDefs);
  634. // procedure Clear;
  635. function FindIndexForFields(const Fields: string): TIndexDef;
  636. function GetIndexForFields(const Fields: string;
  637. CaseInsensitive: Boolean): TIndexDef;
  638. // function IndexOf(const Name: string): Longint;
  639. procedure Update;
  640. // property Count: Longint read FCount;
  641. Property Items[Index: Integer] : TIndexDef read GetItem write SetItem; default;
  642. property Updated: Boolean read FUpdated write FUpdated;
  643. end;
  644. { TCheckConstraint }
  645. TCheckConstraint = class(TCollectionItem)
  646. Private
  647. FCustomConstraint : String;
  648. FErrorMessage : String;
  649. FFromDictionary : Boolean;
  650. FImportedConstraint : String;
  651. public
  652. procedure Assign(Source: TPersistent); override;
  653. // function GetDisplayName: string; override;
  654. published
  655. property CustomConstraint: string read FCustomConstraint write FCustomConstraint;
  656. property ErrorMessage: string read FErrorMessage write FErrorMessage;
  657. property FromDictionary: Boolean read FFromDictionary write FFromDictionary;
  658. property ImportedConstraint: string read FImportedConstraint write FImportedConstraint;
  659. end;
  660. { TCheckConstraints }
  661. TCheckConstraints = class(TCollection)
  662. Private
  663. Function GetItem(Index : Longint) : TCheckConstraint;
  664. Procedure SetItem(index : Longint; Value : TCheckConstraint);
  665. protected
  666. function GetOwner: TPersistent; override;
  667. public
  668. constructor Create(AOwner: TPersistent);
  669. function Add: TCheckConstraint;
  670. property Items[Index: Longint]: TCheckConstraint read GetItem write SetItem; default;
  671. end;
  672. { TFields }
  673. Tfields = Class(TObject)
  674. Private
  675. FDataset : TDataset;
  676. FFieldList : TList;
  677. FOnChange : TNotifyEvent;
  678. FValidFieldKinds : TFieldKinds;
  679. Protected
  680. Procedure Changed;
  681. Procedure CheckfieldKind(Fieldkind : TFieldKind; Field : TField);
  682. Function GetCount : Longint;
  683. Function GetField (Index : longint) : TField;
  684. Procedure SetFieldIndex (Field : TField;Value : Integer);
  685. Property OnChange : TNotifyEvent Read FOnChange Write FOnChange;
  686. Property ValidFieldKinds : TFieldKinds Read FValidFieldKinds;
  687. Public
  688. Constructor Create(ADataset : TDataset);
  689. Destructor Destroy;override;
  690. Procedure Add(Field : TField);
  691. Procedure CheckFieldName (Const Value : String);
  692. Procedure CheckFieldNames (Const Value : String);
  693. Procedure Clear;
  694. Function FindField (Const Value : String) : TField;
  695. Function FieldByName (Const Value : String) : TField;
  696. Function FieldByNumber(FieldNo : Integer) : TField;
  697. Procedure GetFieldNames (Values : TStrings);
  698. Function IndexOf(Field : TField) : Longint;
  699. procedure Remove(Value : TField);
  700. Property Count : Integer Read GetCount;
  701. Property Dataset : TDataset Read FDataset;
  702. Property Fields [Index : Integer] : TField Read GetField; default;
  703. end;
  704. { TDataSet }
  705. TBookmark = Pointer;
  706. TBookmarkStr = string;
  707. PBookmarkFlag = ^TBookmarkFlag;
  708. TBookmarkFlag = (bfCurrent, bfBOF, bfEOF, bfInserted);
  709. PBufferList = ^TBufferList;
  710. TBufferList = array[0..dsMaxBufferCount - 1] of PChar;
  711. TGetMode = (gmCurrent, gmNext, gmPrior);
  712. TGetResult = (grOK, grBOF, grEOF, grError);
  713. TResyncMode = set of (rmExact, rmCenter);
  714. TDataAction = (daFail, daAbort, daRetry);
  715. TUpdateKind = (ukModify, ukInsert, ukDelete);
  716. TLocateOption = (loCaseInsensitive, loPartialKey);
  717. TLocateOptions = set of TLocateOption;
  718. TDataOperation = procedure of object;
  719. TDataSetNotifyEvent = procedure(DataSet: TDataSet) of object;
  720. TDataSetErrorEvent = procedure(DataSet: TDataSet; E: EDatabaseError;
  721. var Action: TDataAction) of object;
  722. TFilterOption = (foCaseInsensitive, foNoPartialCompare);
  723. TFilterOptions = set of TFilterOption;
  724. TFilterRecordEvent = procedure(DataSet: TDataSet;
  725. var Accept: Boolean) of object;
  726. TDatasetClass = Class of TDataset;
  727. TBufferArray = ^pchar;
  728. TDataSet = class(TComponent)
  729. Private
  730. FOpenAfterRead : boolean;
  731. FActiveRecord: Longint;
  732. FAfterCancel: TDataSetNotifyEvent;
  733. FAfterClose: TDataSetNotifyEvent;
  734. FAfterDelete: TDataSetNotifyEvent;
  735. FAfterEdit: TDataSetNotifyEvent;
  736. FAfterInsert: TDataSetNotifyEvent;
  737. FAfterOpen: TDataSetNotifyEvent;
  738. FAfterPost: TDataSetNotifyEvent;
  739. FAfterScroll: TDataSetNotifyEvent;
  740. FAutoCalcFields: Boolean;
  741. FBOF: Boolean;
  742. FBeforeCancel: TDataSetNotifyEvent;
  743. FBeforeClose: TDataSetNotifyEvent;
  744. FBeforeDelete: TDataSetNotifyEvent;
  745. FBeforeEdit: TDataSetNotifyEvent;
  746. FBeforeInsert: TDataSetNotifyEvent;
  747. FBeforeOpen: TDataSetNotifyEvent;
  748. FBeforePost: TDataSetNotifyEvent;
  749. FBeforeScroll: TDataSetNotifyEvent;
  750. FBlobFieldCount: Longint;
  751. FBookmarkSize: Longint;
  752. FBuffers : TBufferArray;
  753. FBufferCount: Longint;
  754. FCalcBuffer: PChar;
  755. FCalcFieldsSize: Longint;
  756. FCanModify: Boolean;
  757. FConstraints: TCheckConstraints;
  758. FDisableControlsCount : Integer;
  759. FDisableControlsState : TDatasetState;
  760. FCurrentRecord: Longint;
  761. FDataSources : TList;
  762. FDefaultFields: Boolean;
  763. FEOF: Boolean;
  764. FEnableControlsEvent : TDataEvent;
  765. FFieldList : TFields;
  766. FFieldCount : Longint;
  767. FFieldDefs: TFieldDefs;
  768. FFilterOptions: TFilterOptions;
  769. FFilterText: string;
  770. FFiltered: Boolean;
  771. FFound: Boolean;
  772. FInternalCalcFields: Boolean;
  773. FModified: Boolean;
  774. FOnCalcFields: TDataSetNotifyEvent;
  775. FOnDeleteError: TDataSetErrorEvent;
  776. FOnEditError: TDataSetErrorEvent;
  777. FOnFilterRecord: TFilterRecordEvent;
  778. FOnNewRecord: TDataSetNotifyEvent;
  779. FOnPostError: TDataSetErrorEvent;
  780. FRecordCount: Longint;
  781. FIsUniDirectional: Boolean;
  782. FState : TDataSetState;
  783. Procedure DoInsertAppend(DoAppend : Boolean);
  784. Procedure DoInternalOpen;
  785. Procedure DoInternalClose(DoCheck : Boolean);
  786. Function GetBuffer (Index : longint) : Pchar;
  787. Function GetField (Index : Longint) : TField;
  788. Procedure RegisterDataSource(ADatasource : TDataSource);
  789. Procedure RemoveField (Field : TField);
  790. Procedure SetActive (Value : Boolean);
  791. Procedure SetField (Index : Longint;Value : TField);
  792. Procedure ShiftBuffersForward;
  793. Procedure ShiftBuffersBackward;
  794. Function TryDoing (P : TDataOperation; Ev : TDatasetErrorEvent) : Boolean;
  795. Function GetActive : boolean;
  796. Procedure UnRegisterDataSource(ADatasource : TDatasource);
  797. Procedure UpdateFieldDefs;
  798. protected
  799. procedure RecalcBufListSize;
  800. procedure ActivateBuffers; virtual;
  801. procedure BindFields(Binding: Boolean);
  802. function BookmarkAvailable: Boolean;
  803. procedure CalculateFields(Buffer: PChar); virtual;
  804. procedure CheckActive; virtual;
  805. procedure CheckInactive; virtual;
  806. procedure Loaded; override;
  807. procedure ClearBuffers; virtual;
  808. procedure ClearCalcFields(Buffer: PChar); virtual;
  809. procedure CloseBlob(Field: TField); virtual;
  810. procedure CloseCursor; virtual;
  811. procedure CreateFields;
  812. procedure DataEvent(Event: TDataEvent; Info: Ptrint); virtual;
  813. procedure DestroyFields; virtual;
  814. procedure DoAfterCancel; virtual;
  815. procedure DoAfterClose; virtual;
  816. procedure DoAfterDelete; virtual;
  817. procedure DoAfterEdit; virtual;
  818. procedure DoAfterInsert; virtual;
  819. procedure DoAfterOpen; virtual;
  820. procedure DoAfterPost; virtual;
  821. procedure DoAfterScroll; virtual;
  822. procedure DoBeforeCancel; virtual;
  823. procedure DoBeforeClose; virtual;
  824. procedure DoBeforeDelete; virtual;
  825. procedure DoBeforeEdit; virtual;
  826. procedure DoBeforeInsert; virtual;
  827. procedure DoBeforeOpen; virtual;
  828. procedure DoBeforePost; virtual;
  829. procedure DoBeforeScroll; virtual;
  830. procedure DoOnCalcFields; virtual;
  831. procedure DoOnNewRecord; virtual;
  832. function FieldByNumber(FieldNo: Longint): TField;
  833. function FindRecord(Restart, GoForward: Boolean): Boolean; virtual;
  834. procedure FreeFieldBuffers; virtual;
  835. function GetBookmarkStr: TBookmarkStr; virtual;
  836. procedure GetCalcFields(Buffer: PChar); virtual;
  837. function GetCanModify: Boolean; virtual;
  838. procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
  839. function GetFieldClass(FieldType: TFieldType): TFieldClass; virtual;
  840. Function GetfieldCount : Integer;
  841. function GetFieldValues(fieldname : string) : string; virtual;
  842. function GetIsIndexField(Field: TField): Boolean; virtual;
  843. function GetNextRecords: Longint; virtual;
  844. function GetNextRecord: Boolean; virtual;
  845. function GetPriorRecords: Longint; virtual;
  846. function GetPriorRecord: Boolean; virtual;
  847. function GetRecordCount: Longint; virtual;
  848. function GetRecNo: Longint; virtual;
  849. procedure InitFieldDefs; virtual;
  850. procedure InitRecord(Buffer: PChar); virtual;
  851. procedure InternalCancel; virtual;
  852. procedure InternalEdit; virtual;
  853. procedure InternalRefresh; virtual;
  854. procedure OpenCursor(InfoQuery: Boolean); virtual;
  855. procedure RefreshInternalCalcFields(Buffer: PChar); virtual;
  856. procedure RestoreState(const Value: TDataSetState);
  857. procedure SetBookmarkStr(const Value: TBookmarkStr); virtual;
  858. procedure SetBufListSize(Value: Longint);
  859. procedure SetChildOrder(Component: TComponent; Order: Longint); override;
  860. procedure SetCurrentRecord(Index: Longint); virtual;
  861. procedure SetFiltered(Value: Boolean); virtual;
  862. procedure SetFilterOptions(Value: TFilterOptions); virtual;
  863. procedure SetFilterText(const Value: string); virtual;
  864. procedure SetFound(const Value: Boolean);
  865. procedure SetFieldValues(fieldname : string;value : string); virtual;
  866. procedure SetModified(Value: Boolean);
  867. procedure SetName(const Value: TComponentName); override;
  868. procedure SetOnFilterRecord(const Value: TFilterRecordEvent); virtual;
  869. procedure SetRecNo(Value: Longint); virtual;
  870. procedure SetState(Value: TDataSetState);
  871. function SetTempState(const Value: TDataSetState): TDataSetState;
  872. function TempBuffer: PChar;
  873. procedure UpdateIndexDefs; virtual;
  874. property ActiveRecord: Longint read FActiveRecord;
  875. property CurrentRecord: Longint read FCurrentRecord;
  876. property BlobFieldCount: Longint read FBlobFieldCount;
  877. property BookmarkSize: Longint read FBookmarkSize write FBookmarkSize;
  878. property Buffers[Index: Longint]: PChar read GetBuffer;
  879. property BufferCount: Longint read FBufferCount;
  880. property CalcBuffer: PChar read FCalcBuffer;
  881. property CalcFieldsSize: Longint read FCalcFieldsSize;
  882. property InternalCalcFields: Boolean read FInternalCalcFields;
  883. property Constraints: TCheckConstraints read FConstraints write FConstraints;
  884. protected { abstract methods }
  885. function AllocRecordBuffer: PChar; virtual; abstract;
  886. procedure FreeRecordBuffer(var Buffer: PChar); virtual; abstract;
  887. procedure GetBookmarkData(Buffer: PChar; Data: Pointer); virtual; abstract;
  888. function GetBookmarkFlag(Buffer: PChar): TBookmarkFlag; virtual; abstract;
  889. function GetDataSource: TDataSource; virtual;
  890. function GetFieldData(Field: TField; Buffer: Pointer): Boolean; virtual; abstract;
  891. function GetRecord(Buffer: PChar; GetMode: TGetMode; DoCheck: Boolean): TGetResult; virtual; abstract;
  892. function GetRecordSize: Word; virtual; abstract;
  893. procedure InternalAddRecord(Buffer: Pointer; Append: Boolean); virtual; abstract;
  894. procedure InternalClose; virtual; abstract;
  895. procedure InternalDelete; virtual; abstract;
  896. procedure InternalFirst; virtual; abstract;
  897. procedure InternalGotoBookmark(ABookmark: Pointer); virtual; abstract;
  898. procedure InternalHandleException; virtual; abstract;
  899. procedure InternalInitFieldDefs; virtual; abstract;
  900. procedure InternalInitRecord(Buffer: PChar); virtual; abstract;
  901. procedure InternalLast; virtual; abstract;
  902. procedure InternalOpen; virtual; abstract;
  903. procedure InternalPost; virtual; abstract;
  904. procedure InternalSetToRecord(Buffer: PChar); virtual; abstract;
  905. function IsCursorOpen: Boolean; virtual; abstract;
  906. procedure SetBookmarkFlag(Buffer: PChar; Value: TBookmarkFlag); virtual; abstract;
  907. procedure SetBookmarkData(Buffer: PChar; Data: Pointer); virtual; abstract;
  908. procedure SetFieldData(Field: TField; Buffer: Pointer); virtual; abstract;
  909. public
  910. constructor Create(AOwner: TComponent); override;
  911. destructor Destroy; override;
  912. function ActiveBuffer: PChar;
  913. procedure Append;
  914. procedure AppendRecord(const Values: array of const);
  915. function BookmarkValid(ABookmark: TBookmark): Boolean; virtual;
  916. procedure Cancel; virtual;
  917. procedure CheckBrowseMode;
  918. procedure ClearFields;
  919. procedure Close;
  920. function ControlsDisabled: Boolean;
  921. function CompareBookmarks(Bookmark1, Bookmark2: TBookmark): Longint; virtual;
  922. function CreateBlobStream(Field: TField; Mode: TBlobStreamMode): TStream; virtual;
  923. procedure CursorPosChanged;
  924. procedure Delete;
  925. procedure DisableControls;
  926. procedure Edit;
  927. procedure EnableControls;
  928. function FieldByName(const FieldName: string): TField;
  929. function FindField(const FieldName: string): TField;
  930. function FindFirst: Boolean;
  931. function FindLast: Boolean;
  932. function FindNext: Boolean;
  933. function FindPrior: Boolean;
  934. procedure First;
  935. procedure FreeBookmark(ABookmark: TBookmark); virtual;
  936. function GetBookmark: TBookmark; virtual;
  937. function GetCurrentRecord(Buffer: PChar): Boolean; virtual;
  938. procedure GetFieldList(List: TList; const FieldNames: string);
  939. procedure GetFieldNames(List: TStrings);
  940. procedure GotoBookmark(ABookmark: TBookmark);
  941. procedure Insert;
  942. procedure InsertRecord(const Values: array of const);
  943. function IsEmpty: Boolean;
  944. function IsSequenced: Boolean; virtual;
  945. procedure Last;
  946. function MoveBy(Distance: Longint): Longint;
  947. procedure Next;
  948. procedure Open;
  949. procedure Post; virtual;
  950. procedure Prior;
  951. procedure Refresh;
  952. procedure Resync(Mode: TResyncMode); virtual;
  953. procedure SetFields(const Values: array of const);
  954. function Translate(Src, Dest: PChar; ToOem: Boolean): Integer; virtual;
  955. procedure UpdateCursorPos;
  956. procedure UpdateRecord;
  957. property BOF: Boolean read FBOF;
  958. property Bookmark: TBookmarkStr read GetBookmarkStr write SetBookmarkStr;
  959. property CanModify: Boolean read GetCanModify;
  960. property DataSource: TDataSource read GetDataSource;
  961. property DefaultFields: Boolean read FDefaultFields;
  962. property EOF: Boolean read FEOF;
  963. property FieldCount: Longint read GetFieldCount;
  964. property FieldDefs: TFieldDefs read FFieldDefs write FFieldDefs;
  965. // property Fields[Index: Longint]: TField read GetField write SetField;
  966. property Found: Boolean read FFound;
  967. property Modified: Boolean read FModified write SetModified;
  968. property IsUniDirectional: Boolean read FIsUniDirectional write FIsUniDirectional default False;
  969. property RecordCount: Longint read GetRecordCount;
  970. property RecNo: Longint read GetRecNo write SetRecNo;
  971. property RecordSize: Word read GetRecordSize;
  972. property State: TDataSetState read FState;
  973. property Fields : TFields read FFieldList;
  974. property FieldValues[fieldname : string] : string read GetFieldValues write SetFieldValues; default;
  975. property Filter: string read FFilterText write SetFilterText;
  976. property Filtered: Boolean read FFiltered write SetFiltered default False;
  977. property FilterOptions: TFilterOptions read FFilterOptions write FFilterOptions;
  978. property Active: Boolean read GetActive write SetActive default False;
  979. property AutoCalcFields: Boolean read FAutoCalcFields write FAutoCalcFields;
  980. property BeforeOpen: TDataSetNotifyEvent read FBeforeOpen write FBeforeOpen;
  981. property AfterOpen: TDataSetNotifyEvent read FAfterOpen write FAfterOpen;
  982. property BeforeClose: TDataSetNotifyEvent read FBeforeClose write FBeforeClose;
  983. property AfterClose: TDataSetNotifyEvent read FAfterClose write FAfterClose;
  984. property BeforeInsert: TDataSetNotifyEvent read FBeforeInsert write FBeforeInsert;
  985. property AfterInsert: TDataSetNotifyEvent read FAfterInsert write FAfterInsert;
  986. property BeforeEdit: TDataSetNotifyEvent read FBeforeEdit write FBeforeEdit;
  987. property AfterEdit: TDataSetNotifyEvent read FAfterEdit write FAfterEdit;
  988. property BeforePost: TDataSetNotifyEvent read FBeforePost write FBeforePost;
  989. property AfterPost: TDataSetNotifyEvent read FAfterPost write FAfterPost;
  990. property BeforeCancel: TDataSetNotifyEvent read FBeforeCancel write FBeforeCancel;
  991. property AfterCancel: TDataSetNotifyEvent read FAfterCancel write FAfterCancel;
  992. property BeforeDelete: TDataSetNotifyEvent read FBeforeDelete write FBeforeDelete;
  993. property AfterDelete: TDataSetNotifyEvent read FAfterDelete write FAfterDelete;
  994. property BeforeScroll: TDataSetNotifyEvent read FBeforeScroll write FBeforeScroll;
  995. property AfterScroll: TDataSetNotifyEvent read FAfterScroll write FAfterScroll;
  996. property OnCalcFields: TDataSetNotifyEvent read FOnCalcFields write FOnCalcFields;
  997. property OnDeleteError: TDataSetErrorEvent read FOnDeleteError write FOnDeleteError;
  998. property OnEditError: TDataSetErrorEvent read FOnEditError write FOnEditError;
  999. property OnFilterRecord: TFilterRecordEvent read FOnFilterRecord write SetOnFilterRecord;
  1000. property OnNewRecord: TDataSetNotifyEvent read FOnNewRecord write FOnNewRecord;
  1001. property OnPostError: TDataSetErrorEvent read FOnPostError write FOnPostError;
  1002. end;
  1003. TDataLink = class(TPersistent)
  1004. private
  1005. FFIrstRecord,
  1006. FBufferCount : Integer;
  1007. FActive,
  1008. FDataSourceFixed,
  1009. FEditing,
  1010. FReadOnly,
  1011. FUpdatingRecord,
  1012. FVisualControl : Boolean;
  1013. FDataSource : TDataSource;
  1014. Function CalcFirstRecord(Index : Integer) : Integer;
  1015. Procedure CalcRange;
  1016. Procedure CheckActiveAndEditing;
  1017. Function GetDataset : TDataset;
  1018. procedure SetActive(AActive: Boolean);
  1019. procedure SetDataSource(Value: TDataSource);
  1020. Procedure SetReadOnly(Value : Boolean);
  1021. protected
  1022. procedure ActiveChanged; virtual;
  1023. procedure CheckBrowseMode; virtual;
  1024. procedure DataEvent(Event: TDataEvent; Info: Ptrint); virtual;
  1025. procedure DataSetChanged; virtual;
  1026. procedure DataSetScrolled(Distance: Integer); virtual;
  1027. procedure EditingChanged; virtual;
  1028. procedure FocusControl(Field: TFieldRef); virtual;
  1029. function GetActiveRecord: Integer; virtual;
  1030. function GetBOF: Boolean; virtual;
  1031. function GetBufferCount: Integer; virtual;
  1032. function GetEOF: Boolean; virtual;
  1033. function GetRecordCount: Integer; virtual;
  1034. procedure LayoutChanged; virtual;
  1035. function MoveBy(Distance: Integer): Integer; virtual;
  1036. procedure RecordChanged(Field: TField); virtual;
  1037. procedure SetActiveRecord(Value: Integer); virtual;
  1038. procedure SetBufferCount(Value: Integer); virtual;
  1039. procedure UpdateData; virtual;
  1040. property VisualControl: Boolean read FVisualControl write FVisualControl;
  1041. public
  1042. constructor Create;
  1043. destructor Destroy; override;
  1044. function Edit: Boolean;
  1045. procedure UpdateRecord;
  1046. property Active: Boolean read FActive;
  1047. property ActiveRecord: Integer read GetActiveRecord write SetActiveRecord;
  1048. property BOF: Boolean read GetBOF;
  1049. property BufferCount: Integer read FBufferCount write SetBufferCount;
  1050. property DataSet: TDataSet read GetDataSet;
  1051. property DataSource: TDataSource read FDataSource write SetDataSource;
  1052. property DataSourceFixed: Boolean read FDataSourceFixed write FDataSourceFixed;
  1053. property Editing: Boolean read FEditing;
  1054. property Eof: Boolean read GetEOF;
  1055. property ReadOnly: Boolean read FReadOnly write SetReadOnly;
  1056. property RecordCount: Integer read GetRecordCount;
  1057. end;
  1058. { TDetailDataLink }
  1059. TDetailDataLink = class(TDataLink)
  1060. protected
  1061. function GetDetailDataSet: TDataSet; virtual;
  1062. public
  1063. property DetailDataSet: TDataSet read GetDetailDataSet;
  1064. end;
  1065. { TMasterDataLink }
  1066. TMasterDataLink = class(TDetailDataLink)
  1067. private
  1068. FDataSet: TDataSet;
  1069. FFieldNames: string;
  1070. FFields: TList;
  1071. FOnMasterChange: TNotifyEvent;
  1072. FOnMasterDisable: TNotifyEvent;
  1073. procedure SetFieldNames(const Value: string);
  1074. protected
  1075. procedure ActiveChanged; override;
  1076. procedure CheckBrowseMode; override;
  1077. function GetDetailDataSet: TDataSet; override;
  1078. procedure LayoutChanged; override;
  1079. procedure RecordChanged(Field: TField); override;
  1080. public
  1081. constructor Create(ADataSet: TDataSet);
  1082. destructor Destroy; override;
  1083. property FieldNames: string read FFieldNames write SetFieldNames;
  1084. property Fields: TList read FFields;
  1085. property OnMasterChange: TNotifyEvent read FOnMasterChange write FOnMasterChange;
  1086. property OnMasterDisable: TNotifyEvent read FOnMasterDisable write FOnMasterDisable;
  1087. end;
  1088. { TDataSource }
  1089. TDataChangeEvent = procedure(Sender: TObject; Field: TField) of object;
  1090. TDataSource = class(TComponent)
  1091. private
  1092. FDataSet: TDataSet;
  1093. FDataLinks: TList;
  1094. FEnabled: Boolean;
  1095. FAutoEdit: Boolean;
  1096. FState: TDataSetState;
  1097. FOnStateChange: TNotifyEvent;
  1098. FOnDataChange: TDataChangeEvent;
  1099. FOnUpdateData: TNotifyEvent;
  1100. procedure DistributeEvent(Event: TDataEvent; Info: Ptrint);
  1101. procedure RegisterDataLink(DataLink: TDataLink);
  1102. Procedure ProcessEvent(Event : TDataEvent; Info : Ptrint);
  1103. procedure SetDataSet(ADataSet: TDataSet);
  1104. procedure SetEnabled(Value: Boolean);
  1105. procedure UnregisterDataLink(DataLink: TDataLink);
  1106. protected
  1107. Procedure DoDataChange (Info : Pointer);virtual;
  1108. Procedure DoStateChange; virtual;
  1109. Procedure DoUpdateData;
  1110. property DataLinks: TList read FDataLinks;
  1111. public
  1112. constructor Create(AOwner: TComponent); override;
  1113. destructor Destroy; override;
  1114. procedure Edit;
  1115. function IsLinkedTo(ADataSet: TDataSet): Boolean;
  1116. property State: TDataSetState read FState;
  1117. published
  1118. property AutoEdit: Boolean read FAutoEdit write FAutoEdit default True;
  1119. property DataSet: TDataSet read FDataSet write SetDataSet;
  1120. property Enabled: Boolean read FEnabled write SetEnabled default True;
  1121. property OnStateChange: TNotifyEvent read FOnStateChange write FOnStateChange;
  1122. property OnDataChange: TDataChangeEvent read FOnDataChange write FOnDataChange;
  1123. property OnUpdateData: TNotifyEvent read FOnUpdateData write FOnUpdateData;
  1124. end;
  1125. { TDBDataset }
  1126. TDBDatasetClass = Class of TDBDataset;
  1127. TDBDataset = Class(TDataset)
  1128. Private
  1129. FDatabase : TDatabase;
  1130. FTransaction : TDBTransaction;
  1131. Protected
  1132. Procedure SetDatabase (Value : TDatabase); virtual;
  1133. Procedure SetTransaction(Value : TDBTransaction); virtual;
  1134. Procedure CheckDatabase;
  1135. Public
  1136. Destructor destroy; override;
  1137. Property DataBase : TDatabase Read FDatabase Write SetDatabase;
  1138. Property Transaction : TDBTransaction Read FTransaction Write SetTransaction;
  1139. end;
  1140. { TDBTransaction }
  1141. TDBTransactionClass = Class of TDBTransaction;
  1142. TDBTransaction = Class(TComponent)
  1143. Private
  1144. FActive : boolean;
  1145. FDatabase : TDatabase;
  1146. FDataSets : TList;
  1147. FOpenAfterRead : boolean;
  1148. Procedure SetDatabase (Value : TDatabase);
  1149. Function GetDataSetCount : Longint;
  1150. Function GetDataset(Index : longint) : TDBDataset;
  1151. procedure RegisterDataset (DS : TDBDataset);
  1152. procedure UnRegisterDataset (DS : TDBDataset);
  1153. procedure RemoveDataSets;
  1154. procedure SetActive(Value : boolean);
  1155. Protected
  1156. procedure CloseTrans;
  1157. procedure openTrans;
  1158. Procedure CheckDatabase;
  1159. Procedure CheckActive;
  1160. Procedure CheckInactive;
  1161. procedure EndTransaction; virtual; abstract;
  1162. procedure StartTransaction; virtual; abstract;
  1163. procedure Loaded; override;
  1164. Public
  1165. constructor Create(AOwner: TComponent); override;
  1166. Destructor destroy; override;
  1167. procedure CloseDataSets;
  1168. Property DataBase : TDatabase Read FDatabase Write SetDatabase;
  1169. published
  1170. property Active : boolean read FActive write setactive;
  1171. end;
  1172. { TDatabase }
  1173. TLoginEvent = procedure(Database: TDatabase;
  1174. LoginParams: TStrings) of object;
  1175. TDatabaseClass = Class Of TDatabase;
  1176. TDatabase = class(TComponent)
  1177. private
  1178. FConnected : Boolean;
  1179. FDataBaseName : String;
  1180. FDataSets : TList;
  1181. FTransactions : TList;
  1182. FDirectory : String;
  1183. FKeepConnection : Boolean;
  1184. FLoginPrompt : Boolean;
  1185. FOnLogin : TLoginEvent;
  1186. FParams : TStrings;
  1187. FSQLBased : Boolean;
  1188. FOpenAfterRead : boolean;
  1189. Function GetDataSetCount : Longint;
  1190. Function GetTransactionCount : Longint;
  1191. Function GetDataset(Index : longint) : TDBDataset;
  1192. Function GetTransaction(Index : longint) : TDBTransaction;
  1193. procedure SetConnected (Value : boolean);
  1194. procedure RegisterDataset (DS : TDBDataset);
  1195. procedure RegisterTransaction (TA : TDBTransaction);
  1196. procedure UnRegisterDataset (DS : TDBDataset);
  1197. procedure UnRegisterTransaction(TA : TDBTransaction);
  1198. procedure RemoveDataSets;
  1199. procedure RemoveTransactions;
  1200. protected
  1201. Procedure CheckConnected;
  1202. Procedure CheckDisConnected;
  1203. procedure Loaded; override;
  1204. procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  1205. Procedure DoInternalConnect; Virtual;Abstract;
  1206. Procedure DoInternalDisConnect; Virtual;Abstract;
  1207. public
  1208. constructor Create(AOwner: TComponent); override;
  1209. destructor Destroy; override;
  1210. procedure Close;
  1211. procedure Open;
  1212. procedure CloseDataSets;
  1213. procedure CloseTransactions;
  1214. // procedure ApplyUpdates;
  1215. procedure StartTransaction; virtual; abstract;
  1216. procedure EndTransaction; virtual; abstract;
  1217. property DataSetCount: Longint read GetDataSetCount;
  1218. property DataSets[Index: Longint]: TDBDataSet read GetDataSet;
  1219. property TransactionCount: Longint read GetTransactionCount;
  1220. property Transactions[Index: Longint]: TDBTransaction read GetTransaction;
  1221. property Directory: string read FDirectory write FDirectory;
  1222. property IsSQLBased: Boolean read FSQLBased;
  1223. published
  1224. property Connected: Boolean read FConnected write SetConnected;
  1225. property DatabaseName: string read FDatabaseName write FDatabaseName;
  1226. property KeepConnection: Boolean read FKeepConnection write FKeepConnection;
  1227. property LoginPrompt: Boolean read FLoginPrompt write FLoginPrompt;
  1228. property Params : TStrings read FParams Write FParams;
  1229. property OnLogin: TLoginEvent read FOnLogin write FOnLogin;
  1230. end;
  1231. { TBufDataset }
  1232. PBufBookmark = ^TBufBookmark;
  1233. TBufBookmark = record
  1234. BookmarkData : integer;
  1235. BookmarkFlag : TBookmarkFlag;
  1236. end;
  1237. PFieldUpdateBuffer = ^TFieldUpdateBuffer;
  1238. TFieldUpdateBuffer = record
  1239. FieldNo : integer;
  1240. NewValue : pointer;
  1241. IsNull : boolean;
  1242. end;
  1243. TFieldsUpdateBuffer = array of TFieldUpdateBuffer;
  1244. PRecUpdateBuffer = ^TRecUpdateBuffer;
  1245. TRecUpdateBuffer = record
  1246. RecordNo : integer;
  1247. FieldsUpdateBuffer : TFieldsUpdateBuffer;
  1248. end;
  1249. TRecordsUpdateBuffer = array of TRecUpdateBuffer;
  1250. TBufDataset = class(TDBDataSet)
  1251. private
  1252. FBBuffers : TBufferArray;
  1253. FBRecordCount : integer;
  1254. FBBufferCount : integer;
  1255. FBCurrentRecord : integer;
  1256. FIsEOF : boolean;
  1257. FIsBOF : boolean;
  1258. FPacketRecords : integer;
  1259. FRecordSize : Integer;
  1260. FNullmaskSize : byte;
  1261. FOpen : Boolean;
  1262. FUpdateBuffer : TRecordsUpdateBuffer;
  1263. FEditBuf : PRecUpdateBuffer;
  1264. procedure CalcRecordSize;
  1265. function LoadBuffer(Buffer : PChar): TGetResult;
  1266. function GetFieldSize(FieldDef : TFieldDef) : longint;
  1267. function GetRecordUpdateBuffer(rno : integer;var RecUpdBuf : PRecUpdateBuffer) : boolean;
  1268. function GetFieldUpdateBuffer(fieldno : integer;RecUpdBuf : PRecUpdateBuffer;var FieldUpdBuf : pFieldUpdateBuffer) : boolean;
  1269. protected
  1270. procedure SetRecNo(Value: Longint); override;
  1271. function GetRecNo: Longint; override;
  1272. function AllocRecordBuffer: PChar; override;
  1273. procedure FreeRecordBuffer(var Buffer: PChar); override;
  1274. procedure InternalInitRecord(Buffer: PChar); override;
  1275. function GetCanModify: Boolean; override;
  1276. function GetRecord(Buffer: PChar; GetMode: TGetMode; DoCheck: Boolean): TGetResult; override;
  1277. procedure InternalOpen; override;
  1278. procedure InternalClose; override;
  1279. function getnextpacket : integer;
  1280. function GetRecordSize: Word; override;
  1281. procedure InternalPost; override;
  1282. procedure InternalEdit; override;
  1283. procedure InternalFirst; override;
  1284. procedure InternalLast; override;
  1285. procedure InternalSetToRecord(Buffer: PChar); override;
  1286. procedure InternalGotoBookmark(ABookmark: Pointer); override;
  1287. procedure SetBookmarkData(Buffer: PChar; Data: Pointer); override;
  1288. procedure SetBookmarkFlag(Buffer: PChar; Value: TBookmarkFlag); override;
  1289. procedure GetBookmarkData(Buffer: PChar; Data: Pointer); override;
  1290. function GetBookmarkFlag(Buffer: PChar): TBookmarkFlag; override;
  1291. function GetFieldData(Field: TField; Buffer: Pointer): Boolean; override;
  1292. procedure SetFieldData(Field: TField; Buffer: Pointer); override;
  1293. function IsCursorOpen: Boolean; override;
  1294. function GetRecordCount: Longint; override;
  1295. function ApplyRecUpdate : boolean; virtual;
  1296. {abstracts, must be overidden by descendents}
  1297. function Fetch : boolean; virtual; abstract;
  1298. function LoadField(FieldDef : TFieldDef;buffer : pointer) : boolean; virtual; abstract;
  1299. public
  1300. constructor Create(AOwner: TComponent); override;
  1301. procedure ApplyUpdates; virtual;
  1302. procedure CancelUpdates; virtual;
  1303. destructor Destroy; override;
  1304. end;
  1305. { TParam }
  1306. TBlobData = string;
  1307. TParamType = (ptUnknown, ptInput, ptOutput, ptInputOutput, ptResult);
  1308. TParamTypes = set of TParamType;
  1309. TParams = class;
  1310. TParam = class(TCollectionItem)
  1311. private
  1312. FNativeStr: string;
  1313. FValue: Variant;
  1314. FPrecision: Integer;
  1315. FNumericScale: Integer;
  1316. FNull: Boolean;
  1317. FName: string;
  1318. FDataType: TFieldType;
  1319. FBound: Boolean;
  1320. FParamType: TParamType;
  1321. FSize: Integer;
  1322. Function GetDataSet: TDataSet;
  1323. Function IsParamStored: Boolean;
  1324. protected
  1325. Procedure AssignParam(Param: TParam);
  1326. Procedure AssignTo(Dest: TPersistent); override;
  1327. Function GetAsBoolean: Boolean;
  1328. Function GetAsCurrency: Currency;
  1329. Function GetAsDateTime: TDateTime;
  1330. Function GetAsFloat: Double;
  1331. Function GetAsInteger: Longint;
  1332. Function GetAsMemo: string;
  1333. Function GetAsString: string;
  1334. Function GetAsVariant: Variant;
  1335. Function GetDisplayName: string; override;
  1336. Function GetIsNull: Boolean;
  1337. Function IsEqual(AValue: TParam): Boolean;
  1338. Procedure SetAsBlob(const AValue: TBlobData);
  1339. Procedure SetAsBoolean(AValue: Boolean);
  1340. Procedure SetAsCurrency(const AValue: Currency);
  1341. Procedure SetAsDate(const AValue: TDateTime);
  1342. Procedure SetAsDateTime(const AValue: TDateTime);
  1343. Procedure SetAsFloat(const AValue: Double);
  1344. Procedure SetAsInteger(AValue: Longint);
  1345. Procedure SetAsMemo(const AValue: string);
  1346. Procedure SetAsSmallInt(AValue: LongInt);
  1347. Procedure SetAsString(const AValue: string);
  1348. Procedure SetAsTime(const AValue: TDateTime);
  1349. Procedure SetAsVariant(const AValue: Variant);
  1350. Procedure SetAsWord(AValue: LongInt);
  1351. Procedure SetDataType(AValue: TFieldType);
  1352. Procedure SetText(const AValue: string);
  1353. public
  1354. constructor Create(ACollection: TCollection); overload; override;
  1355. constructor Create(AParams: TParams; AParamType: TParamType); reintroduce; overload;
  1356. Procedure Assign(Source: TPersistent); override;
  1357. Procedure AssignField(Field: TField);
  1358. Procedure AssignToField(Field: TField);
  1359. Procedure AssignFieldValue(Field: TField; const AValue: Variant);
  1360. Procedure Clear;
  1361. Procedure GetData(Buffer: Pointer);
  1362. Function GetDataSize: Integer;
  1363. Procedure LoadFromFile(const FileName: string; BlobType: TBlobType);
  1364. Procedure LoadFromStream(Stream: TStream; BlobType: TBlobType);
  1365. Procedure SetBlobData(Buffer: Pointer; Size: Integer);
  1366. Procedure SetData(Buffer: Pointer);
  1367. Property AsBlob : TBlobData read GetAsString write SetAsBlob;
  1368. Property AsBoolean : Boolean read GetAsBoolean write SetAsBoolean;
  1369. Property AsCurrency : Currency read GetAsCurrency write SetAsCurrency;
  1370. Property AsDate : TDateTime read GetAsDateTime write SetAsDate;
  1371. Property AsDateTime : TDateTime read GetAsDateTime write SetAsDateTime;
  1372. Property AsFloat : Double read GetAsFloat write SetAsFloat;
  1373. Property AsInteger : LongInt read GetAsInteger write SetAsInteger;
  1374. Property AsMemo : string read GetAsMemo write SetAsMemo;
  1375. Property AsSmallInt : LongInt read GetAsInteger write SetAsSmallInt;
  1376. Property AsString : string read GetAsString write SetAsString;
  1377. Property AsTime : TDateTime read GetAsDateTime write SetAsTime;
  1378. Property AsWord : LongInt read GetAsInteger write SetAsWord;
  1379. Property Bound : Boolean read FBound write FBound;
  1380. Property Dataset : TDataset Read GetDataset;
  1381. Property IsNull : Boolean read GetIsNull;
  1382. Property NativeStr : string read FNativeStr write FNativeStr;
  1383. Property Text : string read GetAsString write SetText;
  1384. Property Value : Variant read GetAsVariant write SetAsVariant stored IsParamStored;
  1385. published
  1386. Property DataType : TFieldType read FDataType write SetDataType;
  1387. Property Name : string read FName write FName;
  1388. Property NumericScale : Integer read FNumericScale write FNumericScale default 0;
  1389. Property ParamType : TParamType read FParamType write FParamType;
  1390. Property Precision : Integer read FPrecision write FPrecision default 0;
  1391. Property Size : Integer read FSize write FSize default 0;
  1392. end;
  1393. { TParams }
  1394. TParams = class(TCollection)
  1395. private
  1396. FOwner: TPersistent;
  1397. Function GetItem(Index: Integer): TParam;
  1398. Function GetParamValue(const ParamName: string): Variant;
  1399. Procedure SetItem(Index: Integer; Value: TParam);
  1400. Procedure SetParamValue(const ParamName: string; const Value: Variant);
  1401. protected
  1402. Procedure AssignTo(Dest: TPersistent); override;
  1403. Function GetDataSet: TDataSet;
  1404. Function GetOwner: TPersistent; override;
  1405. public
  1406. Constructor Create(AOwner: TPersistent); overload;
  1407. Constructor Create; overload;
  1408. Procedure AddParam(Value: TParam);
  1409. Procedure AssignValues(Value: TParams);
  1410. Function CreateParam(FldType: TFieldType; const ParamName: string; ParamType: TParamType): TParam;
  1411. Function FindParam(const Value: string): TParam;
  1412. Procedure GetParamList(List: TList; const ParamNames: string);
  1413. Function IsEqual(Value: TParams): Boolean;
  1414. Function ParamByName(const Value: string): TParam;
  1415. Function ParseSQL(SQL: String; DoCreate: Boolean): String;
  1416. Procedure RemoveParam(Value: TParam);
  1417. Property Dataset : TDataset Read GetDataset;
  1418. Property Items[Index: Integer] : TParam read GetItem write SetItem; default;
  1419. Property ParamValues[const ParamName: string] : Variant read GetParamValue write SetParamValue;
  1420. end;
  1421. const
  1422. FieldTypetoVariantMap : array[TFieldType] of Integer = (varError, varOleStr, varSmallint,
  1423. varInteger, varSmallint, varBoolean, varDouble, varCurrency, varCurrency,
  1424. varDate, varDate, varDate, varOleStr, varOleStr, varInteger, varOleStr,
  1425. varOleStr, varOleStr, varOleStr, varOleStr, varOleStr, varOleStr, varError,
  1426. varOleStr, varOleStr, varError, varError, varError, varError, varError,
  1427. varOleStr, varOleStr, varVariant, varUnknown, varDispatch, varOleStr, varOleStr,varOleStr);
  1428. Const
  1429. Fieldtypenames : Array [TFieldType] of String[15] =
  1430. (
  1431. 'Unknown',
  1432. 'String',
  1433. 'Smallint',
  1434. 'Integer',
  1435. 'Word',
  1436. 'Boolean',
  1437. 'Float',
  1438. 'Currency',
  1439. 'BCD',
  1440. 'Date',
  1441. 'Time',
  1442. 'DateTime',
  1443. 'Bytes',
  1444. 'VarBytes',
  1445. 'AutoInc',
  1446. 'Blob',
  1447. 'Memo',
  1448. 'Graphic',
  1449. 'FmtMemo',
  1450. 'ParadoxOle',
  1451. 'DBaseOle',
  1452. 'TypedBinary',
  1453. 'Cursor',
  1454. 'FixedChar',
  1455. 'WideString',
  1456. 'Largeint',
  1457. 'ADT',
  1458. 'Array',
  1459. 'Reference',
  1460. 'DataSet',
  1461. 'OraBlob',
  1462. 'OraClob',
  1463. 'Variant',
  1464. 'Interface',
  1465. 'IDispatch',
  1466. 'Guid',
  1467. 'TimeStamp',
  1468. 'FMTBcd'
  1469. );
  1470. { 'Unknown',
  1471. 'String',
  1472. 'Smallint',
  1473. 'Integer',
  1474. 'Word',
  1475. 'Boolean',
  1476. 'Float',
  1477. 'Date',
  1478. 'Time',
  1479. 'DateTime',
  1480. 'Bytes',
  1481. 'VarBytes',
  1482. 'AutoInc',
  1483. 'Blob',
  1484. 'Memo',
  1485. 'Graphic',
  1486. 'FmtMemo',
  1487. 'ParadoxOle',
  1488. 'DBaseOle',
  1489. 'TypedBinary',
  1490. 'Cursor'
  1491. );}
  1492. dsEditModes = [dsEdit, dsInsert];
  1493. { Auxiliary functions }
  1494. Procedure DatabaseError (Const Msg : String);
  1495. Procedure DatabaseError (Const Msg : String; Comp : TComponent);
  1496. Procedure DatabaseErrorFmt (Const Fmt : String; Args : Array Of Const);
  1497. Procedure DatabaseErrorFmt (Const Fmt : String; Args : Array Of const;
  1498. Comp : TComponent);
  1499. implementation
  1500. uses dbconst;
  1501. { ---------------------------------------------------------------------
  1502. Auxiliary functions
  1503. ---------------------------------------------------------------------}
  1504. Procedure DatabaseError (Const Msg : String);
  1505. begin
  1506. Raise EDataBaseError.Create(Msg);
  1507. end;
  1508. Procedure DatabaseError (Const Msg : String; Comp : TComponent);
  1509. begin
  1510. Raise EDatabaseError.CreateFmt('%s : %s',[Comp.Name,Msg]);
  1511. end;
  1512. Procedure DatabaseErrorFmt (Const Fmt : String; Args : Array Of Const);
  1513. begin
  1514. Raise EDatabaseError.CreateFmt(Fmt,Args);
  1515. end;
  1516. Procedure DatabaseErrorFmt (Const Fmt : String; Args : Array Of const;
  1517. Comp : TComponent);
  1518. begin
  1519. Raise EDatabaseError.CreateFmt(Format('%s : %s',[Comp.Name,Fmt]),Args);
  1520. end;
  1521. { TIndexDef }
  1522. constructor TIndexDef.Create(Owner: TIndexDefs; const AName, TheFields: string;
  1523. TheOptions: TIndexOptions);
  1524. begin
  1525. inherited create(Owner);
  1526. FName := aname;
  1527. FFields := TheFields;
  1528. FOptions := TheOptions;
  1529. end;
  1530. destructor TIndexDef.Destroy;
  1531. begin
  1532. //!! To be implemented
  1533. end;
  1534. { TIndexDefs }
  1535. Function TIndexDefs.GetItem (Index : integer) : TIndexDef;
  1536. begin
  1537. Result:=(Inherited GetItem(Index)) as TIndexDef;
  1538. end;
  1539. Procedure TIndexDefs.SetItem(Index: Integer; Value: TIndexDef);
  1540. begin
  1541. Inherited SetItem(Index,Value);
  1542. end;
  1543. constructor TIndexDefs.Create(DataSet: TDataSet);
  1544. begin
  1545. FDataset := Dataset;
  1546. inherited create(Dataset, TIndexDef);
  1547. end;
  1548. destructor TIndexDefs.Destroy;
  1549. begin
  1550. //!! To be implemented
  1551. end;
  1552. Function TIndexDefs.AddIndexDef: TIndexDef;
  1553. begin
  1554. // Result := inherited add as TIndexDef;
  1555. Result:=TIndexDef.Create(Self,'','',[]);
  1556. end;
  1557. procedure TIndexDefs.Add(const Name, Fields: string; Options: TIndexOptions);
  1558. begin
  1559. TIndexDef.Create(Self,Name,Fields,Options);
  1560. end;
  1561. procedure TIndexDefs.Assign(IndexDefs: TIndexDefs);
  1562. begin
  1563. //!! To be implemented
  1564. end;
  1565. {procedure TIndexDefs.Clear;
  1566. begin
  1567. //!! To be implemented
  1568. end;}
  1569. function TIndexDefs.FindIndexForFields(const Fields: string): TIndexDef;
  1570. begin
  1571. //!! To be implemented
  1572. end;
  1573. function TIndexDefs.GetIndexForFields(const Fields: string;
  1574. CaseInsensitive: Boolean): TIndexDef;
  1575. begin
  1576. //!! To be implemented
  1577. end;
  1578. {function TIndexDefs.IndexOf(const Name: string): Longint;
  1579. begin
  1580. //!! To be implemented
  1581. end;}
  1582. procedure TIndexDefs.Update;
  1583. begin
  1584. if assigned(Fdataset) then
  1585. Fdataset.UpdateIndexDefs;
  1586. end;
  1587. { TCheckConstraint }
  1588. procedure TCheckConstraint.Assign(Source: TPersistent);
  1589. begin
  1590. //!! To be implemented
  1591. end;
  1592. { TCheckConstraints }
  1593. Function TCheckConstraints.GetItem(Index : Longint) : TCheckConstraint;
  1594. begin
  1595. //!! To be implemented
  1596. end;
  1597. Procedure TCheckConstraints.SetItem(index : Longint; Value : TCheckConstraint);
  1598. begin
  1599. //!! To be implemented
  1600. end;
  1601. function TCheckConstraints.GetOwner: TPersistent;
  1602. begin
  1603. //!! To be implemented
  1604. end;
  1605. constructor TCheckConstraints.Create(AOwner: TPersistent);
  1606. begin
  1607. //!! To be implemented
  1608. end;
  1609. function TCheckConstraints.Add: TCheckConstraint;
  1610. begin
  1611. //!! To be implemented
  1612. end;
  1613. {$i dataset.inc}
  1614. {$i fields.inc}
  1615. {$i datasource.inc}
  1616. {$i database.inc}
  1617. {$i BufDataset.inc}
  1618. {$i dsparams.inc}
  1619. end.
  1620. {
  1621. $Log$
  1622. Revision 1.35 2005-02-03 19:10:39 florian
  1623. + adapted for use fo tcollection.owner
  1624. Revision 1.34 2005/01/12 10:28:44 michael
  1625. * Patch from Joost Van der Sluis:
  1626. - implemented TUpdateMode, TProviderFlags
  1627. - implemented TIndexDef, TIndexDefs
  1628. Revision 1.33 2004/12/29 14:30:53 michael
  1629. + Patch from Joost van der Sluis
  1630. - implemented CachedUpdates (only modifications, no inserts/deletes)
  1631. - implemented GetAsVariant/SetAsVariant for all fields
  1632. - implemented TField.OldValue as a variant
  1633. - changed TField.Value to a variant
  1634. Revision 1.32 2004/12/13 20:19:49 michael
  1635. + Initial implementation of params
  1636. Revision 1.31 2004/12/13 19:20:12 michael
  1637. * Patch from Joost van der Sluis
  1638. - moved IsCursorOpen from TSQLQuery to tbufdataset
  1639. - moved SetFieldData from TSQLQuery to TBufDataset
  1640. - very first start for support of cached updates
  1641. Revision 1.30 2004/12/05 00:05:38 michael
  1642. patch to enable RecNo and DisplayFormat
  1643. Revision 1.29 2004/12/04 22:44:24 michael
  1644. * Patch from Joost van der Sluis
  1645. - implemented TBCDFields
  1646. - adapted for the changes in TBuffDataset
  1647. Revision 1.28 2004/11/05 08:32:02 michael
  1648. TBufDataset.inc:
  1649. - replaced Freemem by Reallocmem, Free by FreeAndNil
  1650. Database.inc:
  1651. - Moved Active property from TSQLTransaction to TDBTransaction
  1652. - Gives an error if the database of an active transaction is changed
  1653. Dataset.inc
  1654. - Don't distribute events if FDisableControlsCount > 0
  1655. - Replaced FActive by FState<>dsInactive
  1656. - Set EOF after append
  1657. db.pp:
  1658. - Removed duplicate definition of TAlignment
  1659. - Moved Active property from TSQLTransaction to TDBTransaction
  1660. - Replaced FActive by FState<>dsInactive
  1661. - Gives an error if the database of an active transaction is changed
  1662. sqldb:
  1663. - Moved Active property from TSQLTransaction to TDBTransaction
  1664. - replaced Freemem by Reallocmem, Free by FreeAndNil
  1665. IBConnection:
  1666. - Moved FSQLDAAllocated to the cursor
  1667. PQConnection:
  1668. - Don't try to free the statement if a fatal error occured
  1669. Revision 1.27 2004/10/27 07:23:13 michael
  1670. + Patch from Joost Van der Sluis to fix transactions
  1671. Revision 1.26 2004/10/10 14:45:51 michael
  1672. + Use of dbconst for resource strings
  1673. Revision 1.25 2004/10/10 14:25:21 michael
  1674. + Small fix for close so it does not check browsemode
  1675. Revision 1.24 2004/09/26 16:55:24 michael
  1676. * big patch from Joost van der Sluis
  1677. bufdataset.inc:
  1678. fix getrecord (prior)
  1679. getcanmodify default false
  1680. database.inc / db.inc:
  1681. Added transactions
  1682. dataset.inc:
  1683. raise error if trying to insert into an readonly dataset
  1684. db.inc:
  1685. remove published properties from bufdataset
  1686. changed ancestor of tbufdataset to tdbdataset
  1687. Revision 1.23 2004/08/31 09:51:27 michael
  1688. + Initial TBufDataset by Joost van der Sluis
  1689. Revision 1.22 2004/08/23 07:30:19 michael
  1690. + Fixes from joost van der sluis: tfieldsdefs.tdatafield and size, cancel of only record and dataset.fieldvalyes
  1691. Revision 1.21 2004/08/14 12:46:35 michael
  1692. + Patch from Joost van der Sluis to implement Modified and UpdateRecord event
  1693. Revision 1.20 2004/08/13 07:06:02 michael
  1694. + Rework of buffer management by Joost Van der Sluis
  1695. Revision 1.19 2004/07/25 11:32:40 michael
  1696. * Patches from Joost van der Sluis
  1697. interbase.pp:
  1698. * Removed unused Fprepared
  1699. * Changed the error message 'database connect string not filled
  1700. in' to 'database connect string (databasename) not filled in'
  1701. * Preparestatement and execute now checks if transaction is
  1702. assigned (in stead of crashing if it isn't) and if the
  1703. transaction isn't started, it calls starttransaction.
  1704. dataset.inc:
  1705. * In DoInternalOpen the buffers are now initialised before the
  1706. dataset is set into browse-state
  1707. database.inc and db.pp:
  1708. * If the dataset is created from a stream, the database is opened
  1709. after the dataset is read completely
  1710. Revision 1.18 2004/07/19 20:27:28 michael
  1711. + Fixes from Jesus Reyes to implement DisplayWith, DisplayLabel, Visibility
  1712. Revision 1.17 2004/07/18 13:16:50 michael
  1713. + Changed extended to double for better Delphi compatibility
  1714. Revision 1.16 2004/05/02 21:23:18 peter
  1715. * use ptrint
  1716. Revision 1.15 2004/03/25 20:43:39 michael
  1717. Some compatibility additions
  1718. Revision 1.14 2004/03/19 23:19:51 michael
  1719. + Corrected the Fields property.
  1720. Revision 1.13 2004/02/25 16:29:26 michael
  1721. + Added AsInteger to TField. Maps to AsLongint for now
  1722. Revision 1.12 2003/11/09 21:23:10 michael
  1723. + Patch from Micha Nelissen, fixing some Delphi compatibility issues
  1724. Revision 1.11 2003/10/06 17:04:27 florian
  1725. * small step towards calculated fields
  1726. Revision 1.10 2003/08/16 16:42:21 michael
  1727. + Fixes in TDBDataset etc. Changed MySQLDb to use database as well
  1728. Revision 1.9 2003/05/15 15:15:15 michael
  1729. + Database class in TDBDataset is public, not published
  1730. Revision 1.8 2003/05/08 21:52:41 michael
  1731. + Patch from Jesus Reyes
  1732. Revision 1.7 2003/02/20 19:30:28 michael
  1733. + Fixes from Jesus Reyes
  1734. Revision 1.6 2002/09/07 15:15:23 peter
  1735. * old logs removed and tabs fixed
  1736. }