📄 sybschemamain.pas
字号:
unit sybschemamain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
sybdatabase, StdCtrls, sybcombobox, sybquery, Menus;
type
Tmain = class(TForm)
schema_syb: TSybDatabase;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Button1: TButton;
type_list: TComboBox;
object_list: TComboBox;
query: tsybquery;
column_list: Tsybcombobox;
MainMenu1: TMainMenu;
mnu_Close: TMenuItem;
mnu_Options: TMenuItem;
mnu_Top: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure type_listChange(Sender: TObject);
procedure object_listChange(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure mnu_TopClick(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
PathName : string;
type_str,
object_str,
column_str :tstrings;
type_indx,
object_indx,
column_indx :integer;
first :boolean;
public
{ Public declarations }
end;
var
main: Tmain;
implementation
{$R *.DFM}
procedure Tmain.FormCreate(Sender: TObject);
begin
type_list.ItemIndex:=0;
first:=false;
end;
procedure Tmain.type_listChange(Sender: TObject);
begin
object_list.clear;
column_list.clear;
if type_list.text = 'Databases' then
query.sql:='select name from master..sysdatabases order by name'
else
if type_list.text = 'Procedures' then
query.sql:='select name from sysobjects where type="P" order by name'
else
if (type_list.text = 'Tables')
or (type_list.text = 'SELECT') then
query.sql:='select name from sysobjects where type in ("U","S") order by name'
else
if type_list.text = 'Views' then
query.sql:='select name from sysobjects where type="V" order by name'
else
if type_list.text = 'Rules' then
query.sql:='select name from sysobjects where type="R" order by name'
else
if type_list.text = 'Triggers' then
query.sql:='select name from sysobjects where type="TR" order by name'
else
if type_list.text = 'Users' then
query.sql:='select name from sysusers where gid<>uid order by name'
else
if type_list.text = 'Groups' then
query.sql:='select name from sysusers where gid=uid order by name'
else
if type_list.text = 'Logins' then
query.sql:='select name from master..syslogins order by name'
else
if type_list.text = 'System Datatypes' then
query.sql:='select name from systypes where usertype < 100 order by name'
else
if type_list.text = 'User Datatypes' then
begin
query.sql:='select name from systypes where usertype > 100 order by name'
end
else
if type_list.text = 'Indexes' then
query.sql:='select so.name + "." + si.name from sysobjects so,sysindexes si where so.id = si.id and si.indid<> 0 and so.type in ("U","S") order by so.name,si.indid';
object_list.clear;
if query.sqlexec = 1 then
begin
if query.nextrow = -1 then
object_list.items.add(query.column(1));
while query.nextrow = -1 do
object_list.items.add(query.column(1));
end;
object_list.itemindex:=0;
if (type_list.text = 'Tables')
or (type_list.text = 'Procedures')
or (type_list.text = 'Views') then
begin
column_list.sql:='select name from syscolumns where id = object_id("' + object_list.text + '") order by colid';
column_list.sqlexec;
end;
if (type_list.text = 'Indexes') then
begin
object_listChange(Self);
end;
end;
procedure Tmain.object_listChange(Sender: TObject);
var l1 :string;
l2 :string[3];
i :integer;
s3,cols :ansistring;
begin
column_list.clear;
if type_list.text = 'Databases' then
begin
schema_syb.dbname:=object_list.text;
caption:=schema_syb.servername + '/' + object_list.text + ':' + schema_syb.username;
end
else
if type_list.text = 'Tables' then
begin
column_list.sql:='select name from syscolumns where id = object_id("' + object_list.text + '") order by colid';
column_list.sqlexec;
end
else
if type_list.text = 'Procedures' then
begin
column_list.sql:='select name from syscolumns where id = object_id("' + object_list.text + '") order by colid';
column_list.sqlexec;
end
else
if type_list.text = 'User Datatypes' then
begin
if length(object_list.text) > 0 then
begin
column_list.sql:='sp_dbaman_get_user_type ' + object_list.text;
column_list.sqlexec;
end;
end;
if type_list.text = 'Indexes' then
begin
Pathname:='';
s3:='';
pathname:=copy(object_list.text,pos('.',object_list.text)+1,length(object_list.text)- pos('.',object_list.text)+1);
s3:=copy(object_list.text,1,pos('.',object_list.text)-1);
query.sql:='sp_dbaman_get_index ' + s3 + ',' + pathname;
if (query.sqlexec = 1) or (query.sqlexec = -1) then
begin
column_list.clear;
while query.nextrow = -1 do;
cols:='';
for i:=1 to length(query.column(2)) do
begin
if (query.column(2)[i]<> ',')
and (query.column(2)[i]<> ' ') then
begin
cols:=cols + query.column(2)[i];
end
else
if query.column(2)[i]<> ' ' then
begin
column_list.items.add(cols);
cols:='';
end;
end;
column_list.items.add(cols);
end;
if column_list.items.count>0 then
column_list.itemindex:=0;
end;
end;
procedure Tmain.Button1Click(Sender: TObject);
begin
{ syb.disconnect;}
close;
end;
procedure Tmain.mnu_TopClick(Sender: TObject);
begin
type_str:=type_list.items;
object_str:=object_list.items;
column_str:=column_list.items;
type_indx:=type_list.itemindex;
object_indx:=object_list.itemindex;
column_indx:=column_list.itemindex;
if mnu_top.checked then
begin
main.formstyle:=fsnormal;
mnu_top.checked:=false;
end
else
begin
main.formstyle:=fsstayontop;
mnu_top.checked:=true;
end;
end;
procedure Tmain.FormPaint(Sender: TObject);
begin
if not first then
begin
type_list.items:=type_str;
object_list.items:=object_str;
column_list.items:=column_str;
end;
if type_list.items.count > 0 then
type_list.itemindex:=type_indx;
if object_list.items.count > 0 then
object_list.itemindex:=object_indx;
if column_list.items.count > 0 then
column_list.itemindex:=column_indx;
end;
procedure Tmain.FormActivate(Sender: TObject);
begin
first:=true;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -