* Dialog to edit SQL statements

git-svn-id: trunk@63097 -
This commit is contained in:
michael 2020-04-30 13:58:47 +00:00
parent 02bbb6443a
commit 8fd9186c05
19 changed files with 3680 additions and 27 deletions

2
.gitattributes vendored
View File

@ -4635,6 +4635,8 @@ components/sqldb/design/tsybaseconnection.png -text svneol=unset#image/png
components/sqldb/design/tsybaseconnection_150.png -text svneol=unset#image/png
components/sqldb/design/tsybaseconnection_200.png -text svneol=unset#image/png
components/sqldb/fpmake.pp svneol=native#text/plain
components/sqldb/generatesqldlg.lfm svneol=native#text/plain
components/sqldb/generatesqldlg.pp svneol=native#text/plain
components/sqldb/languages/registersqldb.cs.po svneol=native#text/plain
components/sqldb/languages/registersqldb.de.po svneol=native#text/plain
components/sqldb/languages/registersqldb.es.po svneol=native#text/plain

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,555 @@
{
***************************************************************************
* *
* This source is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This code is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* General Public License for more details. *
* *
* A copy of the GNU General Public License is available on the World *
* Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
* obtain it by writing to the Free Software Foundation, *
* Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA. *
* *
***************************************************************************
}
unit generatesqldlg;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ComCtrls,
DB, SQLDB, ExtCtrls, Buttons, StdCtrls, Spin, ButtonPanel, SynEdit, SynHighlighterSQL;
type
TSQLKeyWord = (skInsert,skInto,skDelete,skFrom,skUpdate,skSelect,skWhere,skAnd,skValues,skSet);
{ TGenerateSQLForm }
TGenerateSQLForm = class(TForm)
BGenerate: TButton;
BPGenSQL: TButtonPanel;
CBOneFieldPerLine: TCheckBox;
cbUpperCaseKeywords: TCheckBox;
CBSystemTables: TCheckBox;
CBTables: TComboBox;
CBQuoteFields: TCheckBox;
edtQuoteChar: TEdit;
lblQuoteChar: TLabel;
LBKeyFields: TListBox;
LCBTables: TLabel;
Label2: TLabel;
LLBKeyFields: TLabel;
LBFields: TListBox;
LSEIndent: TLabel;
LSELineLength: TLabel;
MInsert: TSynEdit;
MRefresh: TSynEdit;
MUpdate: TSynEdit;
MDelete: TSynEdit;
PKeyFields: TPanel;
POptions: TPanel;
PSelectFields: TPanel;
PCSQL: TPageControl;
cbFullyQualifiedFields: TCheckBox;
seIndent: TSpinEdit;
seLineLength: TSpinEdit;
MSelect: TSynEdit;
SynSQLSyn1: TSynSQLSyn;
TSRefresh: TTabSheet;
TSFields: TTabSheet;
TSSelect: TTabSheet;
TSInsert: TTabSheet;
TSUpdate: TTabSheet;
TSDelete: TTabSheet;
procedure BGenerateClick(Sender: TObject);
procedure CBSystemTablesChange(Sender: TObject);
procedure CBTablesChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure TSResize(Sender: TObject);
private
FConnection : TSQLConnection;
FDataset: TSQLQuery;
QuoteChar : Char;
Function IndentString : string;
Function SQLKeyWord(aKeyWord : TSQLKeyWord) : String;
procedure GenDeleteSQL(const TableName : string; KeyFields, SQL: TStrings);
procedure GenInsertSQL(const TableName : string; UpdateFields, SQL: TStrings);
procedure GenModifySQL(const TableName : string; KeyFields, UpdateFields, SQL: TStrings);
procedure GenRefreshSQL(const TableName : string; SelectFields,KeyFields, SQL: TStrings);
procedure GenWhereClause(const aTableName,ParamPrefix : string; KeyFields, SQL: TStrings);
function GetAS: Boolean;
procedure GetDataFieldNames(List: TStrings);
function GetSQLStatement(Index: integer): TStrings;
function GetTableName: String;
function GetQuoted(const aIdentifier : string; Const aTable : String = ''): string;
procedure SetAS(AValue: Boolean);
procedure SetConnection(AValue: TSQLConnection);
procedure SetTableName(const AValue: String);
Procedure SetFieldLists(aFields : TStrings);
{ private declarations }
public
{ public declarations }
Procedure RefreshTableList;
Procedure GenerateSQL;
Procedure ClearSQL(clearSelect : Boolean = False);
Property Dataset : TSQLQuery Read FDataset Write FDataset;
Property Connection : TSQLConnection Read FConnection Write SetConnection;
Property TableName : String Read GetTableName Write SetTableName;
Property SelectSQL : TStrings Index 0 Read GetSQLStatement;
Property InsertSQL : TStrings Index 1 Read GetSQLStatement;
Property UpdateSQL : TStrings Index 2 Read GetSQLStatement;
Property DeleteSQL : TStrings Index 3 Read GetSQLStatement;
Property RefreshSQL : TStrings Index 4 Read GetSQLStatement;
Property AllowSelectTable : Boolean Read GetAS Write SetAS;
end;
Function GenerateSQL(Q : TSQLQuery): Boolean;
implementation
Resourcestring
lrsGeneratesqlstatements = 'Edit/Generate SQL statements';
lrsSQLDataSetOpen = 'Dataset not open: %s';
lrsSQLGenSelect = 'You must select fields to be updated and key fields';
Function GenerateSQL(Q : TSQLQuery): Boolean;
begin
With TGenerateSQLForm.Create(Application) do
try
Dataset:=Q;
Connection:=Q.SQLConnection;
SelectSQL.Text:=Q.SQL.text;
UpdateSQL.Text:=Q.UpdateSQL.Text;
DeleteSQL.Text:=Q.DeleteSQL.Text;
InsertSQL.Text:=Q.insertSQL.Text;
RefreshSQL.Text:=Q.RefreshSQL.Text;
Result:=ShowModal=mrOK;
if Result then
begin
Q.SQL.text := SelectSQL.Text;
Q.UpdateSQL.Text := UpdateSQL.Text;
Q.DeleteSQL.Text := DeleteSQL.Text;
Q.insertSQL.Text := InsertSQL.Text;
Q.RefreshSQL.Text := RefreshSQL.Text;
end;
finally
Free;
end;
end;
{$R *.lfm}
{ TGenerateSQLForm }
procedure TGenerateSQLForm.GenWhereClause(const aTableName, ParamPrefix: string; KeyFields, SQL: TStrings);
var
Maxlen, I: Integer;
isNotLast : Boolean;
L,FieldName: string;
begin
L:=IndentString;
MaxLen:=seLineLength.Value;
SQL.Add(SQLKeyWord(skWhere));
for I := 0 to KeyFields.Count-1 do
begin
isNotLast:=I<KeyFields.Count-1;
FieldName:=GetQuoted(KeyFields[I],ATableName);
L:=L+' '+Format('(%s = :%s%s)', [FieldName,ParamPrefix,KeyFields[I]]);
if I<KeyFields.Count - 1 then
L:=L+' '+SQLKeyWord(skAnd);
if CBOneFieldPerLine.Checked or ((Length(L)>MaxLen) and IsNotLast) then
begin
SQL.Add(L);
L:=IndentString;
end;
end;
SQL.Add(L);
end;
function TGenerateSQLForm.GetQuoted(const aIdentifier: string; const aTable: String =''): string;
begin
Result:=aIdentifier;
if CBQuoteFields.Checked then
Result:=QuoteChar + Result + QuoteChar;
if (aTable<>'') and CBFullyQualifiedFields.Checked then
Result:=GetQuoted(aTable)+'.'+Result;
end;
procedure TGenerateSQLForm.GenDeleteSQL(const TableName: string; KeyFields, SQL: TStrings);
begin
SQL.Clear;
SQL.Add(Format('%s %s %s', [sqlkeyword(skDelete),sqlkeyword(skFrom),GetQuoted(TableName)])); { Do not localize }
GenWhereClause(TableName, 'OLD_',KeyFields, SQL);
end;
procedure TGenerateSQLForm.GenInsertSQL(const TableName: string; UpdateFields, SQL: TStrings);
procedure GenFieldList(isParam : boolean);
var
FN,L: string;
I,MaxLen : integer;
isNotLast : boolean;
begin
L:=IndentString+'(';
MaxLen:=seLineLength.Value;
for I := 0 to UpdateFields.Count - 1 do
begin
IsNotLast:=(I<UpdateFields.Count-1);
FN:=UpdateFields[i];
if not IsParam then
FN:=GetQuoted(FN,TableName)
else
FN:=':'+FN;
L:=L+FN;
if IsNotLast then
L:=L+', ';
if CBOneFieldPerLine.Checked or ((Length(L)>MaxLen) and IsNotLast) then
begin
SQL.Add(L);
L:=IndentString;
end;
end;
SQL.Add(L+')');
end;
begin
SQL.Clear;
SQL.Add(Format('%s %s %s', [SQLKeyWord(skInsert),SQLKeyWord(skInto), GetQuoted(TableName)]));
GenFieldList(False);
SQL.Add(SQLKeyWord(skValues));
GenFieldList(True);
end;
procedure TGenerateSQLForm.GenModifySQL(const TableName: string; KeyFields, UpdateFields, SQL: TStrings);
var
MaxLen,I: integer;
L,FN: string;
isNotLast : Boolean;
begin
L:=IndentString;
MaxLen:=seLineLength.Value;
SQL.Clear;
SQL.Add(Format('%s %s', [SQLKeyWord(skUpdate),GetQuoted(TableName)])); { Do not localize }
SQL.Add(SQLKeyWord(skSet)); { Do not localize }
for I := 0 to UpdateFields.Count-1 do
begin
isNotLast:=I<UpdateFields.Count-1;
FN:=GetQuoted(UpdateFields[i],TableName);
FN:=FN+' = :'+UpdateFields[i];
L:=L+FN;
if IsNotLast then
L:=L+', ';
if CBOneFieldPerLine.Checked or ((Length(L)>MaxLen) and IsNotLast) then
begin
SQL.Add(L);
L:=IndentString;
end;
end;
GenWhereClause(TableName, 'OLD_',KeyFields,SQL);
end;
procedure TGenerateSQLForm.GetDataFieldNames(List: TStrings);
var
I: Integer;
begin
with Dataset do
try
FieldDefs.Update;
List.BeginUpdate;
try
List.Clear;
for I := 0 to FieldDefs.Count - 1 do
List.Add(FieldDefs[I].Name);
finally
List.EndUpdate;
end;
except
MessageDlg(Format(lrsSQLDataSetOpen, [Dataset.Name]), mtError, [mbOK], 0);
end;
end;
procedure TGenerateSQLForm.GenRefreshSQL(const TableName: string; SelectFields,KeyFields, SQL: TStrings);
var
MaxLen,I: integer;
L,FN: string;
isNotLast : Boolean;
begin
MaxLen:=seLineLength.Value;
SQL.Clear;
SQL.Add(Format('%s', [SQLKeyWord(skselect)])); { Do not localize }
L:=IndentString;
for I := 0 to SelectFields.Count-1 do
begin
isNotLast:=I<SelectFields.Count-1;
FN:=GetQuoted(SelectFields[i],TableName);
L:=L+FN;
if IsNotLast then
L:=L+', ';
if CBOneFieldPerLine.Checked or ((Length(L)>MaxLen) and IsNotLast) then
begin
SQL.Add(L);
L:=IndentString;
end;
end;
SQL.Add(Format('%s %s', [SQLKeyWord(skFrom),GetQuoted(TableName)])); { Do not localize }
GenWhereClause(TableName,'',KeyFields,SQL);
end;
procedure GetSelectedItems(ListBox: TListBox; List: TStrings);
var
I: Integer;
begin
List.Clear;
for I := 0 to ListBox.Items.Count - 1 do
if ListBox.Selected[I] then
List.Add(ListBox.Items[I]);
end;
procedure TGenerateSQLForm.GenerateSQL;
function QuotedTableName(const BaseName: string): string;
begin
if CBQuoteFields.Checked then
Result := Format('"%s"', [BaseName]) {do not localize}
else
Result := BaseName;
end;
var
KeyFields: TStringList;
UpdateFields: TStringList;
DidConnect : Boolean;
begin
if EdtQuoteChar.text<>'' then
QuoteChar:=EdtQuoteChar.text[1]
else
QuoteChar:='"';
if (LBKeyFields.SelCount = 0) or (LBFields.SelCount = 0) then
raise Exception.Create(lrsSQLGenSelect);
KeyFields := TStringList.Create;
DidConnect := not DataSet.Database.Connected;
if DidConnect then
DataSet.Database.Connected := true;
try
GetSelectedItems(LBKeyFields, KeyFields);
UpdateFields := TStringList.Create;
try
GetSelectedItems(LBFields, UpdateFields);
TableName := CBTables.Text;
GenDeleteSQL(TableName, KeyFields, MDelete.Lines);
GenInsertSQL(TableName, UpdateFields, Minsert.Lines);
GenModifySQL(TableName, KeyFields, UpdateFields, MUpdate.Lines);
GenRefreshSQL(TableName, UpdateFields, KeyFields, MRefresh.Lines);
finally
UpdateFields.Free;
end;
finally
KeyFields.Free;
if DidConnect then
DataSet.Database.Connected := false;
end;
end;
procedure TGenerateSQLForm.TSResize(Sender: TObject);
Var
W : Integer;
begin
W:=TSFields.CLientWidth div 3;
POPtions.Width:=W;
PSelectFIelds.Width:=W;
end;
function TGenerateSQLForm.IndentString: string;
begin
Result:=StringOfChar(' ',SEIndent.Value);
end;
function TGenerateSQLForm.SQLKeyWord(aKeyWord: TSQLKeyWord): String;
Const
KeyWords : Array[TSQLKeyWord] of string =
('insert','into','delete','from','update','select','where','and','values','set');
begin
Result:=KeyWords[aKeyWord];
if CBUppercaseKeyWords.Checked then
Result:=UpperCase(Result);
end;
function TGenerateSQLForm.GetTableName: String;
begin
Result:=CBTables.Text;
end;
procedure TGenerateSQLForm.SetAS(AValue: Boolean);
begin
CBTables.Enabled:=AValue;
end;
procedure TGenerateSQLForm.SetConnection(AValue: TSQLConnection);
begin
if FConnection=AValue then Exit;
FConnection:=AValue;
RefreshTableList;
end;
function TGenerateSQLForm.GetSQLStatement(Index: integer): TStrings;
begin
Case Index of
0 : Result:=MSelect.Lines;
1 : Result:=MInsert.Lines;
2 : Result:=MUpdate.Lines;
3 : Result:=MDelete.Lines;
4 : Result:=MRefresh.Lines;
end;
end;
function TGenerateSQLForm.GetAS: Boolean;
begin
Result:=CBTables.Enabled;
end;
procedure TGenerateSQLForm.RefreshTableList;
Var
TN : String;
begin
TN:=CBTables.Text;
With CBTables.Items do
try
BeginUpdate;
Clear;
if Not Assigned(FConnection) then
exit;
FConnection.Connected:=true;
FConnection.GetTableNames(CBTables.Items,CBSystemTables.Checked);
finally
EndUpdate;
end;
With CBTables do
If (TN<>'') then
ItemIndex:=Items.IndexOf(TN);
end;
procedure TGenerateSQLForm.ClearSQL(clearSelect : Boolean = False);
begin
if ClearSelect then
MSelect.Clear;
MInsert.Clear;
MUpdate.Clear;
MDelete.Clear;
MRefresh.Clear;
end;
procedure TGenerateSQLForm.SetTableName(const AValue: String);
begin
With CBTables do
begin
ItemIndex:=Items.IndexOf(AValue);
CBTablesChange(CBTables);
end;
end;
procedure TGenerateSQLForm.SetFieldLists(aFields: TStrings);
Var
I,Idx : Integer;
begin
if aFields=Nil then
begin
LBKeyFields.Items.Clear;
LBFields.Items.Clear;
end
else
begin
LBKeyFields.Items:=aFields;
LBFields.Items:=aFields;
end;
if not Assigned(Dataset) then exit;
For I:=0 to FDataset.FieldDefs.Count-1 do
begin
Idx:=LBFields.Items.IndexOf(FDataset.FieldDefs[i].Name);
if Idx>=0 then
LBFields.Selected[Idx]:=true
end;
For I:=0 to FDataset.Fields.Count-1 do
if ((Dataset.UpdateMode=upWhereKeyOnly) and (pfInKey in FDataset.Fields[i].ProviderFlags)) or
(Dataset.UpdateMode=upWhereAll) then
begin
Idx:=LBKeyFields.Items.IndexOf(FDataset.Fields[i].FieldName);
if (Idx>=0) then
LBKeyFields.Selected[Idx]:=true;
end;
end;
procedure TGenerateSQLForm.CBTablesChange(Sender: TObject);
Var
l : TStringList;
begin
With CBTables do
If (ItemIndex=-1) Then
SetFieldLists(Nil)
else
begin
L:=TstringList.Create;
try
Connection.GetFieldNames(TableName,L);
SetFieldLists(L)
finally
L.Free;
end;
end;
ClearSQL;
end;
procedure TGenerateSQLForm.FormCreate(Sender: TObject);
begin
Caption:= lrsGeneratesqlstatements;
EdtQuoteChar.Text:='"';
end;
procedure TGenerateSQLForm.BGenerateClick(Sender: TObject);
begin
GenerateSQL;
end;
procedure TGenerateSQLForm.CBSystemTablesChange(Sender: TObject);
begin
if Assigned(Connection) then
RefreshTableList;
end;
end.

