database access Tom Schindl How do I query a database in OpenOffice using StarBASIC?

Fairly simple check this out. You'll have to register an DataSource named "my_resource" using Tools -> Datasources.

Sub executeSQLOne Dim RowSet ' Create a row-set to query the database RowSet = createUnoService("com.sun.star.sdb.RowSet") RowSet.DataSourceName = "my_resource" RowSet.CommandType = com.sun.star.sdb.CommandType.COMMAND RowSet.Command = "SELECT max(m_id) FROM member WHERE delmark = 0" RowSet.execute() ' it only returns 1 row ' so we need no loop RowSet.next() MsgBoxg "The MaxId is " + rowSet.getString(1) End Sub Sub executeSQLMore ' Create a row-set to query the database RowSet = createUnoService("com.sun.star.sdb.RowSet") RowSet.DataSourceName = "my_resource" RowSet.CommandType = com.sun.star.sdb.CommandType.COMMAND RowSet.Command = "SELECT m_id, m_surname FROM member WHERE delmark = 0" RowSet.execute() ' loop through the resultset until no record is left while RowSet.next() MsgBoxg "The Person " + rowSet.getString(2) + " has the ID " + rowSet.getString(1); wend End Sub
Initial version