Single Handle ASA backup/restore Program

Source: Internet
Author: User
Tags add sql mysql return string trim backup
Backup | programs | recovery
adaptive Server Anywhere (ASA in this article) is a database management system that is PowerBuilder (Pb in this paper) and can be used as a database server for small application systems. And the backup/restore of the database is a basic work, can you do it in just a few minutes to complete the writing of this kind of program? This article will introduce a PB with the ASA Backup/recovery program, only a short time, can be completed and applied to ASA Data Environment for small applications.

A backup program
First take a look at the backup program part of the wording. Create a text box sle_1 on the form to display the file name of the backup and add two buttons: cb_1 (Browse), cb_2 (Backup). The corresponding event code is as follows:

//cb_1.clicked ()

string Fname,name

getfilesavename (' Save ', fname,name, DB, ' database backup file (*.1), *.1 ')

sle_1.text=fname

//cb_2.clicked ()

string Mysql,bfname

bfname=trim (Sle_1.text)

bfname=left (Bfname,len (Bfname)-2)

mysql= "BACKUP DATABASE to" "+bfname+" "

execute immediate:mysql using sqlca;//SQL statement to perform backup immediately

if Sqlca.sqlcode=0 Then

messagebox ("Info tip", ' Backup successful! ', information! Ok! )//gives information about the success or failure of the backup

else

messagebox ("info hint", "Backup failed!") ', information! Ok! )

end if

Two recovery program
Let's take a look at the preparation of the recovery database program. Build a text box sle_1 on the form, display the backup file name for recovery, and add two buttons: cb_1 (Find), cb_2 (Restore). Declare an API function that modifies file properties:

function ulong SetFileAttributes (ref string Lpfilename,ulong dwfileattributes) LIBRARY "kernel32.dll" ALIAS for " Setfileattributesa "

The corresponding event code is as follows:

//cb_1.clicked ()

string Fname,name

getfileopenname (' lookup ', Fname,name, "1", "Database backup file (*.1), *.1")

sle_1.text=fname

//cb_2.clicked ()

string Mysql,bfname,gzname

ulong sxz=32,kb//sxz is the property value of the file, and 32 indicates a read-write

boolean tmp

bfname=trim (Sle_1.text)

bfname=left (Bfname,len (Bfname)-2)

//D:lgz is the directory of the database files in the example, Tmp.db is a temporary database file

mysql= "RESTORE DATABASE ' d:lgz\tmp.db ' from '" +bfname+ ""

execute Immediate:mysql using sqlca;//also uses SQL statements to immediately perform the recovery database work

if Sqlca.sqlcode <> 0 Then

messagebox ("Information Prompt", "Data recovery failed!") ', information! Ok! )

return

end if

disconnect; Disconnecting a database

gzname= ' d:lgz\gz.db '//containing the path of the database file

setfileattributes (GZNAME,SXZ)//Remove read-only property

tmp=filedelete (' d:lgz\gz.db ')//delete pre-restore Database

if Tmp=false Then

messagebox ("info hint", "Backup failed!") ', information! Ok! )

return

end if

//copy of the temporary database to the current database file

bfname= "D:lgz\tmp.db"

gzname= "D:lgz\gz.db"

kb=filecopy (Bfname,gzname,true)

if Kb=1 Then

messagebox ("Information prompt", ' Database recovery successful! ', information! Ok! )

else

messagebox ("Informational Prompt", "Database replication failed!") ', information! Ok! )

return

end if

filedelete (' d:lgz\tmp.db ')//delete temporary database files

connect;

Summary of the Three
The implementation of the program backup and restore all just call the SQL built-in function to achieve, so that the program appears relatively concise. Although the function is single and simple, it can also meet the needs of database backup and recovery, and can save a lot of energy for the database administrators in the application situations where the requirements are not high. The above program is debugged in PB 9.0.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.