View File

@ -10,10 +10,26 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.5.4\n"
#: registersqldb.seditsql
msgid "Edit SQL ..."
msgstr ""
#: registersqldb.seditupdatesql
msgid "Edit all SQL statements"
msgstr ""
#: registersqldb.serrconnectionnotassigned
msgid "Database not assigned. Assign Database first"
msgstr ""
#: registersqldb.sfirebirddatabases
msgid "Firebird databases"
msgstr "Firebird datebáze"
#: registersqldb.sgenerateupdatesql
msgid "Generate update SQL"
msgstr ""
#: registersqldb.sinterbasedatabases
msgid "Interbase databases"
msgstr "Interbase databáze"

View File

@ -11,10 +11,26 @@ msgstr ""
"Language: de\n"
"X-Generator: Poedit 1.8.9\n"
#: registersqldb.seditsql
msgid "Edit SQL ..."
msgstr ""
#: registersqldb.seditupdatesql
msgid "Edit all SQL statements"
msgstr ""
#: registersqldb.serrconnectionnotassigned
msgid "Database not assigned. Assign Database first"
msgstr ""
#: registersqldb.sfirebirddatabases
msgid "Firebird databases"
msgstr "Firebird-Datenbanken"
#: registersqldb.sgenerateupdatesql
msgid "Generate update SQL"
msgstr ""
#: registersqldb.sinterbasedatabases
msgid "Interbase databases"
msgstr "Interbase-Datenbanken"

