Hello
I have a very strange issue when trying to get a rowset from postgresql in different ways:
1:
Dim pgCon as Object
Sub Main
makePGConnection
sql = "SELECT ""id"", ""url"" FROM ""journeycache"".""urls"" ""urls"" ORDER BY ""id"" desc"
rem this fails
rs1 = getRowSetForward(pgCon, sql)
closeDbObject(rs1)
closeDbObject(locCon)
End Sub
sub makePGConnection()
Dim sURL$
Dim myDict As Variant
Dim oParms As Variant
sURL$ ="sdbc:postgresql:host=localhost port=5412 dbname=postgres user=postgres password=postgres"
pgCon = connectionManager(sURL)
End Sub
Function connectionManager(sURL As String) As Object
Dim oManager As object
oManager = CreateUnoService("com.sun.star.sdbc.DriverManager")
connectionManager= oManager.getConnection(sURL)
End Function
public Function getRowSetForward(con As object,sql As String) As Object
set getRowSetForward = initiateRowSet(con,sql)
makeRowSetType getRowSetForward,com.sun.star.sdbc.ResultSetType.FORWARD_ONLY,com.sun.star.sdbc.ResultSetConcurrency.READ_ONLY
End Function
Function initiateRowSet(con As object,sql As String) As Object
set initiateRowSet= CreateUNOService("com.sun.star.sdb.RowSet")
With initiateRowSet
.activeconnection = con
.CommandType = com.sun.star.sdb.CommandType.COMMAND
.Command =sql
End with
End Function
Public sub makeRowSetType(rs As Object,rsType As integer,rsConcurreny As Integer)
Dim exc As Variant
rs.ResultSetType= rsType
rs.ResultSetConcurrency=rsConcurreny
rs.execute()
End sub
The result is:
However when making a connection to base file which connects to postgres like this:
Dim pgCon as Object
Sub Main
openLocal(converttourl("e:\Documents\LOCALHOST.odb"))
sql = "SELECT ""id"", ""url"" FROM ""journeycache"".""urls"" ""urls"" ORDER BY ""id"" desc"
rs2 = getRowSetForward(pgCon, sql)
closeDbObject(rs2)
closeDbObject(locCon)
End Sub
Public Sub openLocal(db$)
pgCon= getFBConnection(db)
End Sub
Private Function getFBConnection(context$)
Dim DatabaseContext As Object
DatabaseContext = createUnoService("com.sun.star.sdb.DatabaseContext")
DataSource = DatabaseContext.getByName(context)
getFBConnection= DataSource.getConnection("","")
End Function
public Function getRowSetForward(con As object,sql As String) As Object
set getRowSetForward = initiateRowSet(con,sql)
makeRowSetType getRowSetForward,com.sun.star.sdbc.ResultSetType.FORWARD_ONLY,com.sun.star.sdbc.ResultSetConcurrency.READ_ONLY
End Function
Function initiateRowSet(con As object,sql As String) As Object
set initiateRowSet= CreateUNOService("com.sun.star.sdb.RowSet")
With initiateRowSet
.activeconnection = con
.CommandType = com.sun.star.sdb.CommandType.COMMAND
.Command =sql
End with
End Function
Public sub makeRowSetType(rs As Object,rsType As integer,rsConcurreny As Integer)
Dim exc As Variant
rs.ResultSetType= rsType
rs.ResultSetConcurrency=rsConcurreny
rs.execute()
End sub
The connection setting for e:\Documents\LOCALHOST.odb
is
host=localhost port=5412 dbname=postgres user=postgres password=postgres
The result of this test is that the sdb.Rowset is created successfully with no errors.
Current setting is
Version: 7.6.6.3 (X86_64) / LibreOffice Community
Build ID: d97b2716a9a4a2ce1391dee1765565ea469b0ae7
CPU threads: 4; OS: Windows 10.0 Build 19045; UI render: Skia/Raster; VCL: win
Locale: en-GB (en_US); UI: en-US
Calc: CL threaded
What could be the issue? Thank you.