Apache OpenOffice (AOO) Bugzilla – Issue 69979
Dispose locks database (bug or feature)
Last modified: 2013-08-07 15:45:17 UTC
The following script can only be run once. After that the it crashes on oDbContext.hasByName(sDbName), and the "data source" windows is unaccesseble. After restarting OOo, the script can be run (once) again. Tried on Linux and Windows, with same result. Removing the line: oDbContext.dispose() fixes the problem REM ***** BASIC ***** Option Explicit Sub Main DbTest("/home/knobo/csv/", "foo", "foo") End Sub Function DbTest(sDbDir ,sCsvFile, sDbName) As Boolean On Error Goto ErrorHandler Dim oDbContext As Object Dim oDbInstance As Object Dim mDbProp(6) oDbContext = CreateUnoService("com.sun.star.sdb.DatabaseContext") If oDbContext.hasByName(sDbName) Then oDbContext.revokeObject(sDbName) End If oDbInstance = oDbContext.createInstance () oDbInstance.DatabaseDocument.storeAsURL( convertToURL( sDbDir + sDbName + ".odb" ), Array()) oDbInstance.URL = "sdbc:flat:" + convertToURL( sDbDir ) mDbProp(0) = MakePropertyValue( "Charset", "iso-8859-1" ) mDbProp(1) = MakePropertyValue( "DecimalDelimiter", "," ) mDbProp(2) = MakePropertyValue( "FieldDelimiter", Chr(9) ) ' => \t mDbProp(3) = MakePropertyValue( "Extension", "csv" ) mDbProp(4) = MakePropertyValue( "HeaderLine", True ) mDbProp(5) = MakePropertyValue( "StringDelimiter", """" ) ' => " mDbProp(6) = MakePropertyValue( "ThousandDelimiter", "" ) Dim oDbConnection As Object oDbInstance.Info = mDbProp oDbContext.registerObject( sDbName, oDbInstance ) oDbConnection = oDbInstance.getConnection( "", "" ) REM REM Do some funny db functions here REM CleanUp: On Error Resume Next if not isNull (oDbConnection) Then oDbConnection.close() oDbConnection.dispose() End If if Not IsNull (oDbInstance) Then oDbInstance.DatabaseDocument.close (True) oDbInstance.dispose() End If oDbContext.revokeObject(sDbName) oDbContext.dispose() 'Remove me? Exit Function ErrorHandler: MsgBox "DbTest error [line: " + Erl + "] error [" + Err + "]: " + Error$ Goto Cleanup End Function Function MakePropertyValue( Optional cName As String, Optional uValue ) As com.sun.star.beans.PropertyValue Dim oPropertyValue As New com.sun.star.beans.PropertyValue If Not IsMissing( cName ) Then oPropertyValue.Name = cName EndIf If Not IsMissing( uValue ) Then oPropertyValue.Value = uValue EndIf MakePropertyValue() = oPropertyValue End Function
change owner
What is the status on this?
clu->msc:may you have a look on this?
knobo, I have tried running your script via Tools - Macros - Run and got "wrong number of parameters" error message. Please atach sample file to this issue.
It is a bug but the questions is - in your script or that fact that Basic can dispose of it. The Developers Guide, Chapter 13, clearly states that: "The database context is a container for data sources. It is a singleton, that is, it may exist only once in a running OpenOffice.org API instance and can be accessed by creating it at the global service manager of the office." So, you should not dispose of it. Whether Basic should be allowed to do so is another question. I tried your script and yes it does just what you say - OOo must be restarted after the call to oDbContext.dispose() in order to work with any datasource, not just run your script a second time. After the call to dispose if a Base file is opened, for example, an attempt to create a connection to it simply fails - quietly. No error message is displayed to the user. I tested this under OOo 2.2 stable on WinXP. Perhaps someone on the API team, or the team responsible for the Basic script engine, should look at this and make the call. My personal opinion is that this is not a bug, as if the script programmer disposes of the context object then that is a bug in the script.
> My personal opinion is that this is not a bug, as if the script > programmer disposes of the context object then that is a bug in the > script. Seconded. Disposing an object which you're not the owner of is a no-go, and can lead to a variety of undesired results (note that quietly doing nothing is one of the more gently reactions). The Basic runtime itself is unable to determine whether certain actions on certain objects are allowed, that's conceptually pretty impossible. Doing the right thing here is the task of the programmer. Side note: If such a wrong API usage would result in OOo crashing, I would accept this as a bug. A crashing OOo is unacceptable. However, a not-running macro after doing something wrong is, well, only a not-running macro.
The Issue you raised has been marked as 'Resolved' and not updated within the last 1 year+. I am therefore setting this issue to 'Verified' as the first step towards Closing it. If you feel this is incorrect, please re-open the issue and add any comments. Many thanks, Andrew Cleaning-up and Closing old Issues ~ The Grand Bug Squash, pre v3 ~ http://marketing.openoffice.org/3.0/announcementbeta.html
As per previous posting: Verified -> Closed. A Closed Issue is a Happy Issue (TM). Regards, Andrew