You've got the right idea Jason.
This type approach works a treat for us in an application suite that
supports multiple RDBMS platforms.
We have a .ini file that provides us with the connection string, a
'platform' indicator and the path to the xml file.
The sql strings for all platforms are stored in one xml file that is
implemented as an ADODB.Recordset streamed to xml.
The application creates an ADODB.Recordset, opens it from the xml file and
filters it based on the platform indicator.
Each record in the recordset has the platform identifier, a record
identifier and the sql string.
A Public function 'GetSQL' is used to return the required sql string which
then can be executed, assigned to the connamdtext property of an
ADODB.Command object or whatever.
The required identifier is passed to the function along with a ParamArray
containing replaceable parameters thus:
sql = GetSQL(12345,"fred",3)
Once the function has located the sql string it works through the ParamArray
replacing tokens with the supplied values. We represent the tokens as '%R%'
thus:
select aaa,bbb,ccc from zzz where ddd='%R%' and eee=%R%
The sql string returned will be:
select aaa,bbb,ccc from zzz where ddd='fred' and eee=3
The xml file can be freely edited as long as one remembers about special xml
characters such as < and > etc.
Once you have converted to using stored procedures, the same mechanism can
still be used except that the sql strings will define stored procedure calls
instead.
One thing I find usefule is to include the sql string in the source as a
comment line associated with the GetSQL call so it is easy to see what one
is doing.
You will find that, using this approach, the size of the executable will be
significantly reduced becaue the literal sql strings are, of course, not
compiled into the executable.
Clear as mud?
> I have a VB6 application I'm developing that has to be able to query both
> SQL Server and Oracle databases. The queries it has to submit will be
[quoted text clipped - 25 lines]
> Thanks,
> Jason
Jason - 31 Aug 2003 23:32 GMT
Thanks Stephany, that is almost exactly what I had in mind.
A couple of questions for you...
you said, "it works through the ParamArray" -- Is ParamArray a custom
object or class or is it a VB type? I'll go look it up of course but thought
I'd ask.
I know how < (<) and > (>) are special characters in XML, so how do
you use them w/ your query XML file? Enclose them in CData or something?
Thanks for your help,
Jason
> You've got the right idea Jason.
>
[quoted text clipped - 81 lines]
> > Thanks,
> > Jason