[Solved] No Data Available

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
rharrex
Posts: 2
Joined: Mon Dec 12, 2016 12:43 pm

[Solved] No Data Available

Post by rharrex »

Hi I get an error message suggesting there is "no data is available" from this line in the script: ocell.String = oColumn.getString()
Can anyone see any thing wrong in the code?

I have since narrowed it down to the while loop?

The error code is:

Code: Select all

com.sun.star.uno.ExceptionNo data is available (Error during invoking function main in module file:///C:/Program%20Files/LibreOffice%205/share/Scripts/python/Test_1220_13122016.py (<class 'ooo_script_framework.com.sun.star.sdbc.SQLException'>: No data is available
  C:\Program Files\LibreOffice 5\share\Scripts\python\Test_1220_13122016.py:121 in function subLoadSheet() [ocell.String = oColumn.getString()]
  C:\Program Files\LibreOffice 5\share\Scripts\python\Test_1220_13122016.py:26 in function main() [subLoadSheet(rowSet)]
  C:\Program Files\LibreOffice 5\program\pythonscript.py:870 in function invoke() [ret = self.func( *args )]
))

Code: Select all

import uno
import unohelper

from com.sun.star.awt.MessageBoxButtons import BUTTONS_OK, BUTTONS_OK_CANCEL, BUTTONS_YES_NO, BUTTONS_YES_NO_CANCEL, BUTTONS_ABORT_IGNORE_RETRY
from com.sun.star.awt.MessageBoxButtons import  DEFAULT_BUTTON_OK, DEFAULT_BUTTON_CANCEL, DEFAULT_BUTTON_RETRY, DEFAULT_BUTTON_YES, DEFAULT_BUTTON_NO, DEFAULT_BUTTON_IGNORE

from com.sun.star.awt.MessageBoxType import  MESSAGEBOX, INFOBOX, WARNINGBOX, ERRORBOX, QUERYBOX
from com.sun.star.sdb.CommandType import COMMAND

sDBURL = "file:///E:/Estimator.odb"
sRegName = "Estimator"
sUser = ""
sPassword = ""

doc = XSCRIPTCONTEXT.getDocument()
parentwin =  doc.CurrentController.Frame.ContainerWindow
    
def main():
    #Mri_test()
    desktop = XSCRIPTCONTEXT.getDesktop()
    model = desktop.getCurrentComponent

    #print(MsgBox.show("A small message",0,"Dialog title"))
    oDBConn = connToDataBase(sDBURL, sRegName, sUser, sPassword)
    rowSet = getRowSet(oDBConn)
    subLoadSheet(rowSet)
    disConnFromDataBase(oDBConn)

    
def TestMessageBox():
    doc = XSCRIPTCONTEXT.getDocument()
    parentwin =  doc.CurrentController.Frame.ContainerWindow

    s = "This a message"
    t = "Title of of the box"
    #res = MessageBox(parentwin, s, t, INFOBOX, BUTTONS_YES_NO_CANCEL + DEFAULT_BUTTON_NO)
    #s = res
    #MessageBox(parentwin,s, t, "infobox")
    MessageBox(parentwin, t, s, INFOBOX, BUTTONS_YES_NO_CANCEL + DEFAULT_BUTTON_NO)
    
#---------------------------------------------------------------------------subLoadSheet(iRowSet)
#   Function Name:	    MessageBox
#   Description: 		    This function creates a user GUI information box
#   Parameters:        oParentWin
#                      sMsgTitle is a string containing title of message box
#                      sMsgText is a string containing the message text
#                      
#   Calls:	            None
#   Called From:       Main
#---------------------------------------------------------------------------
def MessageBox(oParentWin, sMsgTitle, sMsgText, oMessageType=MESSAGEBOX, oMsgButtons=BUTTONS_OK):
    serv = createUnoService("com.sun.star.awt.Toolkit")
    myBox = serv.createMessageBox(oParentWin, oMessageType, oMsgButtons, sMsgTitle, sMsgText)
    return myBox.execute()

def createUnoService(serviceName):
    # get the uno component context from the PyUNO runtime
    localContext = uno.getComponentContext()
    serviceManager = localContext.ServiceManager
    try:
        service = serviceManager.createInstanceWithContext(serviceName, localContext)
    except:
        service = NONE
    #print (serviceManager.getAvailableServiceNames)
    return service