View File

@ -9,10 +9,26 @@ msgstr ""
"POT-Creation-Date: \n"
"MIME-Version: 1.0\n"
#: registersqldb.seditsql
msgid "Edit SQL ..."
msgstr ""
#: registersqldb.seditupdatesql
msgid "Edit all SQL statements"
msgstr ""
#: registersqldb.serrconnectionnotassigned
msgid "Database not assigned. Assign Database first"
msgstr ""
#: registersqldb.sfirebirddatabases
msgid "Firebird databases"
msgstr "Base de datos Firebird"
#: registersqldb.sgenerateupdatesql
msgid "Generate update SQL"
msgstr ""
#: registersqldb.sinterbasedatabases
msgid "Interbase databases"
msgstr "Base de datos Interbase"

View File

@ -11,10 +11,26 @@ msgstr ""
"Language: fr\n"
"X-Generator: Poedit 1.8.11\n"
#: registersqldb.seditsql
msgid "Edit SQL ..."
msgstr ""
#: registersqldb.seditupdatesql
msgid "Edit all SQL statements"
msgstr ""
#: registersqldb.serrconnectionnotassigned
msgid "Database not assigned. Assign Database first"
msgstr ""
#: registersqldb.sfirebirddatabases
msgid "Firebird databases"
msgstr "Bases de données Firebird"
#: registersqldb.sgenerateupdatesql
msgid "Generate update SQL"
msgstr ""
#: registersqldb.sinterbasedatabases
msgid "Interbase databases"
msgstr "Bases de données Interbase"

