📄 myldblocalengine.pas
字号:
DoInternalDelete;
finally
if (FTableData is TMYLDBDiskTableData) then
begin
TMYLDBDiskTableData(FTableData).UnlockRecord(Session.SessionID, CurrentRecordID);
if (not Session.InTransaction) then
TMYLDBDiskTableData(FTableData).UnlockTable(Session.SessionID, ltRW);
end;
end;
if (not TableLockSucceeded) then
ErrorCode := MYLDB_ERR_TABLE_LOCKED
else
if (not RecordLockSucceeded) then
begin
ErrorCode := MYLDB_ERR_RECORD_LOCKED;
TMYLDBDiskTableData(FTableData).UnlockTable(Session.SessionID, LockType);
end;
end
else
{$ENDIF}
DoInternalDelete;
finally
UnlockTableData;
end;
end; // InternalDelete
//------------------------------------------------------------------------------
// activate filters
//------------------------------------------------------------------------------
procedure TMYLDBLocalCursor.ApplyDistinct(FieldNamesList, AscDescList, CaseSensitivityList: TStringList);
var IsCreated: Boolean;
begin
LockTableData;
try
FIndexName := FindOrCreateIndex(FieldNamesList, AscDescList, CaseSensitivityList, IsCreated);
SetIndexName(FIndexName);
DistinctFieldCount := FieldNamesList.Count;
DisableRecordBitmap;
finally
UnlockTableData;
end;
end;
//------------------------------------------------------------------------------
// activate filters
//------------------------------------------------------------------------------
procedure TMYLDBLocalCursor.ActivateFilters(
FilterText: String;
CaseInsensitive: Boolean;
PartialKey: Boolean
);
begin
if (FilterExpression <> nil) then
TMYLDBExpression(FilterExpression).Free;
FilterExpression := TMYLDBExpression.Create;
TMYLDBExpression(FilterExpression).ParseForFilter(Self,FilterText,CaseInsensitive,PartialKey);
DisableRecordBitmap;
end; // ActivateFilters
//------------------------------------------------------------------------------
// deactivate filters
//------------------------------------------------------------------------------
procedure TMYLDBLocalCursor.DeactivateFilters;
begin
if (FilterExpression <> nil) then
TMYLDBExpression(FilterExpression).Free;
FilterExpression := nil;
DisableRecordBitmap;
end; // DeactivateFilters
//------------------------------------------------------------------------------
// locate
//------------------------------------------------------------------------------
function TMYLDBLocalCursor.Locate(
const KeyFields: String;
const KeyValues: Variant;
CaseInsensitive: Boolean;
PartialKey: Boolean
): Boolean;
var SearchExpression: TMYLDBExpression;
begin
SearchExpression := TMYLDBExpression.Create;
try
SearchExpression.ParseForLocate(Self,KeyFields,KeyValues,CaseInsensitive,PartialKey);
Result := FTableData.Locate(Self,SearchExpression);
finally
SearchExpression.Free;
end;
end; // Locate
//------------------------------------------------------------------------------
// find key
//------------------------------------------------------------------------------
function TMYLDBLocalCursor.FindKey(SearchCondition: TMYLDBSearchCondition): Boolean;
begin
Result := FTableData.FindKey(Self,SearchCondition);
end; // FindKey
//------------------------------------------------------------------------------
// used by SQL: "where field > all (select ...)"
//------------------------------------------------------------------------------
function TMYLDBLocalCursor.IsAnyRecordMatchCondition(const FieldName: string;
const Operator: TMYLDBDataOperator; const Value: TMYLDBVariant): Boolean;
var SearchExpression: TMYLDBExpression;
begin
SearchExpression := TMYLDBExpression.Create;
try
SearchExpression.ParseForIsAnyRecordMatchCondition(Self, FieldName, Operator, Value);
Result := FTableData.Locate(Self,SearchExpression);
finally
SearchExpression.Free;
end;
end;// IsAnyRecordMatchCondition
//------------------------------------------------------------------------------
// create blob stream
//------------------------------------------------------------------------------
function TMYLDBLocalCursor.InternalCreateBlobStream(
ToInsert: Boolean;
ToEdit: Boolean;
FieldNo: Integer;
OpenMode: TMYLDBBLOBOpenMode;
CanDoGetRecordBuffer: Boolean
):TMYLDBStream;
var
grResult: TMYLDBGetRecordResult;
{$IFDEF FILE_SERVER_VERSION}
Pos: Pointer;
{$ENDIF}
function DoInternalCreateBlobStream: TMYLDBStream;
var
FieldNumber: Integer;
i: Integer;
LocalBLOBStream: TMYLDBLocalBLOBStream;
begin
if (FieldNo >= FVisibleFieldDefs.Count) then
raise EMYLDBException.Create(10110,ErrorLInvalidFieldNumber,
[FieldNo,FVisibleFieldDefs.Count]);
if (FBLOBStreams = nil) then
raise EMYLDBException.Create(10113,ErrorLNilPointer);
FieldNumber := FVisibleFieldDefs.Items[FieldNo].FieldNoReference;
// find existing blob stream
if ((OpenMode = bomReadWrite) or (OpenMode = bomWrite)) then
for i := 0 to FBLOBStreams.Count -1 do
begin
LocalBLOBStream := TMYLDBLocalBLOBStream(FBLOBStreams.Items[i]);
if (LocalBLOBStream = nil) then
raise EMYLDBException.Create(10114,ErrorLNilPointer);
if (LocalBLOBStream.FFieldNo = FieldNumber) then
if ((LocalBLOBStream.OpenMode = bomReadWrite) or
(LocalBLOBStream.OpenMode = bomWrite)) then
raise EMYLDBException.Create(10115,ErrorLBLOBFieldAlreadyOpened,[FieldNumber,
FFieldDefs.Items[FieldNumber].Name]);
end;
Result := FTableData.InternalCreateBlobStream(Self,ToInsert,FieldNumber,OpenMode);
if (Result <> nil) then
FBLOBStreams.Add(Result);
end;
begin
LockTableData;
Result := nil;
try
{$IFDEF FILE_SERVER_VERSION}
if (FDatabaseData.MultiUser and
(FTableData is TMYLDBDiskTableData)) then
begin
if (LockTable(ltS, CreateBlobStreamTableLockRetries, CreateBlobStreamTableLockDelay)) then
try
if ((not ToInsert) and (not ToEdit) and (CanDoGetRecordBuffer) and (FBlobStreams.Count = 0)) then
begin
Pos := SavePosition;
try
FirstPosition := False;
LastPosition := False;
grResult := GetRecordBuffer(grmCurrent);
finally
RestorePosition(Pos);
FreePosition(Pos);
end;
end
else
grResult := grrOK;
if (grResult = grrOK) then
Result := DoInternalCreateBlobStream
else
Result := nil;
finally
UnlockTable(ltS);
end
else
end
else
{$ENDIF}
Result := DoInternalCreateBlobStream;
finally
UnlockTableData;
end;
end; // InternalCreateBlobStream
//------------------------------------------------------------------------------
// close blob
//------------------------------------------------------------------------------
procedure TMYLDBLocalCursor.InternalCloseBLOB(FieldNo: Integer);
var FieldNumber: Integer;
i: Integer;
LocalBLOBStream: TMYLDBLocalBLOBStream;
begin
LockTableData;
try
if (FieldNo >= FVisibleFieldDefs.Count) then
raise EMYLDBException.Create(10118,ErrorLInvalidFieldNumber,
[FieldNo,FVisibleFieldDefs.Count]);
if (FBLOBStreams = nil) then
raise EMYLDBException.Create(10119,ErrorLNilPointer);
FieldNumber := FVisibleFieldDefs.Items[FieldNo].FieldNoReference;
i := 0;
while (i < FBLOBStreams.Count) do
begin
LocalBLOBStream := TMYLDBLocalBLOBStream(FBLOBStreams.Items[i]);
if (LocalBLOBStream = nil) then
raise EMYLDBException.Create(10120,ErrorLNilPointer);
if (LocalBLOBStream.FieldNo = FieldNumber) then
begin
if ((LocalBLOBStream.OpenMode = bomWrite) or
(LocalBLOBStream.OpenMode = bomReadWrite)) then
FTableData.WriteBLOBFieldToRecordBuffer(Self,FieldNumber,LocalBLOBStream);
if (not LocalBLOBStream.Modified) then
if (FTableData is TMYLDBDiskTableData) then
FTableData.ClearBLOBFieldInRecordBuffer(CurrentRecordBuffer, FieldNumber);
if (LocalBLOBStream.UserBLOBStream <> nil) then
LocalBLOBStream.UserBLOBStream.Free;
LocalBLOBStream.Free;
FBLOBStreams.Delete(i);
Dec(i);
end;
Inc(i);
end;
finally
UnlockTableData;
end;
end; // InternalCloseBLOB
//------------------------------------------------------------------------------
// clear blob streams
//------------------------------------------------------------------------------
procedure TMYLDBLocalCursor.ClearBLOBStreams(WriteOnly: Boolean = False);
var i: Integer;
LocalBLOBStream: TMYLDBLocalBLOBStream;
begin
i := 0;
if (FBLOBStreams <> nil) then
while (i < FBLOBStreams.Count) and (FBLOBStreams.Count > 0) do
begin
LocalBLOBStream := TMYLDBLocalBLOBStream(FBLOBStreams.Items[i]);
if (LocalBLOBStream = nil) then
raise EMYLDBException.Create(10121,ErrorLNilPointer);
if ((Not WriteOnly) or
((WriteOnly) and
((LocalBLOBStream.OpenMode = bomWrite) or
(LocalBLOBStream.OpenMode = bomReadWrite)))) then
begin
if (LocalBLOBStream.UserBLOBStream <> nil) then
LocalBLOBStream.UserBLOBStream.Free;
// LocalBLOBStream.Free;
// FBLOBStreams.Delete(i);
Dec(i);
end;
Inc(i);
end;
end; // ClearBLOBStreams
//------------------------------------------------------------------------------
//LastAutoincValue
//------------------------------------------------------------------------------
function TMYLDBLocalCursor.LastAutoincValue(FieldNo: Integer): Int64;
begin
Result := FTableData.LastAutoincValue(FieldNo, FSession);
end;//LastAutoincValue
//------------------------------------------------------------------------------
// BeginBatchUpdate
//------------------------------------------------------------------------------
procedure TMYLDBLocalCursor.BeginBatchUpdate;
begin
if (not Session.InTransaction) then
begin
InBatchUpdate := True;
end;
end;// BeginBatchUpdate
//------------------------------------------------------------------------------
// EndBatchUpdate
//------------------------------------------------------------------------------
procedure TMYLDBLocalCursor.EndBatchUpdate;
begin
if ((not Session.InTransaction) and (InBatchUpdate)) then
begin
if (FTableData is TMYLDBDiskTableData) then
FTableData.ApplyChanges(Session.SessionID, Session.InTransaction);
InBatchUpdate := False;
end;
end;// EndBatchUpdate
//------------------------------------------------------------------------------
// CancelBatchUpdate
//------------------------------------------------------------------------------
procedure TMYLDBLocalCursor.CancelBatchUpdate;
begin
if ((not Session.InTransaction) and (InBatchUpdate)) then
begin
if (FTableData is TMYLDBDiskTableData) then
FTableData.CancelChanges(Session.SessionID, Session.InTransaction);
InBatchUpdate := False;
end;
end;// CancelBatchUpdate
//------------------------------------------------------------------------------
// CheckConstraints
//------------------------------------------------------------------------------
function TMYLDBLocalCursor.CheckConstraints(ToInsert: Boolean): Boolean;
begin
Result := FTableData.ConstraintManager.CheckConstraints(
Session.SessionID, CurrentRecordBuffer, EditRecordBuffer,
ToInsert, CurrentRecordID, False);
end;// CheckConstraints
////////////////////////////////////////////////////////////////////////////////
//
// TMYLDBLocalSession
//
////////////////////////////////////////////////////////////////////////////////
//------------------------------------------------------------------------------
// GetPassword
//------------------------------------------------------------------------------
function TMYLDBLocalSession.GetPassword: PMYLDBPassword;
begin
Result := @FPassword;
end;//GetPassword
//------------------------------------------------------------------------------
// does DBData correspond to this local sesion?
//------------------------------------------------------------------------------
function TMYLDBLocalSession.IsAppropriateDatabaseData(DBData: TMY
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -