The Free and Open Productivity Suite
Released: Apache OpenOffice 4.1.15

Read/Write access rights (privileges) for JDBC/ODBC data sources

Note: The below information is outdated, it applies only to versions prior to 2.0.

The Problem

When working with drivers which not fully support the access to the privileges of  the database or returning just incorect information, only allows the operations which the driver returns. E.g. when the driver doesn't return the right to insert values into a table even when the database allows it, also shows the table in read only mode.

The Solution

The JDBC/ODBC-SDBC bridge (more sloppy: OOo's JDBC/ODBC driver) supports to work around the problem in just to return that all rigths are granted, the sytem driver won't be asked in that case.

Read/Write access rights can be enabled on a per-data-source basis. For this, the "Info" property of a data source should contain a name-value-pair with
Name: IgnoreDriverPrivileges
Value: TRUE

Unfortunately, there is no user interface, yet, for doing so. You could use the Basic macro provided below, which adds the setting for a data source of your choice.

The Macro

The following macro enables Read/Write access rights for a data source of your choice. You can also download this macro in the downloads section.

REM  *****  BASIC  *****

Option Explicit

Sub Main
    Dim sDataSourceName as String
    sDataSourceName = InputBox( "Please enter the name of the data source:" )
(sDataSourceName )
End Sub

IgnoreDriverPrivileges(sDataSourceName as String )
    ' the data source context (ehm - the service name is historical :)
    Dim aContext as Object
    aContext = createUnoService( "" )

    If ( Not aContext.hasByName( sDataSourceName ) ) Then
        MsgBox "There is no data source named " + sDataSourceName + "!"
        Exit Sub
    End If

    ' the data source
    Dim aDataSource as Object
    aDataSource = aContext.getByName( sDataSourceName )

    ' append the new
    Dim bFlag as Boolean
    bFlag = TRUE
    Dim aInfo as Variant
    aInfo = aDataSource.Info
    aInfo = AddInfo( aInfo, "IgnoreDriverPrivileges", bFlag )

    ' and write back
    aDataSource.Info = aInfo
    ' flush (not really necessary, but to be on the safe side :)
End Sub

Function AddInfo( aOldInfo() as new,sSettingsName as String, aSettingsValue as Variant ) as Variant
    Dim nLower as Integer
    Dim nUpper as Integer
    nLower = LBound( aOldInfo() )
    nUpper = UBound( aOldInfo() )

    ' look if the setting is already present
    Dim bNeedAdd as Boolean
    bNeedAdd = TRUE

    Dim i As Integer
    For i = nLower To nUpper
        If ( aOldInfo( i ).Name = sSettingsName ) Then
            aOldInfo( i ).Value = aSettingsValue
            bNeedAdd = FALSE
        End If
    Next i

    ' allocate the new array
    Dim nNewSize as Integer
    nNewSize = ( nUpper - nLower )
    If bNeedAdd Then nNewSize = nNewSize + 1
    Dim aNewInfo( nNewSize ) as new

    ' copy the elements (a simply copy does not work in Basic)
    For i = nLower To nUpper
        aNewInfo( i ) = aOldInfo( i )
    Next i

    ' append the new setting, if necessary
    If ( bNeedAdd ) Then
        aNewInfo( nUpper + 1 ).Name = sSettingsName
        aNewInfo( nUpper + 1 ).Value = aSettingsValue
    End If

    AddInfo = aNewInfo()
End Function

Apache Software Foundation

Copyright & License | Privacy | Contact Us | Donate | Thanks

Apache, OpenOffice, and the seagull logo are registered trademarks of The Apache Software Foundation. The Apache feather logo is a trademark of The Apache Software Foundation. Other names appearing on the site may be trademarks of their respective owners.