View File

@ -11,10 +11,26 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.5.4\n"
#: registersqldb.seditsql
msgid "Edit SQL ..."
msgstr ""
#: registersqldb.seditupdatesql
msgid "Edit all SQL statements"
msgstr ""
#: registersqldb.serrconnectionnotassigned
msgid "Database not assigned. Assign Database first"
msgstr ""
#: registersqldb.sfirebirddatabases
msgid "Firebird databases"
msgstr "Firebird adatbázisok"
#: registersqldb.sgenerateupdatesql
msgid "Generate update SQL"
msgstr ""
#: registersqldb.sinterbasedatabases
msgid "Interbase databases"
msgstr "Interbase adatbázisok"

View File

@ -12,10 +12,26 @@ msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: \n"
#: registersqldb.seditsql
msgid "Edit SQL ..."
msgstr ""
#: registersqldb.seditupdatesql
msgid "Edit all SQL statements"
msgstr ""
#: registersqldb.serrconnectionnotassigned
msgid "Database not assigned. Assign Database first"
msgstr ""
#: registersqldb.sfirebirddatabases
msgid "Firebird databases"
msgstr "Archivi Firebird"
#: registersqldb.sgenerateupdatesql
msgid "Generate update SQL"
msgstr ""
#: registersqldb.sinterbasedatabases
msgid "Interbase databases"
msgstr "Archivi Interbase"

