Table of Contents
Lesson 2 - "Employees" Database on Server
In Lesson 1, you learned out to create a local, Valentina-powered database application with Revolution.
In Lesson 2, you will learn how to work with local databases as well as remote databases running under Valentina Server.
In order to follow this lesson, you must have the project created under Lesson 1.
Step 1: Project Preparation for the Work with Server
Copy the files you created in Lesson1_step6 to a new location, start Revolution, then load the project.
In the current stack, create a new custom property called gClient. This is used in the openCard handler. To do this you should make the next:
- From the toolbar, select Inspector.
- In the Inspector, Select the Custom Properties option. Create a new custom property called gClient. In the Property Contents box, set the value to true.
- Go back to your card and select Edit Card Script. Modify the code you OpenCard handler as follows:
on OpenCard if the gClient of this stack is true then get valentina_InitClient() else get valentina_Init( 10 * 1024 * 1024 ) end if DatabaseCreate end OpenCard
Modifying the DatabaseCreate handler
Instead of creating a database locally, you need to create a database on the remote server. Locate the DatabaseCreate handler from Lesson 1 and modify the script as:
on DatabaseCreate if the gClient of this stack is true then put VConnection_Constructor( "localhost", "sa", "sa") into mConn get VConnection_Open( mConn ) put VDatabase_Constructor( mConn ) into mDatabase else put VDatabase_Constructor() into mDatabase end if get VDatabase_Open( mDatabase, "Database1" ) if VDatabase_ErrNumber( mDatabase ) is not "0" then if VDatabase_ErrNumber( mDatabase ) is not "532480" then get VDatabase_Create( mDatabase, "Database1", "kDscDatBlbInd" ) CreateStructure else answer VDatabase_ErrString( mDatabase ) close the defaultStack end if end if get VDatabase_DateFormat( mDatabase, "kYMD" ) get VDatabase_DateSep( mDatabase, "-" ) put VDatabase_Table( mDatabase, "Person" ) into mPerson put VTable_Field( mPerson, "FirstName" ) into mFirstName put VTable_Field( mPerson, "LastName" ) into mLastName put VTable_Field( mPerson, "BirthDate" ) into mBirthDate end DatabaseCreate
If Valentina Server is located on another computer, you should change “localhost” to the address of your server.
Preparing Valentina Server
Before you can use your project, Valentina Server has to be running. You can do this in a terminal window. Set the VerboseLevel to 3 in ini-file of the server. You can find out how to do this in the document ValentinaServer.pdf.
Run the code you have so far. If you followed all of the tasks, Valentina creates a database where the server stores databases and not locally in a folder.
Step 2: Adding error checking
Adding new function ShowError()
To do this you should make the following:
- Choose “Edit Card Script” from the card popup menu.
- Write the following text:
function ShowError put Valentina_ErrNumber() into errCode put Valentina_ErrString() into errString if errCode <> 0 then show message box put errString into message end if end ShowError
Improving DatabaseCreate() procedure
Locate the DatabaseCreate handler modify the script as
on DatabaseCreate if the gClient of this stack is true then put VConnection_Constructor( "localhost", "sa", "sa") into mConn get VConnection_Open( mConn ) get ShowError() put VDatabase_Constructor( mConn ) into mDatabase else put VDatabase_Constructor() into mDatabase end if get VDatabase_Open( mDatabase, "Database1" ) get ShowError() ...