Am Montag, den 02.06.2008, 09:19 -0400 schrieb Drew Jensen:
> David Warren wrote:
> > to change a long filter that syntax wise works with oo base macros.
> >  
> > I have managed to change a filter to run a report but oo Base has to 
> > have double quotes around file and field names and single quotes around 
> > variables (unlike straight sql).
> >  
> > This means that a long query can only be changed by adding something on 
> > the end or replacing a string in the middle. Is it at all possible to 
> > build up an sql query with select, from, where and order clauses as 
> > separate components that can be replaced in a macro and then 
> > concatenated together.
> >  
> > Thanks again for your patience but I need need to create sql 
> > commands dynamically to update the database as well as filter reports, 
> > forms and queries.
> >  
> > David
> >  
> 
> The answer is yes.

Hi David and Drew,

I had that problem once and Frank kindly pointed me to another Service.
The solution looks like this:

sub quoteSQL
        oDataSource = createUnoService( _
                "com.sun.star.sdb.DatabaseContext" ).getByName( "test j" )
        oConnection = oDataSource.getConnection( "marc", "*******" )
        oCmp = oConnection.createQueryComposer()
        oCmp.setQuery("SELECT A, B FROM TestTab WHERE ((A=15021) OR (C=1,2))")
        msgbox oCmp.getComposedQuery()

        oConnection.close()

end sub

Btw., the rule of single and double quotes does not always hold true,
but it is a property of the underlying database in use. You can fetch
that information from the metadata somewhere.

This dates back to 1.1.3 as many macro code I wrote, but since the API
is as stable as possible it should do nowadays.

Have fun,
Marc



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to