View File

@ -12,10 +12,26 @@ msgstr ""
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
"Language: lt\n"
#: registersqldb.seditsql
msgid "Edit SQL ..."
msgstr ""
#: registersqldb.seditupdatesql
msgid "Edit all SQL statements"
msgstr ""
#: registersqldb.serrconnectionnotassigned
msgid "Database not assigned. Assign Database first"
msgstr ""
#: registersqldb.sfirebirddatabases
msgid "Firebird databases"
msgstr "Firebird duomenų bazės"
#: registersqldb.sgenerateupdatesql
msgid "Generate update SQL"
msgstr ""
#: registersqldb.sinterbasedatabases
msgid "Interbase databases"
msgstr "Interbase duomenų bazės"

View File

@ -12,10 +12,26 @@ msgstr ""
"Language: pl\n"
"X-Generator: Poedit 1.8.7.1\n"
#: registersqldb.seditsql
msgid "Edit SQL ..."
msgstr ""
#: registersqldb.seditupdatesql
msgid "Edit all SQL statements"
msgstr ""
#: registersqldb.serrconnectionnotassigned
msgid "Database not assigned. Assign Database first"
msgstr ""
#: registersqldb.sfirebirddatabases
msgid "Firebird databases"
msgstr "Bazy danych Firebird"
#: registersqldb.sgenerateupdatesql
msgid "Generate update SQL"
msgstr ""
#: registersqldb.sinterbasedatabases
msgid "Interbase databases"
msgstr "Bazy danych Interbase"

