Issue 69979 - Dispose locks database (bug or feature)
Summary: Dispose locks database (bug or feature)
Status: CLOSED NOT_AN_OOO_ISSUE
Alias: None
Product: Base
Classification: Application
Component: code (show other issues)
Version: OOo 2.0.4
Hardware: All All
: P4 Trivial (vote)
Target Milestone: ---
Assignee: marc.neumann
QA Contact: issues@dba
URL:
Keywords: needmoreinfo, oooqa
Depends on:
Blocks:
 
Reported: 2006-09-29 14:41 UTC by knobo
Modified: 2013-08-07 15:45 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description knobo 2006-09-29 14:41:40 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
Comment 1 christoph.lukasiak 2006-10-25 16:51:22 UTC
change owner
Comment 2 knobo 2007-01-26 20:44:13 UTC
What is the status on this?
Comment 3 christoph.lukasiak 2007-01-30 16:10:56 UTC
clu->msc:may you have a look on this?
Comment 4 kpalagin 2007-04-26 20:57:35 UTC
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.
Comment 5 drewjensen.inbox 2007-04-27 02:50:02 UTC
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. 

Comment 6 Frank Schönheit 2007-05-02 10:04:13 UTC
> 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.
Comment 7 ace_dent 2008-05-17 21:41:45 UTC
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
Comment 8 ace_dent 2008-05-17 23:46:23 UTC
As per previous posting: Verified -> Closed.
A Closed Issue is a Happy Issue (TM).

Regards,
Andrew