Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Database Access / August 2003



Tip: Looking for answers? Try searching our database.

Flexible Data Model

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jason - 31 Aug 2003 10:41 GMT
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
different depending on the database. Eventually we will probably move the
data calls into Stored Procedures but, at the moment, we're just using
dynamically generated queries in the code. I don't like these "hard coded"
queries though, as they're not flexible enough to change based on the
database.

My idea: use an XML "query file" (sqlserverqueries.xml / oraclequeries.xml)
with a structure like

<?xml bla bla>
   <queries>
       <query id=1 sql=SELECT * FROM TABLE1/>
       <query id=2 sql=SELECT * FROM TABLE2/>
   </queries>
</xml>

Then simply pass a file location reference to the xml query file and submit
queries retrieved from it. Does this seem like a good idea? bad idea? anyone
have any comments on how I could improve this or should I do something
entirely different? Keep in mind stored procedures aren't an option right
now but might be in the future

Also, I figured using XPath would be best to get the values from the xml
file since it would have a pretty simple structure, agree/disagree?

Thanks,
Jason
Stephany Young - 31 Aug 2003 13:17 GMT
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 < (&lt;) and > (&gt;) 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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.