Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to specify the name of a database that is in a different directory Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
28-Aug-02
Category
Database-SQL
Language
Delphi All Versions
Views
68
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas 

In an SQL select statement, how do I specify the name of a database that is in a 
different directory? Is there a way to parameterize the name so that a BDE alias is 
used to supply the directory?

Answer:

You cannot parameterize the value in an SQL statement such that a BDE alias could 
use the value. You could programmatically change the directory specified in the BDE 
alias itself, though. For that, see the TSession.ModifyAlias method.

But there are other ways to do this, ways that do not involve aliases. The table 
reference in a local SQL statement can consist of just a table name:

SELECT *
FROM Customer

It can be a table name and filename extension:


SELECT *
FROM "Customer.db"

It can be a table name prefixed with the name of a BDE alias:

SELECT *
FROM ": DBDEMOS: Customer.db"

or it can be a table name prefixed with a specific drive and directory reference:

SELECT *
FROM "C:\Program Files\Common Files\Borland Shared\Data\Customer"

With the different parts of an SQL statement on different lines within the 
TQuery.SQL property, you can more easily change just one of those parts without 
affecting the other parts. Do this by referencing one element of the string list 
object that is the SQL property. For example, to change just the second line (the 
FROM clause):

1   with Query1 do
2   begin
3     Close;
4     SQL[1] := '"' + DatabaseStrVar + 'Customer.db"';
5     Open;
6   end;


You could then set this memory variable DatabaseStrVar to a number of different 
values and the same code would still work.

1. An empty string.
2. The name of an alias (including colons in the variable).
3. A valid drive/ directory reference (ending in a back-slash).

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC