7 MySQL interface tutorial

7.1 On MySQL

Working with MySql has two advantages over Oracle and Microsoft Access.

7.2 Downloading and installing MySQL

You can download MySQL at http://www.mysql.com

Installing MySQL on Windows is straightforward. However, to make MySQL work with Beta you must do the following after installing MySQL:
Copy the file
mysql\lib\opt\libmySQL.lib
into the directory
beta\lib\nti_gnu\ (if you use the GNU tools) or
beta\lib\nti_ms\ (if you use the Microsoft tools).
This is only necessary on Windows.

Installing MySQL on Unix is done as follows:
gunzip ...
tar -xvf ...
./scripts/mysql_install_db
./bin/safe_mysqld

7.3 Creating databases and users

The database is now up and running. By default it has only one user called 'root' whose password is empty. New users are created using eg. GRANT statements as follows:

Start MySQL as user 'root' on the database 'mysql':
./bin/mysql -u root mysql
Create a user called 'firstusr' whose password is 'firstpswd':
mysql> GRANT ALL PRIVILEGES ON *.* TO firstusr@localhost IDENTIFIED BY 'firstpswd' WITH GRANT OPTION;
mysql> GRANT ALL PRIVILEGES ON *.* TO firstusr@"%" IDENTIFIED BY 'firstpswd' WITH GRANT OPTION;
Additional users can be created in a similar fashion. Now create a database for the user 'firstusr':
./bin/mysqladmin -u firstusr -p create firstdb
This creates a database 'firstdb' after prompting for the password. The user 'firstusr' can now log on to the database 'firstdb':
./bin/mysql -u firstusr -p firstdb
Tables can now be created using standard SQL statements:
mysql> CREATE TABLE test (name CHAR(200) NOT NULL, KEY index_name (name(10)));

7.4 Moving data between servers

mysqldump is useful for moving data from one MySQL server to another:
./bin/mysqldump -u firstusr -p firstdb > firstdb.txt
firstdb.txt is now a text file containing SQL statements. These statements will construct the tables and data of firstdb on another MySQL server when used as follows:
./bin/mysql/mysql -u firstusr -p < firstdb.txt.

7.5 Communicating with MySQL from a Beta program:

To utilize the MySQL interface in Beta you must do two things: To illustrate these points here are 10 lines from the adhoc.bet demo program:
ORIGIN '~beta/betadbc/betadbc-mysql';
INCLUDE '~beta/basiclib/formatio'
        '~beta/basiclib/numberio' '~beta/basiclib/file';
-- program: Descriptor --
(#
   sqlCon: @Connection; stmt: @sqlCon.DirectSQLStatement;
   res: ^sqlCon.resultSet
do
   'hi there'->putline;
   (2->arguments,3->arguments,4->arguments)->sqlCon.open;
   'firstdb'->sqlCon.selectdb;
adhoc is then invoked as follows:
./adhoc vertigo firstusr firstpswd

Where vertigo is the host on which the MySQL server is running. It is possible to use 'localhost'.

Please note that shared variables is currently not possible when using the MySQL interface. Suggested workaround: build your SQL statement dynamically using append or putformat.

7.6 Types in MySQL and Beta

The following table shows the possible types of data in MySQL, and the type to which they are mapped in Beta:

MySQL type
Beta type
DecimalintegerObject
TinycharObject
ShortintegerObject
LongintegerObject
FloatrealObject
DoublerealObject
VarStringtext
Stringtext
NullUnsupported type
TimestampUnsupported type
Longlongtext
Int24Unsupported type
Datetime
DateTimeUnsupported type
YearUnsupported type
NewDateUnsupported type
EnumUnsupported type
SetUnsupported type
TinyBLOBUnsupported type
MediumBLOBUnsupported type
LongBLOBUnsupported type
BLOBUnsupported type


The BetaDBC Library - Reference Manual and Tutorial
© 1999-2002 Mjølner Informatics
[Modified: Tuesday November 14th 2000 at 16:48]