View File

@ -1,10 +1,26 @@
msgid ""
msgstr "Content-Type: text/plain; charset=UTF-8"
#: registersqldb.seditsql
msgid "Edit SQL ..."
msgstr ""
#: registersqldb.seditupdatesql
msgid "Edit all SQL statements"
msgstr ""
#: registersqldb.serrconnectionnotassigned
msgid "Database not assigned. Assign Database first"
msgstr ""
#: registersqldb.sfirebirddatabases
msgid "Firebird databases"
msgstr ""
#: registersqldb.sgenerateupdatesql
msgid "Generate update SQL"
msgstr ""
#: registersqldb.sinterbasedatabases
msgid "Interbase databases"
msgstr ""

View File

@ -11,10 +11,26 @@ msgstr ""
"Language: pt_BR\n"
"X-Generator: Poedit 1.8.7.1\n"
#: registersqldb.seditsql
msgid "Edit SQL ..."
msgstr ""
#: registersqldb.seditupdatesql
msgid "Edit all SQL statements"
msgstr ""
#: registersqldb.serrconnectionnotassigned
msgid "Database not assigned. Assign Database first"
msgstr ""
#: registersqldb.sfirebirddatabases
msgid "Firebird databases"
msgstr "Bancos de dados \"Firebird\""
#: registersqldb.sgenerateupdatesql
msgid "Generate update SQL"
msgstr ""
#: registersqldb.sinterbasedatabases
msgid "Interbase databases"
msgstr "Bancos de dados \"Interbase\""

View File

@ -11,10 +11,26 @@ msgstr ""
"Language: ru\n"
"X-Generator: Poedit 1.7.7\n"
#: registersqldb.seditsql
msgid "Edit SQL ..."
msgstr ""
#: registersqldb.seditupdatesql
msgid "Edit all SQL statements"
msgstr ""
#: registersqldb.serrconnectionnotassigned
msgid "Database not assigned. Assign Database first"
msgstr ""
#: registersqldb.sfirebirddatabases
msgid "Firebird databases"
msgstr "Базы данных Firebird"
#: registersqldb.sgenerateupdatesql
msgid "Generate update SQL"
msgstr ""
#: registersqldb.sinterbasedatabases
msgid "Interbase databases"
msgstr "Базы данных Interbase"

View File

@ -13,10 +13,26 @@ msgstr ""
"X-Generator: Lokalize 1.5\n"
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
#: registersqldb.seditsql
msgid "Edit SQL ..."
msgstr ""
#: registersqldb.seditupdatesql
msgid "Edit all SQL statements"
msgstr ""
#: registersqldb.serrconnectionnotassigned
msgid "Database not assigned. Assign Database first"
msgstr ""
#: registersqldb.sfirebirddatabases
msgid "Firebird databases"
msgstr "Бази даних Firebird"
#: registersqldb.sgenerateupdatesql
msgid "Generate update SQL"
msgstr ""
#: registersqldb.sinterbasedatabases
msgid "Interbase databases"
msgstr "Бази даних Interbase"

