Page 1 of 1

SQL queries. Positioning over a specific record

Posted: Wed Apr 30, 2008 3:53 pm
by BenD
Hi guys

I wonder if is it possible set the table pointer into an specific record provided by a SQL ADS query

My problem is the following:

I have a SQL query with too many results. Then, I think in giving the users the abiliity of searching through this result set and positioning over the
selected record.

With no SQL queries, this job was simple, only changing the index with ordsetfocus and executing a dbseek. But with an alias which is a result of a query i don´t know the way for do it...

Executing sql queries, are generated some default indexes ??

Thank In advance

Posted: Wed Apr 30, 2008 8:53 pm
by reinaldocrespo
If you are referring to the result of an SQL query, then you mean a "cursor". ADS cursors can be treated just like any .dbf alias.

(alias)->( recno() )

will yield the record number where the file pointer is in the cursor.

I hope I answered the question.


Reinaldo.

Posted: Wed Apr 30, 2008 9:37 pm
by BenD
Thanks Reinaldo for your interest...


Yes, I´m using this results as an alias..

But... how can I execute any search in that alias (cursor)...ie: the alias has 3 fields: name, tel, id, and I want to permit the users search over any of these fields...If the user chooses id and searches "1059", the cursor must go to that record, a lo DBSEEK.

Can you understand my problem...

Posted: Wed Apr 30, 2008 10:03 pm
by reinaldocrespo
I think I understand.

You can create an index, or even a temp index and then:

(cCursor)->( dbseek( ) ).... As you would on a real table.

With ADS server creating an index should happen very fast.

That should work.

Another option is to load the data into an array (dbeval()) and then allow the user to sort the data by clicking on the column's header (aSort()). Then allow them to increment search using aScan().

The SQL statement could be ORDER BY... so a quick search is possible using a binary search on sorted data.

Hope this helps.


Reinaldo.

Posted: Wed Apr 30, 2008 11:12 pm
by BenD
Thanks mate...

Excuse my poor knowlegdment, but, how is created the temp index over the cursor.. For do it, isn´t necessary opening in exclusive mode ?

Can you post any example ?