Re: Fastest way to get table scheme?
From: Arthur Hoornweg (arthur.hoornweg_at_wanadoo.nl.net)
Date: 11/16/04
- Next message: Shekar: "Re: Return Multiple Datasets using ADO"
- Previous message: ed: "AV Connecting to a AS400"
- In reply to: Del M: "Re: Fastest way to get table scheme?"
- Next in thread: Del M: "Re: Fastest way to get table scheme?"
- Reply: Del M: "Re: Fastest way to get table scheme?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 16 Nov 2004 09:55:03 +0100
Del M wrote:
> The way that you do it is generic since systables etc are unique to Sql
> server. But ... what is the problem with just selecting your data, then
> making some fields invisible and the rest persistent. Why do you need the
> table structure to do that ?
Part of the problem is that the number and most of the names
of the data fields are not known at design-time. So I can't
just do a "select column1, column2..." in my query.
The other part of the problem is that it's not just *one* query
that is performed, in fact a new query is performed every time
the user scrolls through my dbgrid.
I have a form with a dbgrid (TMS dbAdvStringGrid).
The underlying table is 50,000+ records large and is accessed
by the customer through a VPN tunnel with only 64 kilobits/second.
The connection is ADO, using a client-side recordset. Data are
fetched using a firehose cursor and all updates are performed as
batch updates.
The table contains numerical data from oilwells and the various
parameters are different from oilwell to oilwell and from
customer to customer.
The users need to be able to scroll through the whole dataset
transparently with the dbgrid. The look-and-feel of a grid is
absolutely necessary for this particular purpose.
I have designed the logic of the form in such a way, that only the
data that are currently visible on the screen are fetched. So the
grid is maybe only 30 records in size. Still it has a scrollbar
that allows you to scroll through the entire dataset and behaves
like any other live dbgrid.
Everytime the vertical scrollbar is moved (or if the user presses
pgup/pgdn) a new query is automatically generated that fetches the
desired records. So the whole thing looks like a dbgrid, feels like
a dbgrid but doesn't have the bandwidth/table size limitations of
a normal dbgrid. Scrolling to *any* position in the dataset takes
no more than a second or two even over a 64 kbit connection.
At design-time, the exact number of fields in this table is
unknown, it depends on the number of parameters the particular
customer wants recorded. So my trick is, when the dataset is first
opened, I determine the table structure just to determine which
fields are present, I then exclude some fields that the customer
shouldn't see, add some calculated fields and then transform the
lot into persistent fields.
I want to do this only once, not every time the user scrolls through
the dataset, because I've found the grid behaves erratically if I
change the field layout all the time.
So when the dataset is first opened my query is "select * from mytable
where 0=1" which gives me the table structure.
Any subsequent queries look like "select * from mytable where
project='ABCDE' and depth between 1000.8 and 1030.8 order by depth"
where the exact numbers depend on the position of the scrollbar.
It works magnificently but I am a bit worried if all database
engines behave the same if you give them a "where 0=1" query.
The table can have millions of records, eventually, and it
would be pretty sad if the database engine would iterate
through all records verifying a condition that always evaluates
to "false".
-- Arthur Hoornweg (please remove the ".net" from my e-mail address. I had to take this measure to counteract SPAM flooding my mail box)
- Next message: Shekar: "Re: Return Multiple Datasets using ADO"
- Previous message: ed: "AV Connecting to a AS400"
- In reply to: Del M: "Re: Fastest way to get table scheme?"
- Next in thread: Del M: "Re: Fastest way to get table scheme?"
- Reply: Del M: "Re: Fastest way to get table scheme?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|