mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-06 18:24:26 +08:00
Slightly enhance open SQL file mechanism:
- Open the file in "read and leave" mode, don't lock it for write operations. This fixes opening a file which is opened and write locked in another application - Handle exceptions for ReadTextfile in QueryLoad which was malfunctioning yet, lead to an AV. - Enhance inline documentation
This commit is contained in:
@ -3567,7 +3567,7 @@ var
|
|||||||
msgtext : String;
|
msgtext : String;
|
||||||
begin
|
begin
|
||||||
// Ask for action when loading a big file
|
// Ask for action when loading a big file
|
||||||
if _GetFileSize( filename ) > LOAD_SIZE then
|
if FileExists(filename) and (_GetFileSize( filename ) > LOAD_SIZE) then
|
||||||
begin
|
begin
|
||||||
msgtext := 'The file you are about to load is bigger than '+FormatByteNumber(LOAD_SIZE, 0)+'.' + CRLF + CRLF +
|
msgtext := 'The file you are about to load is bigger than '+FormatByteNumber(LOAD_SIZE, 0)+'.' + CRLF + CRLF +
|
||||||
'Do you want to just run the file to avoid loading it completely into the query-editor ( = memory ) ?' + CRLF + CRLF +
|
'Do you want to just run the file to avoid loading it completely into the query-editor ( = memory ) ?' + CRLF + CRLF +
|
||||||
@ -3576,21 +3576,20 @@ begin
|
|||||||
' [No] to load the file into the query editor' + CRLF +
|
' [No] to load the file into the query editor' + CRLF +
|
||||||
' [Cancel] to cancel file opening.';
|
' [Cancel] to cancel file opening.';
|
||||||
case MessageDlg( msgtext, mtWarning, [mbYes, mbNo, mbCancel], 0 ) of
|
case MessageDlg( msgtext, mtWarning, [mbYes, mbNo, mbCancel], 0 ) of
|
||||||
mrYes: // Run the file, don't load it into the editor
|
// Run the file, don't load it into the editor
|
||||||
|
mrYes:
|
||||||
begin
|
begin
|
||||||
RunSQLFileWindow( Self, filename );
|
RunSQLFileWindow( Self, filename );
|
||||||
// Add filename to history menu
|
// Add filename to history menu
|
||||||
if Pos( DIRNAME_SNIPPETS, filename ) = 0 then
|
if Pos( DIRNAME_SNIPPETS, filename ) = 0 then
|
||||||
Mainform.AddOrRemoveFromQueryLoadHistory( filename, true );
|
Mainform.AddOrRemoveFromQueryLoadHistory( filename, true );
|
||||||
// Don't load into editor
|
// Don't load into editor
|
||||||
abort;
|
Abort;
|
||||||
end;
|
end;
|
||||||
|
// Do nothing here, go ahead and load the file normally into the editor
|
||||||
mrNo:; // Do nothing, just load the file normally into the editor
|
mrNo:;
|
||||||
|
// Cancel opening file
|
||||||
mrCancel: // Cancel opening file
|
mrCancel: Abort;
|
||||||
abort;
|
|
||||||
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -3601,33 +3600,21 @@ begin
|
|||||||
Screen.Cursor := crHourGlass;
|
Screen.Cursor := crHourGlass;
|
||||||
try
|
try
|
||||||
filecontent := ReadTextfile(filename);
|
filecontent := ReadTextfile(filename);
|
||||||
except
|
if Pos( DIRNAME_SNIPPETS, filename ) = 0 then
|
||||||
on E: Exception do
|
Mainform.AddOrRemoveFromQueryLoadHistory( filename, true );
|
||||||
begin
|
Mainform.FillPopupQueryLoad;
|
||||||
MessageDLG( 'Error while reading file ' + filename + ':' + CRLF + CRLF + E.Message, mtError, [mbOK], 0);
|
PagecontrolMain.ActivePage := tabQuery;
|
||||||
Mainform.AddOrRemoveFromQueryLoadHistory( filename, false );
|
SynCompletionProposal1.Editor.UndoList.AddGroupBreak;
|
||||||
Mainform.FillPopupQueryLoad;
|
SynMemoQuery.BeginUpdate;
|
||||||
Screen.Cursor := crDefault;
|
if ReplaceContent then
|
||||||
exit;
|
SynMemoQuery.SelectAll;
|
||||||
end;
|
SynMemoQuery.SelText := filecontent;
|
||||||
|
SynMemoQuery.SelStart := SynMemoQuery.SelEnd;
|
||||||
|
SynMemoQuery.EndUpdate;
|
||||||
|
except on E:Exception do
|
||||||
|
// File does not exist, is locked or broken
|
||||||
|
MessageDlg(E.message, mtError, [mbOK], 0);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
PagecontrolMain.ActivePage := tabQuery;
|
|
||||||
SynCompletionProposal1.Editor.UndoList.AddGroupBreak;
|
|
||||||
SynMemoQuery.BeginUpdate;
|
|
||||||
if ReplaceContent then
|
|
||||||
begin
|
|
||||||
SynMemoQuery.SelectAll;
|
|
||||||
end;
|
|
||||||
SynMemoQuery.SelText := filecontent;
|
|
||||||
SynMemoQuery.SelStart := SynMemoQuery.SelEnd;
|
|
||||||
SynMemoQuery.EndUpdate;
|
|
||||||
ValidateQueryControls;
|
|
||||||
|
|
||||||
if Pos( DIRNAME_SNIPPETS, filename ) = 0 then
|
|
||||||
Mainform.AddOrRemoveFromQueryLoadHistory( filename, true );
|
|
||||||
Mainform.FillPopupQueryLoad;
|
|
||||||
|
|
||||||
Screen.Cursor := crDefault;
|
Screen.Cursor := crDefault;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -2339,7 +2339,7 @@ end;
|
|||||||
}
|
}
|
||||||
procedure OpenTextFile(const Filename: String; out Stream: TFileStream; out FileCharset: TFileCharset);
|
procedure OpenTextFile(const Filename: String; out Stream: TFileStream; out FileCharset: TFileCharset);
|
||||||
begin
|
begin
|
||||||
Stream := TFileStream.Create(Filename, fmOpenRead or fmShareDenyWrite);
|
Stream := TFileStream.Create(Filename, fmOpenRead or fmShareDenyNone);
|
||||||
Stream.Position := 0;
|
Stream.Position := 0;
|
||||||
FileCharset := GetFileCharset(Stream);
|
FileCharset := GetFileCharset(Stream);
|
||||||
end;
|
end;
|
||||||
@ -2545,12 +2545,9 @@ var
|
|||||||
Stream: TFileStream;
|
Stream: TFileStream;
|
||||||
FileCharset: TFileCharset;
|
FileCharset: TFileCharset;
|
||||||
begin
|
begin
|
||||||
try
|
OpenTextfile(Filename, Stream, FileCharset);
|
||||||
OpenTextfile(Filename, Stream, FileCharset);
|
Result := ReadTextfileChunk(Stream, FileCharset);
|
||||||
Result := ReadTextfileChunk(Stream, FileCharset);
|
Stream.Free;
|
||||||
finally
|
|
||||||
Stream.Free;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user