OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

sql statement with where won't execute

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
willie2
General User
General User


Joined: 29 Apr 2005
Posts: 9

PostPosted: Wed Sep 30, 2009 10:36 am    Post subject: sql statement with where won't execute Reply with quote

I have quite a strange problem with a sql statement in a macro. With OOo 2.1 everything is fine. But since i updated to OOo 2.4 i can't execute sql statements with a "where" inside.

Example:

oResultSet = oStatement.executeQuery("SELECT LV FROM LV WHERE Project = ""test"";")
in OOo 2.1 no problem, but with OOo 2.4 an error

the same with:

oResultSet = oStatement.executeQuery("SELECT `" & fieldName & "` FROM `" & table & "` WHERE (`Project` = """ & InProject & """);")

There must be some problem with the expression after the ... WHERE Project . I tried all sorts or "arrangements" of quotations etc, but no success. If i use:

oResultSet = oStatement.executeQuery("SELECT LV FROM LV WHERE Project ;")
there is no error, but of course not the wanted result.

Any suggestions are appreciated ...
Back to top
View user's profile Send private message
thom314
OOo Enthusiast
OOo Enthusiast


Joined: 03 Aug 2005
Posts: 186
Location: Denver, Colorado

PostPosted: Sun Oct 11, 2009 7:31 pm    Post subject: Reply with quote

I don't have time to test this but I think you need double quotes around:the table and column names and single quotes around strings, as in:

"SELECT ""title"" FROM ""books"" WHERE ""author"" = 'betty'"
_________________
- Tom on Linux Mint
Back to top
View user's profile Send private message
willie2
General User
General User


Joined: 29 Apr 2005
Posts: 9

PostPosted: Sun Oct 11, 2009 10:49 pm    Post subject: Reply with quote

Thanks a lot, first part solved ...

oResultSet = oStatement.executeQuery("SELECT ""LV"" FROM ""LV"" WHERE ""Project"" = 'test';")

works! But how to set Quotations with variables

... WHERE (""Project"" = Quotations? & InProject & Quotations?);")

I tried many different variants but no success. Perhaps you can help me once again ...
Back to top
View user's profile Send private message
RPG
Super User
Super User


Joined: 24 Apr 2008
Posts: 2696
Location: Apeldoorn, Netherland

PostPosted: Mon Oct 12, 2009 1:24 am    Post subject: Reply with quote

Hello

Variabelen in a SQL statement must be surround with double quotes.

Basic and SQL don't see each other.

Conclusion use enough double quotes.

Romke
Back to top
View user's profile Send private message
thom314
OOo Enthusiast
OOo Enthusiast


Joined: 03 Aug 2005
Posts: 186
Location: Denver, Colorado

PostPosted: Mon Oct 12, 2009 1:50 pm    Post subject: Reply with quote

Perhaps I misunderstand your question but:
Code:
"SELECT ""LV"" FROM ""LV"" WHERE ""Project"" = 'test';"

is the same as
Code:
InProject = "test"
"SELECT ""LV"" FROM ""LV"" WHERE ""Project"" = '" & InProject & "';"

By the way, I don't believe you need the semi-colon
_________________
- Tom on Linux Mint
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group