Search code examples
libreoffice-basic

Make pre-prepared sql command in libreoffice basic


I'm trying to make a prepared query based on the value in a field in my form in libreoffice basic.For this, I created a macro. But it returns an error on the query line saying

BASIC syntax error. Unexpected symbol: oInstruction_SQL

Sub concatMotherName

Dim oSourceDonnees As Object
Dim oConnexion As Object
Dim stSql As String
Dim oResultat As Object

oSourceDonnees = thisComponent.Parent.dataSource
oConnexion = oSourceDonnees.getConnection("","")
oInstruction_SQL = oConnexion.createStatement()
Dim valueData As String
Dim dateLabel As String

valueData = ThisComponent.Drawpage.Forms.getByName("Form").getByName("id_mother_label").getCurrentValue()
stSql = "SELECT NOM_MERE FROM ""T_MOTHER"" WHERE ""NUM_MOTHER"" = ?" _
oInstruction_SQL = = oConnection.prepareStatement(stSql)
oInstruction_SQL.setString(1, valueData)
oResultat = oInstruction_SQL.executeQuery(stSql)
If Not IsNull(oResultat) Then
   oResultat.Next()
   MsgBox oResultat.getString(1)
End If
End Sub

Solution

  • There are two syntax problems. The first is the _ after the query string, which indicates that the next line is a continuation of that one. It's not a continuation, so remove it.

    The second error is on the next line: = =.

    When these errors are fixed, the code compiles successfully.