Database Guide : GLORP Tutorial : Simplest Possible GLORP Example
Simplest Possible GLORP Example
It is possible in GLORP to send an SQL statement to the database. If this all you wish to do there is no point in using GLORP, just use the database drivers for your database. The following example is useful to determine if GLORP can talk to the database. If you are not using ODBC then you need to change the connectString and the SQL set to the database. The connectString is the connect string used by the database driver for your database. For ODBC the connection string has the name of the ODBC driver data source. The SQL string needs to be something that you know will work on your database. For example, in Oracle:
login := Login new
database: OracleODBCPlatform new;
username: 'taylor';
password: 'foo';
connectString: 'orcl';
yourself.
Once VA Smalltalk has the needed information it can log on to the database.
accessor := DatabaseAccessor forLogin: login.
accessor login.
Once we are logged on we can use an accessor to execute SQL statements.
result := accessor basicExecuteSQLString: 'select 1 + 1 from dual'.
result next first.
This statement ends the connection to the database:
accessor logout.
The equivalent code in DB2 would be:
login := Login new
database: DB2Platform new;
username: 'taylor';
password: 'foo';
connectString: 'sample';
yourself
result := accessor basicExecuteSQLString: 'select 1+1 from sysibm.sysdummy1'.
result next first
The connection is terminated in the same fashion:
accessor logout.
 
Last modified date: 01/29/2015