Working with MySql has two advantages over Oracle and Microsoft Access.
- In MySQL you can use excactly the same SQL syntax on SGIs and Windows PCs. Consequently, Beta users do not have to change their source code when porting programs from one platform to another.
- Using MySQL it is quite easy to move data between databases on different platforms. There is no easy way to do this when working with MS Access or Oracle.
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 |
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))); |
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. |
To utilize the MySQL interface in Beta you must do two things:
- The Beta program must have its ORIGIN set to
'~beta/betadbc/betadbc-mysql'
- After using connection.open you must select the database by using
connection.select_db
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.
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 |
Decimal | integerObject |
Tiny | charObject |
Short | integerObject |
Long | integerObject |
Float | realObject |
Double | realObject |
VarString | text |
String | text |
Null | Unsupported type |
Timestamp | Unsupported type |
Longlong | text |
Int24 | Unsupported type |
Date | time |
DateTime | Unsupported type |
Year | Unsupported type |
NewDate | Unsupported type |
Enum | Unsupported type |
Set | Unsupported type |
TinyBLOB | Unsupported type |
MediumBLOB | Unsupported type |
LongBLOB | Unsupported type |
BLOB | Unsupported type |
The BetaDBC Library - Reference Manual and Tutorial |
© 1999-2002 Mjølner Informatics |
[Modified: Tuesday November 14th 2000 at 16:48]
|