base de donnees, gambas 1, Tutoriels - GB1- Tutoriel sur les bases de donnees -

GB1- Tutoriel sur les bases de donnees

( Temps de lecture estimé à 4 min 18 sec )




Have you ever wanted to use Visual Basic on Linux? Why? Well, you could be like me and have spent many years programming in VB, but want to move to Linux without having to learn a new language. It could be that you 're brand new to programming and need something you can learn quickly and easily—and still be able to produce a good quality application.

Well, now you can—almost.

Gambas is short for Gambas is—almost—Basic, and it has been designed to look at the good things VB can do for Windows and then does them for Linux. Above all, Gambas is easy to use—as this article shows. I explain how to build a useful application in Gambas—a bug-tracking system that stores its information in a MySQL database.

Installation is as simple. First go to the Gambas Web site, and check the Distributions &amp OS page—this is just to make sure there are no known peculiarities with your flavour of Linux. Then, go to the Download page and get the most current, stable version (1.09 at the time of this writing). If you 've done this type of thing before, simply carry on and get yourself ready to use Gambas if not, don 't worry—we 're nearly there.

Open a terminal and move to the directory where you 've saved the bz2 file. If you 're going to use 1.09, it will be called gambas-1.0.9.tar.bz2. Now bunzip2 the file, and follow the installation instructions (unless the distribution page has given you some additional parameters for your distribution).

With that, you 're ready to use Gambas. Type gambas on the command line, and the welcome screen appears (Figure 1).
ex2-1.png
Figure 1. The Gambas Welcome Screen

The Gambas screen gives you access to example applications—you 'll find these very useful if you are new to programming. In this case, click on New Project. Gambas now displays its project creation wizard, so follow the instructions to create your first project. When asked create a graphical project, set the name to bugTracker (note that underscores are not allowed), and then set the title to Bug Tracker. You also will be asked where to store your project. I suggest you create a new directory called Gambas in your home directory and then use it for all future projects as well.

Next, we jump straight in to the creation of a new form. Right-click in the project window, select New and then Form. Gambas puts you into its form creation wizard. All you need to do now is give the form a name—call it frmBugTracker. (Don 't leave it as Form1. That 's very bad practice).

Now, you can start adding the elements to the form—and, the first one to add is a Close button. Why do this first? Quite simply, you always want to be able to close a form, or an application, for that matter, cleanly and easily, so get into this habit as quickly as possible. To create the button, click on its icon in the toolbox (the icon is a box with OK on it), and then use the left-mouse button to draw it onto the form. By default, the button is called Button1, but exactly like the form, we rename it. Click on the button, and press F4 to display the Properties box. Change its name to btnClose and its text to Close.

The button won 't do anything yet—we have to add some code to it, which is really, really easy. If you double-click on the button, Gambas takes you to the code window, and you 'll find an empty btnClose_Click subroutine. Modify it so that it says:

PUBLIC SUB btnClose_Click()

ME.Close

END
ex2-2.png
Figure 2. Designing a New Gambas Form

You should notice something as you type in the code—as soon as you put in the period, a drop-down menu appears, giving you all of the methods and parameters associated with the ME object—in this case, ME refers to the form, so ME.Close means close this form.

Suppose you want to see the results of your hard work now. Go to the Project window and click on the little green run button. And there you are—your first Gambas application. You even can close the form with your brand-new button.

Before building the application itself, we need to think about what we want the bug tracker to do. Then, we need to have a look at the data—how it is to be arranged, and what is going to be stored.

The bug tracker will have to do the following:

*

Have the details of new bugs entered.
*

Record who raised the bug.
*

Have a bug assigned to a programmer.
*

Update the status of the bug.
*

Record when the bug was raised.
*

Record the release for the bug fix.
*

Provide the ability to view new, working and complete bugs.

The data required is therefore:

*

Who raised the bug.
*

Who is fixing the bug.
*

Bug details.
*

Developer details: ID, first name, surname and user name.
*

Bug Details: ID, description, date created, ID of raiser, ID of developer, status, release number and application details.

From this, we can start building a database schema. Start by creating a file (such as database_schema.sql) that we will use to create the database:

/*
First you must create the database. The listing
table includes only the user ids for raised by
and coder .
*/
create database bugtracker

create table bugtracker.listing (
id int auto_increment primary key,
details longtext,
application_id int,
release float,
raised_by_id int,
coder_id int,
status_id int,
created datetime,
priority int,
status int);




Date de creation :
Redacteur : Rédigé par spheris
Classé dans : base de donnees, gambas 1, Tutoriels