2
0
Эх сурвалжийг харах

Consolidate code for getting select query in querywindow

Reinier Olislagers 11 жил өмнө
parent
commit
d4f6424617
4 өөрчлөгдсөн 29 нэмэгдсэн , 55 устгасан
  1. 1 1
      querywindow.lfm
  2. 1 3
      querywindow.lrs
  3. 25 49
      querywindow.pas
  4. 2 2
      tablemanage.pas

+ 1 - 1
querywindow.lfm

@@ -2676,7 +2676,7 @@ object fmQueryWindow: TfmQueryWindow
       OnClick = lmCopyAllClick
     end
     object lmExportAsComma: TMenuItem
-      Caption = 'Export Grid as Comma Delemited'
+      Caption = 'Export Grid as Comma Delimited'
       OnClick = lmExportAsCommaClick
     end
     object lmExportAsHTML: TMenuItem

+ 1 - 3
querywindow.lrs

@@ -1,5 +1,3 @@
-{ This is an automatically generated lazarus resource file }
-
 LazarusResources.Add('TfmQueryWindow','FORMDATA',[
   'TPF0'#14'TfmQueryWindow'#13'fmQueryWindow'#4'Left'#3#21#2#6'Height'#3'Y'#2#3
   +'Top'#3#204#0#5'Width'#3#208#2#13'ActiveControl'#7#6'Panel1'#7'Caption'#6#13
@@ -2504,7 +2502,7 @@ LazarusResources.Add('TfmQueryWindow','FORMDATA',[
   +'ion'#6#10'Copy field'#7'OnClick'#7#15'lmCopyCellClick'#0#0#9'TMenuItem'#9'l'
   +'mCopyAll'#7'Caption'#6#15'Copy all result'#7'OnClick'#7#14'lmCopyAllClick'#0
   +#0#9'TMenuItem'#15'lmExportAsComma'#7'Caption'#6#30'Export Grid as Comma Del'
-  +'emited'#7'OnClick'#7#20'lmExportAsCommaClick'#0#0#9'TMenuItem'#14'lmExportA'
+  +'imited'#7'OnClick'#7#20'lmExportAsCommaClick'#0#0#9'TMenuItem'#14'lmExportA'
   +'sHTML'#7'Caption'#6#19'Export Grid as HTML'#7'OnClick'#7#19'lmExportAsHTMLC'
   +'lick'#0#0#0#14'TSynCompletion'#14'SynCompletion1'#8'Position'#2#0#13'LinesI'
   +'nWindow'#2#6#13'SelectedColor'#7#11'clHighlight'#13'CaseSensitive'#8#5'Widt'

+ 25 - 49
querywindow.pas

@@ -222,7 +222,6 @@ type
     function ExecuteScript(Script: string): Boolean;
     // Create a new Apply button in the specified panel
     procedure NewApplyButton(var Pan: TPanel; var ATab: TTabSheet);
-    function FindSqlQuery: TSqlQuery;
     // Returns whether query is DDL or DML
     function GetSQLType(Query: string; var Command: string): string;
     // Tries to split up text into separate queries
@@ -1575,31 +1574,6 @@ begin
 end;
 
 
-{ FindSQLQuery: Return current TSQLQuery component from current query window }
-
-function TfmQueryWindow.FindSqlQuery: TSqlQuery;
-var
-  i: Integer;
-begin
-  Result:= nil;
-  if pgOutputPageCtl.PageCount > 0 then
-  begin
-    with pgOutputPageCtl.ActivePage do
-    begin
-      for i:= 0 to ControlCount - 1 do
-      begin
-        //todo: directly go to sqlquery?
-        if Controls[i] is TDBGrid then
-        begin
-          Result:= TSqlQuery((Controls[i] as TDBGrid).DataSource.DataSet);
-          Break;
-        end;
-      end;
-    end;
-  end;
-end;
-
-
 { GetSQLType: get SQL type of current SQL text }
 
 function TfmQueryWindow.GetSQLType(Query: string; var Command: string): string;
@@ -1719,15 +1693,15 @@ var
   SqlQuery: TSQLQuery;
 //    indexoption : TIndexOptions;
 begin
-  SqlQuery:= FindSqlQuery;
-  if  SqlQuery <> Nil then
-  if SqlQuery.IndexFieldNames = Column.Field.FieldName then
+  SQLQuery:= nil;
+  SqlQuery:= GetCurrentSelectQuery;
+  if (assigned(SqlQuery)) and
+    (SqlQuery.IndexFieldNames = Column.Field.FieldName) then
     SqlQuery.IndexFieldNames := Column.Field.FieldName //+ 'DESC'
-  //   indexoption :=[ixDescending];
-  //   SqlQuery.AddIndex('',Column.Field.FieldName,indexoption,'');
+    //   indexoption :=[ixDescending];
+    //   SqlQuery.AddIndex('',Column.Field.FieldName,indexoption,'');
   else
     SqlQuery.IndexFieldNames := Column.Field.FieldName
-
 end;
 
 
@@ -1847,44 +1821,45 @@ var
   SqlQuery: TSQLQuery;
 begin
   SaveDialog1.DefaultExt:= '.txt';
-  SqlQuery:= FindSqlQuery;
-  if SqlQuery = nil then
+  SqlQuery:= nil;
+  SqlQuery:= GetCurrentSelectQuery;
+  if not(assigned(SqlQuery)) then
   begin
     ShowMessage('There is no recordset in result');
     Exit;
   end;
-  if (not SQLQuery.Active) or (SQLQuery.RecordCount = 0) then
+  if (not SqlQuery.Active) or (SqlQuery.RecordCount = 0) then
     MessageDlg('No data', mtError, [mbOk], 0)
   else
   if SaveDialog1.Execute then
   begin
-    SQLQuery.DisableControls;
-    SQLQuery.First;
+    SqlQuery.DisableControls;
+    SqlQuery.First;
     AssignFile(F, SaveDialog1.FileName);
     Rewrite(F);
-    for i:= 0 to SQLQuery.FieldCount - 1 do
+    for i:= 0 to SqlQuery.FieldCount - 1 do
     begin
-      Write(F, '"', SQLQuery.Fields[i].FieldName, '"');
-      if i = SQLQuery.FieldCount - 1 then
+      Write(F, '"', SqlQuery.Fields[i].FieldName, '"');
+      if i = SqlQuery.FieldCount - 1 then
         Writeln(F)
       else
         Write(F, ', ');
     end;
 
-    while not SQLQuery.EOF do
+    while not SqlQuery.EOF do
     begin
-      for i:= 0 to SQLQuery.FieldCount - 1 do
+      for i:= 0 to SqlQuery.FieldCount - 1 do
       begin
-        Write(F, '"', SQLQuery.Fields[i].AsString, '"');
-        if i = SQLQuery.FieldCount - 1 then
+        Write(F, '"', SqlQuery.Fields[i].AsString, '"');
+        if i = SqlQuery.FieldCount - 1 then
           Writeln(F)
         else
           Write(F, ', ');
       end;
-      SQLQuery.Next;
+      SqlQuery.Next;
     end;
     CloseFile(F);
-    SQLQuery.EnableControls;
+    SqlQuery.EnableControls;
   end;
 
 end;
@@ -1967,7 +1942,7 @@ begin
 end;
 
 
-{ Export to comma delimeted file }
+{ Export to comma delimited file }
 
 procedure TfmQueryWindow.lmExportAsCommaClick(Sender: TObject);
 begin
@@ -1991,8 +1966,9 @@ var
   SqlQuery: TSQLQuery;
 begin
   SaveDialog1.DefaultExt:= '.htm';
-  SqlQuery:= FindSqlQuery;
-  if SqlQuery = nil then
+  SqlQuery:= nil;
+  SqlQuery:= GetCurrentSelectQuery;
+  if not(assigned(SqlQuery)) then
     ShowMessage('There is no record set in result')
   else
   if (not SQLQuery.Active) or (SQLQuery.RecordCount = 0) then

+ 2 - 2
tablemanage.pas

@@ -164,8 +164,8 @@ begin
    from a query is awful. Rework to use e.g. the function}
   with sgFields, fmNewEditField do
   begin
-    Characterset:= ''; //todo: support character set in field editing!!!
-    Collation:= ''; //todo: support collation
+    Characterset:= ''; //todo: support character set in field editing: add column to grid
+    Collation:= ''; //todo: support collation in field editing: add column to grid
     FieldName:= Cells[1, Row];
     FieldType:= Cells[2, Row];
     FieldSize:= StrtoInt(Cells[3, Row]);