Composite (User) type to OpenOffice

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Nikita_1234
Posts: 1
Joined: Wed Feb 01, 2017 9:49 am

Composite (User) type to OpenOffice

Post by Nikita_1234 »

Hello. In postgresql composite type

Code: Select all

Create type CompLaLaLa AS (
    Name character varying,
    Count numeric
);
Table:

Code: Select all

CREATE TABLE "LaLaLa" (
    "ID" serial NOT NULL,
    "Сomposition" CompLaLaLa[] NOT NULL,
    CONSTRAINT LaLaLa_pk PRIMARY KEY ("ID")
);
macro:

Code: Select all

sub main
     Dim db as Object
     db = connect_to_database("postgre")
     SelectPrixod(db,30)
     disconnect_from_database(db)
end sub

Sub SelectPrixod(dbName as Object,ID as integer)
     Dim pSql as String
     Dim i as Integer
     Dim oRowSet as Object
     Dim oResult as String
     oSql = " SELECT ""Composition"" FROM ""LaLaLa"" Where ""ID""=ID;"
     oRowSet = createUnoService("com.sun.star.sdb.RowSet")
     oRowSet.activeConnection = dbName 
     oRowSet.Command = oSql 
     oRowSet.execute 

     while oRowSet.Next 'бежим 
        oResult = oResult & capitalize (oRowSet.getString(1)) & " " & chr(13)
     wend
     msgbox oResult
End Sub

Function capitalize (iName as String) as String
     Dim wordStart as String
     Dim wordEnd as String
     wordStart = UCase (Mid (iName, 1, 1))
     wordEnd = LCase (Mid (iName, 2))
     capitalize = wordStart & wordEnd
End Function

Function connect_to_database (dbName as String) as Object
     Dim dbContext As Object
     Dim oDataSource As Object
     dbContext = createUnoService("com.sun.star.sdb.DatabaseContext")
     oDataSource = dbContext.getByName(dbName)
     connect_to_database = oDataSource.GetConnection("admin", "Oma") 
End Function

Sub disconnect_from_database (db as Object)
     db.close
     db.dispose()
End Sub
It displays the empty cells. If to_json ( "Somposition"), simply type Object displays. How to count in this type of OpenOffice?
open office-4.1.3 windows 7
Post Reply