在 libreoffice basic 中制作预先准备好的 sql 命令

问题描述

我正在尝试根据 libreoffice basic 表单中字段中的值进行准备查询。为此,我创建了一个宏。 但是它在查询行上返回一个错误

基本语法错误。 意外符号: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

解决方法

有两个语法问题。第一个是查询字符串后的 _,表示下一行是该行的延续。这不是一个延续,所以删除它。

第二个错误在下一行:= =

修复这些错误后,代码将成功编译。