#-------------------------------------------------------------------------subLoadSheet(iRowSet)
#   Function Name:	    connToDataBase
#   Description: 		    This function connects to a database
#   Parameters:        sDBURL As String is the database location,
#                      sRegName As String is the database registration name
#   Calls:	            None
#   Called From:       Main
#-------------------------------------------------------------------------
def connToDataBase(sDBURL, sRegName, sUser, sPassword):
    
    oDBContext = createUnoService("com.sun.star.sdb.DatabaseContext")
    oDataSource = oDBContext.getByName(sDBURL)
    if oDBContext.hasByName(sRegName) == False:
        oDBContext.registerObject(sRegName, oDataSource)
        oDBConn = oDataSource.getConnection(sUser,sPassword)
        MessageBox(parentwin, "t", "Success", INFOBOX, BUTTONS_YES_NO_CANCEL + DEFAULT_BUTTON_NO)
    else:
           oDBConn = oDataSource.getConnection(sUser,sPassword)
        
    return oDBConn


def getRowSet(oDBase):
    oRowSet = createUnoService("com.sun.star.sdb.ResultSet")
    oStatement = oDBase.createStatement()
    QueryDefinitions = oDBase.getQueries()
    QueryDefinition = QueryDefinitions.getByName("Query_Materials")
    sSQL= QueryDefinition.Command
    oRowSet = oStatement.executeQuery(sSQL)
    return oRowSet

def Mri_test():
    ctx = XSCRIPTCONTEXT.getComponentContext()
    document = XSCRIPTCONTEXT.getDocument()
    
    mri(ctx,document)
 
def mri(ctx, target):
    mri = ctx.ServiceManager.createInstanceWithContext("mytools.Mri",ctx)
    mri.inspect(target)

def subLoadSheet(iRowSet):
    oSheet = doc.Sheets.getByName("Materials_Sheet")
    oEnumerate = iRowSet.Columns.createEnumeration()
 	
    if  not iRowSet is None:
        i= 1    
        while iRowSet.next:
            for j in range (0, (iRowSet.Columns.Count-1)):
                oColumn = iRowSet.Columns.getByIndex(j)
                MessageBox(parentwin, "rowcount", str(iRowSet.Columns.Count-1), INFOBOX, BUTTONS_YES_NO_CANCEL + DEFAULT_BUTTON_NO)
                #MessageBox(parentwin, "i", i, INFOBOX, BUTTONS_YES_NO_CANCEL + DEFAULT_BUTTON_NO)
                ocell = oSheet.getCellByPosition(j,i)
                MessageBox(parentwin, "i", str(ocell), INFOBOX, BUTTONS_YES_NO_CANCEL + DEFAULT_BUTTON_NO)
                ocell.String = oColumn.getString()
            i = i + 1
        
    return






def disConnFromDataBase(oDBase):
    oDBase.close
    oDBase.dispose()
    return

g_exportedScripts = TestMessageBox, main
#if __name__ == '__main__':
  #main()
Last edited by rharrex on Fri Dec 16, 2016 4:41 am, edited 3 times in total.
OpenOffice4.1.2 on Windows 10
rharrex
Posts: 2
Joined: Mon Dec 12, 2016 12:43 pm

Re: No Data Available

Post by rharrex »

Hi Folks, I've solved this issue myself :D . Made a few fundamental mistakes in the def subLoadSheet(iRowSet) function. All working now as expected. (New to python programming!)

Code: Select all

def subLoadSheet(iRowSet):
    if not (iRowSet is None):
        oSheet = doc.Sheets.getByName("Materials_Sheet")
        i  = 0
        x = 0
        for x in range (0, (iRowSet.Columns.Count)):
            oColumn = iRowSet.Columns.getByIndex(x)
            ocell = oSheet.getCellByPosition(x,i)
            ocell.String = oColumn.Name
        i = 1
        while  iRowSet.next():
            for j in range (0, (iRowSet.Columns.Count)):
                oColumn = iRowSet.Columns.getByIndex(j)
                ocell = oSheet.getCellByPosition(j,i)
                ocell.String = oColumn.getString()
            i = i + 1
    return
OpenOffice4.1.2 on Windows 10
Post Reply