| View previous topic :: View next topic |
| Author |
Message |
oodev Newbie

Joined: 07 Oct 2006 Posts: 4
|
Posted: Mon Oct 09, 2006 1:55 pm Post subject: Table not found in statement ? |
|
|
Hi,
I've a very simple SQL statement, that can be executed as a query in the OO Base IDE (2.0.3) but not in a macro.
To get sure that the table exists I print all tablenames.
But the same table name('mytab') in my sql statement fails.
Can anyone help?
| Code: |
Sub Main
Const sDBBaseName$ = "MyOODB"
Dim ctx As Object
Dim ds As Object
Dim con As Object
Dim stmnt As Object
Dim rs As Object
Dim sql As String
Dim txt As String
sql = "SELECT * FROM mytab"
ctx = CreateUnoService("com.sun.star.sdb.DatabaseContext")
ds = ctx.getByName(sDBBaseName$)
con = ds.getConnection("", "")
oTables = con.getTables()
For iCount = 0 To oTables.Count - 1
txt = txt + " " + oTables.ElementNames(iCount)
Next iCount
Print txt
stmnt = con.createStatement()
rs = stmnt.executeQuery(sql)
'SQLException
'Message:Table not found in statement [SELECT * FROM mytab]
If Not isNull(rs) Then
txt = ""
While rs.next()
txt = txt + " " + rs.getString(1)
Wend
Else
MsgBox("rs is null")
End If
con.close()
End Sub |
|
|
| Back to top |
|
 |
DrewJensen Super User


Joined: 06 Jul 2005 Posts: 2616 Location: Cumberland, MD
|
Posted: Mon Oct 09, 2006 3:53 pm Post subject: |
|
|
The problem is quoting.
The rule for HSQLDB, as used in Base's embedded database model.
If column names or table names are not ALL CAPITAL they must be double quoted.
sql = "SELECT * FROM ""mytab""" |
|
| Back to top |
|
 |
oodev Newbie

Joined: 07 Oct 2006 Posts: 4
|
Posted: Tue Oct 10, 2006 1:24 pm Post subject: |
|
|
just thanx, thanx, thanx
A little bit strange, but ok I'll get used to it |
|
| Back to top |
|
 |
|