I am having trouble trying to create a conditional index with ADS Local and xHarbour.

Normally (no ADS) I would create an index as follows: INDEX ON MyData->Field1 TO C:\MyIndexFile FOR MyData->Field2 = cSomeVar

After doing a bunch of searches I found that ADS Lcoal cannot use: cSomeVar
and the work around is to do "&cSomeVar" in place of cSomeVar. So the line of code should look like: INDEX ON MyData->Field1 TO C:\MyIndexFile FOR MyData->Field2 = "&cSomeVar"

This does not work as it just sees the "&cSomeVar" as straight text (does not convert the cSomeVar to its avtual value)

Does anyone know how I can get this to work?

Thanks for any info you can supply, Jeff

asked 12 Jan '14, 06:54

JeffB's gravatar image

accept rate: 0%

edited 15 Jan '14, 01:58

Joachim%20Duerr's gravatar image

Joachim Duerr

May be the question can be tagged 'harbour' xharbour'

(15 Jan '14, 01:23) Carlos Mora

I'm not sure exactly wich is the spected behavoir of the index using a var as an expresion. Let's asume that a var is being used to specify a constant value. To do that you can't use the command because the varriable cSomeVar will be part of the expression and couldn't be evaluated by the server after disconnection. The index must be created using OrdCondSet() and OrdCreate().

ordCondSet( <"for">, <{for}>, [<.all.>], <{while}>, ;
                     <{eval}>, <every>, RECNO(), <next>, <rec>, ;
                     [<.rest.>], [<.descend.>],, ;
                     [<.add.>], [<.cur.>], [<.cust.>], [<.noopt.>], ;
                     <"while">, [<.mem.>], [<.filter.>], [<.ex.>] ) ;;
         ordCreate( <(bag)>, <(tag)>, <"key">, <{key}>, [<.unique.>] )

In your case, it will look more or less like

OrdCondSet( "MyData->Field2 == '"+cSomeVar+"'", &("{||MyData->Field2 == '"+cSomeVar+"'}")
OrdCreate( "C:\MyIndexFile", "Field1", "MyData->Field1", {|| MyData->Field1 }, .F. )

I use Harbour, not xHarbour, so may be there are some minor differences, but it should solve the problem. I suggest you to compile your curren code with the /p command line option to generate the preprocessed code generated for an INDEX ON command, and adapt that piece of code to yours in de ordCondSet function.


answered 15 Jan '14, 00:35

Carlos%20Mora's gravatar image

Carlos Mora
accept rate: 0%

I am not familiar with how xHarbour converts the index call to the Advantage Client Engine call (ACE). But the INDEX ON MyData->Field1 ... call I suspect ends up getting translated to a call such as the following:

ret = AdsCreateIndex90( hTable, "myindexfile", "tagname", "Field1", 
           "Field2=somevalue", <=== This line is the FOR condition
           NULL, options, ... &hIndex );

The FOR clause is passed as a string value to the ACE API. The Advantage code (client and server) does not have access to any of the calling process' variables (e.g., cSomeVar). So if xHarbour is not converting the FOR expression to the actual value, then it might be necessary for you to make that conversion:

INDEX ON MyData->Field1 TO C:\MyIndexFile FOR MyData->Field2 = 1234

answered 13 Jan '14, 09:56

Mark%20Wilkins's gravatar image

Mark Wilkins
accept rate: 26%

Your answer to the original question.
If responding to a request for additional information, please edit the question or use the comment functionality.
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 12 Jan '14, 06:54

Seen: 2,443 times

Last updated: 15 Jan '14, 01:58

Advantage Developer Zone Contact Us Privacy Policy Copyright Info

Powered by Advantage Database Server and OSQA
Disclaimer: Opinions expressed here are those of the poster and do not necessarily reflect the views of the company.