Using macros to dynamically change a query definition

Hello!
My name is Stuart Simon. I am an active LibreOffice user and an experienced SQL programmer. However, I am just learning Java and am relatively new to LibreOffice macros. I have read through parts of OpenOffice.org’s documentation and am still confused about what everything means for the user who is not experienced with macros. I have a database registered to LibreOffice under the name of “ArchiveMusic” and a query inside said database named “CSVExport” whose SQL definition string I would like to change dynamically. I would like to know the clause that assigns the new definition string to the “CSVExport” query inside the “ArchiveMusic” database. I would also like to know the command I can use to run a SELECT statement inside the macro that returns a single integer value, and assign said value to the macro variable var, preferably using the syntax ‘$var = select_value(“SELECT …”)’. If you quote your answer, like I just did, please remember to use double quotes to quote single quotes and quadruple quotes to quote double quotes. Thank you!

I think you can find useful information in:

https://wiki.documentfoundation.org/Macros

Andrew’s Macros it’s a reference.
OO.o Basic Programmer’s guide.