資料表備份之相關問題 |
答題得分者是:william
|
funging
一般會員 發表:13 回覆:41 積分:10 註冊:2002-10-28 發送簡訊給我 |
請各位高手幫個忙,這個delphi程式,主要是要將資料庫之資料表備份成xxx.dat檔,
但是小妹我在執行程式時,發生"file not found"這個錯誤訊息,
錯誤在程式執行formactivate的Reset(bkfile_tableList);這一行,
原先我bkfile_tableList的型態為設定為bkfile_tableList :file of TBackupInfo;
而TbackupInfor 設定如下:
TBackupInfo = packed record
tb_Name :string[20];
tb_Title :string[38];
tb_BackupTime :string[22];
tb_Title :string[38];
tb_BackupTime :string[22];
CRLF :string[2];
end;
其實不是很懂為何要這樣設?而且也出現問題了!><
請知道的高手幫個忙,回答一下吧!^^謝謝!
以下為原始程式:
unit Dbset_Backup; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Spin, ComCtrls, FileCtrl, ExtCtrls, DB, DBTables,
Buttons; type
TfmDbSet_Backup = class(TForm)
rgBackupType: TRadioGroup;
flbBackupFile: TFileListBox;
spedYear: TSpinEdit;
Label1: TLabel;
RadioButton1: TRadioButton;
tb_bkNTIS: TTable;
bitnExit: TBitBtn;
pbBackup: TProgressBar;
Database1: TDatabase;
lvNTIS: TListView;
bitnBackup: TBitBtn;
RadioButton2: TRadioButton;
RadioButton3: TRadioButton;
RadioButton4: TRadioButton;
RadioButton5: TRadioButton;
RadioButton6: TRadioButton;
procedure FormActivate(Sender: TObject);
procedure bitnBackupClick(Sender: TObject);
procedure rgBackupTypeClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure bitnExitClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
procedure AllListSavetoFile(tb_bkNTIS :TTable);
procedure UpdateTime(fileName,tableName :string);
end; TBackupInfo = packed record
tb_Name :string[20];
tb_Title :string[38];
tb_BackupTime :string[22];
CRLF :string[2];
end;
TCollege = packed record
COL_ID :string[1];
COL_CNAME :string[20];
COL_ENAME :string[60];
end;
var
fmDbSet_Backup: TfmDbSet_Backup; implementation {$R *.dfm}
procedure TfmDbSet_Backup.AllListSavetoFile(tb_bkNTIS :TTable);
var
bkfile_College :file of TCollege;
rCollege :TCollege;
currentDir:string;
fileHead:string;
begin
tb_bkNTIS.open;
currentDir:='c:\Backup\';
fileHead:=currentDir '@' spedYear.text '_';
if tb_bkNTIS.TableName = 'COLLEGE' then
begin
assignfile(bkfile_College,fileHead 'College.dat');
Rewrite(bkfile_College); while not tb_bkNTIS.Eof do
begin
rCollege.COL_ID:=tb_bkNTIS.fieldbyname('COL_ID').AsString;
rCollege.COL_CNAME:=tb_bkNTIS.fieldbyname('COL_CNAME').AsString;
rCollege.COL_ENAME:=tb_bkNTIS.fieldbyname('COL_ENAME').AsString;
Write(bkfile_College,rCollege);
pbBackup.Position:=pbBackup.Position 100;
tb_bkNTIS.Next;
end; closefile(bkfile_College);
UpdateTime('c:\Backup\bkfile_AllList.dat','COLLEGE');
UpdateTime('c:\Backup\bkfile_SchList.dat','COLLEGE');
end;
chDir('C:\Backup\');
tb_bkNTIS.Close; end;
procedure TfmDbSet_Backup.UpdateTime(fileName,tableName :string);
var
bk_Items :TBackupInfo;
bkfile_tableList :file of TBackupInfo;
count :integer;
begin
assignfile(bkfile_tableList,fileName);
filemode:=2;
reset(bkfile_tableList);
count:=0; while not eof(bkfile_tableList) do
begin
read(bkfile_tableList,bk_Items); if bk_Items.tb_Name = tableName then
begin
bk_Items.tb_BackupTime:=datetostr(now) ' ' timetostr(time);//紀錄時間
seek(bkfile_tableList,count);
write(bkfile_tableList,bk_Items);
break;
end; count:=count 1;
end; closefile(bkfile_tableList);
end; procedure TfmDbSet_Backup.FormActivate(Sender: TObject);
var
bk_Items :TBackupInfo;
bkfile_tableList :file of TBackupInfo;
year :string;
begin
mkdir('c:\Backup\');
flbBackupFile.Directory:='c:\Backup\';
year:=inttostr(strtoint(copy(datetostr(now),1,4)));
showmessage(year);
spedYear.text:=year;
rgBackupType.ItemIndex:=0; //預設初始為全部備份之選項;
AssignFile(bkfile_tableList,'bkfile_AllList.dat');//備份之檔名為xx.dat;
Reset(bkfile_tableList); while not eof(bkfile_tableList) do
begin
Read(bkfile_tableList,bk_Items); with lvNTIS.Items.Add do
begin
Caption:=bk_Items.tb_Name;
SubItems.Add(bk_Items.tb_title);
SubItems.Add(bk_Items.tb_BackupTime);
end;
end; CloseFile(bkfile_tableList);
flbBackupFile.Directory:='c:\Backup\';
end; procedure TfmDbSet_Backup.bitnBackupClick(Sender: TObject);
var
tb_bkNTIS :Ttable;
i :byte;
tableName :string;
begin
tb_bkNTIS:=ttable.create(self);
tb_bkNTIS.DatabaseName:='TeacherGrade'; for i:=0 to lvNTIS.Items.Count-1 do
begin
tableName:=lvNTIS.Items[i].Caption;
tb_bkNTIS.TableName:=tableName;
AllListSavetoFile(tb_bkNTIS);
end;
end;
procedure TfmDbSet_Backup.rgBackupTypeClick(Sender: TObject);
var
bk_Items :TBackupInfo;
bkfile_tableList :file of TBackupInfo;
// i :byte;
begin
ChDir('c:\Backup\');
lvNTIS.Items.Clear;
case rgBackupType.ItemIndex of
0:begin
AssignFile(bkfile_tableList,'bkfile_AllList.dat');
Reset(bkfile_tableList); while not eof(bkfile_tableList) do
begin
Read(bkfile_tableList,bk_Items); with lvNTIS.Items.Add do
begin
Caption:=bk_Items.tb_Name;
SubItems.Add(bk_Items.tb_title);
SubItems.Add(bk_Items.tb_BackupTime);
end;
end; CloseFile(bkfile_tableList);
end; end;
end; procedure TfmDbSet_Backup.FormClose(Sender: TObject; var Action: TCloseAction);
begin
//mkDir('c:\Backup\'); ChDir('c:\Backup\');
fmDbSet_Backup.free;
end;
procedure TfmDbSet_Backup.bitnExitClick(Sender: TObject);
begin
close;
end; procedure TfmDbSet_Backup.FormCreate(Sender: TObject);
begin end; end.
|
william
版主 發表:66 回覆:2535 積分:3048 註冊:2002-07-11 發送簡訊給我 |
|
funging
一般會員 發表:13 回覆:41 積分:10 註冊:2002-10-28 發送簡訊給我 |
1、bkfile_tableList :file of TBackupInfo;
2、
TBackupInfo = packed record
tb_Name :string[20];
tb_Title :string[38];
tb_BackupTime :string[22];
tb_Title :string[38];
tb_BackupTime :string[22];
CRLF :string[2];
end; 再請問一下,諸如上述的設定,目的是在做什麼??
是否有相關資訊可以參考?? 我想寫個將mysql資料庫裡的資料表的資料,做備份的程式!
煩請知道的高手能替我解答!謝謝!^^
|
william
版主 發表:66 回覆:2535 積分:3048 註冊:2002-07-11 發送簡訊給我 |
1) declare a typed file, which is made up of records (TBackupInfo) stored sequentially. You can vertify it by using some binary editor (e.g. UltraEdit) to view the file content. 2) 'packed' keyword is to tell the compiler NOT to make any alignment for the following record definition. e.g.
TARec = packed record AByte: byte; AWord: word; end; .... ARec: TARec = (AByte: 1; AWord: 2); ....In memory ARec will looks like "01 02 00", i.e. 3 bytes in size. Without the "packed" keyword, it may look like "01 00 02 00" or something else depending on your setting of "Record field alignment" in Project|Options|Compilers' |
funging
一般會員 發表:13 回覆:41 積分:10 註冊:2002-10-28 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |