[Gambas-devel] Cijo needs a little help

Ron Onstenk ronstk at ...124...
Tue Jun 27 19:03:20 CEST 2006


On Monday 26 June 2006 06:58, Cijo Jose wrote:
> hello ,
> 
> im using Debian Linux 3.1
> 
> is anyone help to show how can i connect Gambas with mysql ?
> 
> please expect ur help
> 
> bye bye
> 
> Cijo
> 

A very drastic way but gives all the information you need
is the source code of the gambas-database-manager.

However it is not always easy to understand how things are
coupled together.
Simple by cleanup the code if your project is ready, using new 
subroutines to make common parts more easy usable in the project.
Therefore you have to look in many files and mostly open several
as reminder during reading the main file.
(that's for me the reason to have Fabians workspace)
But for almost every question you can find (not always easy) some code.
Really it is good and works perfect with gambas.
I'm still learning (slowly) every time from it and not only DB 
usage but some programming tips for my project to.
A tip for finding. Mark the word you want a sample for.
Click the binocular and check in "Options" the "Search List" and
in "Search In" the "Project"
You will get a nice list where that particular word is used.
The only bad thing is not know the good word. :)


So what do you want?
A MySQL database for some storage.

What do you need for it.?
A _running_ MySQL server (really someforget this)

Some help documentaion.

How to connect to the database?
Use in gambas the Connection object. 
Find Help for "Connection.Open (gb.db)" 
	at http://gambasdoc.org/help/comp/gb.db/connection/open 
(You could find this example in above link)

  DIM $hConn As NEW Connection

  WITH $hConn
     .Type = "postgresql"
     .Host = "localhost"
     .Login = "username"
     .Password = "passwd"
     .Name = "testdb"
  END WITH

  TRY $hConn.Open
  IF Error THEN PRINT "Cannot Open Database. Error = "; Error.Text

Now you should be able to use 2 ways.
The safe way or the advanced way.
Your choice should be the "safe" way for now.

----
For the safe way
Find Help for "gb.db - Database access component" 
	at http://gambasdoc.org/help/comp/gb.db 

Using the DB component will prevent you to make the most common mistakes
that beginners make. 
It also is a common method to several database engines that living in the *nix world.
Changing at a later stage to a different engine is easy to do.

----
The advanced way is using the Connection object and you are
responsible for correct formulated queries for one of the engines.
Change of engine will/can require rewrite of the SQL requests.


I hope this will give some start of help

Ron

----
PS
Note why I speak about "Engines".

Not every database system is server based as MySQL, MSQL or Postgresql.
SQlite is a simple file based system 
CVS files, XML files and Excel Sheets are other sources for data storage.

All they need programs to handle request and give results.
That is 1 or more program(s), other times complete network based systems.
That is the driver package and in running condition is what I call "Engine"

Unix-ODBC or MS-ODBC are packages with methods to reach those engines.
They are not databases or servers on there own, they provide a common 
interface to those Engines.

For gambas the DB component provides the same common interface to the
Engines or to the common interface ODBC (when ready).

So by using the DB component you are as programmer of the project 
responsible for the correct choice and maintaining of the "Engine". 

Using *-ODBC will transfer this to the user of the program.

This to give a impression, not the real trough.

Ron














More information about the Devel mailing list