Browse Source

* Added helper routines to be used with QueryUpdates: GetSQLValue and ClearUpdates

git-svn-id: trunk@13272 -
blikblum 16 years ago
parent
commit
e4d43bea8a
1 changed files with 20 additions and 0 deletions
  1. 20 0
      packages/fcl-db/src/sqlite/customsqliteds.pas

+ 20 - 0
packages/fcl-db/src/sqlite/customsqliteds.pas

@@ -206,6 +206,7 @@ type
     function Lookup(const KeyFields: String; const KeyValues: Variant; const ResultFields: String): Variant; override;
     function Lookup(const KeyFields: String; const KeyValues: Variant; const ResultFields: String): Variant; override;
     // Additional procedures
     // Additional procedures
     function ApplyUpdates: Boolean;
     function ApplyUpdates: Boolean;
+    procedure ClearUpdates(RecordStates: TRecordStateSet = [rsAdded, rsDeleted, rsUpdated]);
     function CreateTable: Boolean;
     function CreateTable: Boolean;
     function CreateTable(const ATableName: String): Boolean;
     function CreateTable(const ATableName: String): Boolean;
     procedure ExecCallback(const ASql: String; UserData: Pointer = nil);
     procedure ExecCallback(const ASql: String; UserData: Pointer = nil);
@@ -213,6 +214,7 @@ type
     procedure ExecSQL(const ASql: String);
     procedure ExecSQL(const ASql: String);
     procedure ExecSQLList;
     procedure ExecSQLList;
     procedure ExecuteDirect(const ASql: String); virtual; abstract;
     procedure ExecuteDirect(const ASql: String); virtual; abstract;
+    function GetSQLValue(Values: PPChar; FieldIndex: Integer): String;
     procedure QueryUpdates(RecordStates: TRecordStateSet; Callback: TQueryUpdatesCallback; UserData: Pointer = nil);
     procedure QueryUpdates(RecordStates: TRecordStateSet; Callback: TQueryUpdatesCallback; UserData: Pointer = nil);
     function QuickQuery(const ASql: String):String;overload;
     function QuickQuery(const ASql: String):String;overload;
     function QuickQuery(const ASql: String; const AStrList: TStrings): String; overload;
     function QuickQuery(const ASql: String; const AStrList: TStrings): String; overload;
@@ -1457,6 +1459,14 @@ begin
     DatabaseError(ReturnString, Self);
     DatabaseError(ReturnString, Self);
 end;
 end;
 
 
+function TCustomSqliteDataset.GetSQLValue(Values: PPChar; FieldIndex: Integer
+  ): String;
+begin
+  if (State = dsInactive) or (FieldIndex < 0) or (FieldIndex >= FieldDefs.Count) then
+    DatabaseError('Error retrieving SQL value: dataset inactive or field out of range', Self);
+  Result := FGetSqlStr[FieldIndex](Values[FieldIndex]);
+end;
+
 procedure TCustomSqliteDataset.ExecSQL;
 procedure TCustomSqliteDataset.ExecSQL;
 begin
 begin
   ExecSQL(FSQL);
   ExecSQL(FSQL);
@@ -1603,6 +1613,16 @@ begin
   {$endif}   
   {$endif}   
 end;
 end;
 
 
+procedure TCustomSqliteDataset.ClearUpdates(RecordStates: TRecordStateSet);
+begin
+  if rsUpdated in RecordStates then
+    FUpdatedItems.Clear;
+  if rsDeleted in RecordStates then
+    FDeletedItems.Clear;
+  if rsAdded in RecordStates then
+    FAddedItems.Clear;
+end;
+
 function TCustomSqliteDataset.CreateTable: Boolean;
 function TCustomSqliteDataset.CreateTable: Boolean;
 begin
 begin
   Result := CreateTable(FTableName);
   Result := CreateTable(FTableName);