View File

@ -12,10 +12,26 @@ msgstr ""
"X-Generator: Poedit 1.8.7.1\n"
"X-Poedit-SourceCharset: UTF-8\n"
#: registersqldb.seditsql
msgid "Edit SQL ..."
msgstr ""
#: registersqldb.seditupdatesql
msgid "Edit all SQL statements"
msgstr ""
#: registersqldb.serrconnectionnotassigned
msgid "Database not assigned. Assign Database first"
msgstr ""
#: registersqldb.sfirebirddatabases
msgid "Firebird databases"
msgstr "Firebird数据库"
#: registersqldb.sgenerateupdatesql
msgid "Generate update SQL"
msgstr ""
#: registersqldb.sinterbasedatabases
msgid "Interbase databases"
msgstr "Interbase数据库"

View File

@ -25,6 +25,7 @@
unit registersqldb;
{$mode objfpc}{$H+}
{$modeswitch typehelpers}
{$DEFINE HASIBCONNECTION}
{$DEFINE HASMYSQL55CONNECTION}
@ -209,7 +210,11 @@ Type
TSQLQueryEditor = class(TBufDatasetDesignEditor)
Private
FVOffset : Integer;
Procedure EditSQL;
Protected
procedure DesignUpdateSQL(aQuery: TSQLQuery); virtual;
procedure GenerateUpdateSQL(aQuery: TSQLQuery); virtual;
procedure EditSQL(aQuery: TSQLQuery); virtual;
procedure DoEditSQL(aQuery: TSQLQuery); virtual;
public
constructor Create(AComponent: TComponent; ADesigner: TComponentEditorDesigner); override;
procedure ExecuteVerb(Index: integer); override;
@ -223,7 +228,7 @@ implementation
{$R registersqldb.res}
uses dynlibs;
uses dialogs, generatesqldlg, dynlibs;
procedure RegisterUnitSQLdb;
begin
@ -286,7 +291,10 @@ Resourcestring
SSQLScript = 'SQL Script file';
SSQLScriptDesc = 'Create a new SQL Script file';
SSQLSource = 'Insert your SQL statements here';
SEditSQL = 'Edit SQL...';
SEditSQL = 'Edit SQL ...';
SGenerateUpdateSQL = 'Generate update SQL';
SEditUpdateSQL = 'Edit all SQL statements';
SErrConnectionNotAssigned = 'Database not assigned. Assign Database first';
SFireBirdDatabases = 'Firebird databases';
SSQLite3Databases = 'SQLite3 databases';
@ -295,23 +303,71 @@ Resourcestring
sLibraries = 'Shared libraries';
Type
{ TConnectionHelper }
TConnectionHelper = Class(TSQLConnection)
Public
Function GenerateStatement(Q : TCustomSQLQuery; aKind : TUpdateKind; Out WithReturning : Boolean) : String;
end;
{ TConnectionHelper }
function TConnectionHelper.GenerateStatement(Q : TCustomSQLQuery; aKind: TUpdateKind; Out WithReturning : Boolean): String;
begin
WithReturning:=False;
Case aKind of
ukModify : Result:=Self.ConstructUpdateSQL(Q,WithReturning);
ukDelete : Result:=Self.ConstructDeleteSQL(Q);
ukInsert : Result:=Self.ConstructInsertSQL(Q,WithReturning);
end;
end;
{ TSQLQueryEditor }
procedure TSQLQueryEditor.EditSQL;
procedure TSQLQueryEditor.DesignUpdateSQL(aQuery: TSQLQuery);
begin
if GenerateSQL(aQuery) then
Modified;
end;
procedure TSQLQueryEditor.GenerateUpdateSQL(aQuery: TSQLQuery);
Var
TH : TConnectionHelper;
R : Boolean;
begin
if not Assigned(aQuery.SQLConnection) then
ShowMessage(SErrConnectionNotAssigned)
else
begin
TH:=TConnectionHelper(Aquery.SQLConnection);
R:=False;
aQuery.UpdateSQL.Text:=TH.GenerateStatement(aQuery,ukModify,R);
aQuery.DeleteSQL.Text:=TH.GenerateStatement(aQuery,ukDelete,R);
aQuery.InsertSQL.Text:=TH.GenerateStatement(aQuery,ukInsert,R);
Modified;
end;
end;
procedure TSQLQueryEditor.EditSQL(aQuery : TSQLQuery);
var
TheDialog:TSQLStringsPropertyEditorDlg;
Strings :TStrings;
Query :TSQLQuery;
begin
Query := Component as TSQLQuery;
Strings := Query.SQL;
Strings := aQuery.SQL;
TheDialog := TSQLStringsPropertyEditorDlg.Create(Application);
try
TheDialog.SQLEditor.Text := Strings.Text;
TheDialog.Caption := Format(SSQLStringsPropertyEditorDlgTitle, ['SQL']);
TheDialog.Connection := (Query.DataBase as TSQLConnection);
TheDialog.Transaction := (Query.Transaction as TSQLTransaction);
TheDialog.Connection := (aQuery.DataBase as TSQLConnection);
TheDialog.Transaction := (aQuery.Transaction as TSQLTransaction);
if (TheDialog.ShowModal = mrOK)then
begin
Strings.Text := TheDialog.SQLEditor.Text;
@ -329,26 +385,46 @@ begin
FVOffset:=Inherited GetVerbCount;
end;
procedure TSQLQueryEditor.ExecuteVerb(Index: integer);
procedure TSQLQueryEditor.DoEditSQL(aQuery: TSQLQuery);
var
AHook: TPropertyEditorHook;
pe: TPropertyEditor;
begin
if not GetHook(AHook) then
EditSQL(aQuery)
else
begin
pe := TSQLStringsPropertyEditor.Create(AHook, 1);
try
pe.SetPropEntry(0, Component, FindPropInfo(Component, 'SQL'));
pe.Edit;
finally
pe.Free;
end;
end;
end;
procedure TSQLQueryEditor.ExecuteVerb(Index: integer);
var
Q : TSQLQuery;
begin
if Index < FVOffset then
inherited
else
if not GetHook(AHook) then
editSQL
begin
Q:=Component as TSQLQuery;
case Index - FVOffset of
0 : DoEditSQL(Q);
1 : GenerateUpdateSQL(Q);
2 : DesignUpdateSQL(Q);
else
begin
pe := TSQLStringsPropertyEditor.Create(AHook, 1);
try
pe.SetPropEntry(0, Component, FindPropInfo(Component, 'SQL'));
pe.Edit;
finally
pe.Free;
end;
end;
// Do nothing
end;
end;
end;
function TSQLQueryEditor.GetVerb(Index: integer): string;
@ -356,12 +432,16 @@ begin
if Index < FVOffset then
Result := inherited
else
Result := SEditSQL;
case Index - FVOffset of
0 : Result := SEditSQL;
1 : Result := SGenerateUpdateSQL;
2 : Result := SEditUpdateSQL;
end;
end;
function TSQLQueryEditor.GetVerbCount: integer;
begin
Result := FVOffset + 1;
Result := FVOffset + 3;
end;
{ TSQLDBLibraryLoaderConnectionTypePropertyEditor }

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<Package Version="4">
<Package Version="5">
<Name Value="SQLDBLaz"/>
<Type Value="RunAndDesignTime"/>
<Author Value="Joost van der Sluis"/>
@ -24,7 +24,7 @@
With the exception of the unit registersqldb, which is GPL-2. This unit contains code for the IDE and is usually not used by programs."/>
<Version Major="1" Release="2"/>
<Files Count="3">
<Files Count="5">
<Item1>
<Filename Value="registersqldb.pas"/>
<HasRegisterProc Value="True"/>
@ -39,6 +39,14 @@ With the exception of the unit registersqldb, which is GPL-2. This unit contains
<Filename Value="sqlstringspropertyeditordlg.pas"/>
<UnitName Value="SQLStringsPropertyEditorDlg"/>
</Item3>
<Item4>
<Filename Value="generatesqldlg.lfm"/>
<Type Value="LFM"/>
</Item4>
<Item5>
<Filename Value="generatesqldlg.pp"/>
<UnitName Value="generatesqldlg"/>
</Item5>
</Files>
<i18n>
<EnableI18N Value="True"/>
@ -63,7 +71,6 @@ With the exception of the unit registersqldb, which is GPL-2. This unit contains
</UsageOptions>
<PublishOptions>
<Version Value="2"/>
<IgnoreBinaries Value="False"/>
</PublishOptions>
</Package>
</CONFIG>

View File

@ -8,7 +8,7 @@ unit SQLDBLaz;
interface
uses
registersqldb, SQLStringsPropertyEditorDlg, LazarusPackageIntf;
registersqldb, SQLStringsPropertyEditorDlg, generatesqldlg, LazarusPackageIntf;
implementation