# How to make a ResultSet Read/Write

I have a DRAW document and BASE document. The BASE document has tables that contain data which relates to different shapes in the DRAW document.

I have written a macro that will display data related to a selected shape and display it in a Dialog.

Clicking the "Cancel button on the Dialog causes it to close, so all good up to that point.

I want to be able to edit the TextBoxes on the Dialog and then click the OK button to save the updated data back to the BASE document but when I try to do this I get an error message that the "Result Set is Read Only".

I've used MRI to examine the Connection to determine that it is Read/Write, but do not see a Read Only property for the Result Set.

I have manually tested the SQL statement in the BASE GUI and I can update the fields that way, so I think my SQL is OK.

The OOo BASIC Guide tells me there is a ResultSetConcurrency Variant that controls whether the Result Set can be modified (but doesn't go so far as to explain how to modify it). Using MRI I can see that ResultSetConcurrency is a number which is ReadOnly. I'm guessing that I need to set this value to something else, somehow, as part of the ExecuteQuery method. Half a day of looking through various documents and forums has not enlightened me :(

I've attached my Macro(s) that relate to the problem I'm stuck at, so perhaps someone can point me in the right direction (please!)
BTW - these macros are still in very early development, so maybe there is some fundamental flaw here somewhere.

Option Explicit

Global FibreDoc As Object
Global Connection As Object
Global DataSource As Object
Global DatabaseContext As Object
Global bPitSaveFlag as Boolean
Global oPitDialog as Object

Sub SetDefaults

Dim InteractionHandler as Object

FibreDoc = ThisComponent
DatabaseContext = createUnoService("com.sun.star.sdb.DatabaseContext")
DataSource = DatabaseContext.getByName("Fibre-data")

Connection = DataSource.GetConnection("","")
Else
InteractionHandler = createUnoService("com.sun.star.sdb.InteractionHandler")
Connection = DataSource.ConnectWithCompletion(InteractionHandler)
End If
'mri(Connection)
End Sub

Sub ShowPitDialog
Dim oCurrentSelection As Variant
Dim oPit As Variant
Dim sPitName as String
Dim iNameLength as Integer
Dim iSepPos as Integer
Dim iPitID as Integer
Dim sPitSQL as String
Dim sTypeSQL as String
Dim oPitStatement as Object
Dim oTypeStatement as Object
Dim oResultSet as Object
Dim oTypeResult as Object
Dim oTypeList as Object
Dim sTitle as String
Dim iCount as Integer

End If

bPitSaveFlag = False 'Indicator to save updated data

'mri(Connection)

oCurrentSelection = FibreDoc.getCurrentSelection()
oPit = oCurrentSelection.getByIndex(0)
sPitName = oPit.Name  'The name of the object that is selected
iNameLength = len(sPitName)
iSepPos = InStr(sPitName,":")  'Location of the separating ":" in the name
iPitID = Right(sPitName,(iNameLength-iSepPos)) 'The number to the right of the separating ":"

sPitSQL = "SELECT ""ID"", ""Lat"", ""Long"", ""Type"", ""Comments"" FROM ...
edit retag close merge delete

Sort by » oldest newest most voted

Hello,

When using executeQuery you are reading. With 'executeUpdate you are writing.

So you have at least two choices. In the first, have two connections for statements. See this post -> How to scroll through a table in base

That same post has a link to -> firebird equivalent for resultset.last which uses a RowSet to do what you want. Tested with this code:

Dim oRS as Object
oRS = createUnoService("com.sun.star.sdb.RowSet")
oRS.DataSourceName = ThisComponent.Location
oRS.CommandType = com.sun.star.sdb.CommandType.COMMAND
oRS.Command = sPitSQL
oRS.Execute
oRS.First
oRS.updateRow()
`

There is a lot to cover with this situation. The first link above contains many other links which are most helpful in covering this topic in more detail.

and also for CommandType in RowSet -> https://www.openoffice.org/api/docs/c...

NOTE: This was tested with HSQLDB v1.8 embedded database. You have not specified what DB you are using.

more