Page 1 of 1

Indexing by field specified by number

Posted: Mon Jul 23, 2018 12:46 pm
by Eugene Lutsenko
Is it possible to organize indexing in the database specified as the value of a variable on the field specified by the number in this database? Something like that:

Code: Select all

    SELECT(mInpData)
    DO CASE
       CASE FIELDTYPE(mNumFieldTabl) = 'N'
            INDEX ON STR(FIELDGET(mNumFieldTabl),FIELDSIZE(mNumFieldTabl),FIELDDECI(mNumFieldTabl)) TO Mrk_funi
       CASE FIELDTYPE(mNumFieldTabl) = 'C'
            INDEX ON FIELDGET(mNumFieldTabl) TO Mrk_funi
       CASE FIELDTYPE(mNumFieldTabl) = 'D'
            INDEX ON DTOC(FIELDGET(mNumFieldTabl)) TO Mrk_funi
    ENDCASE
[/size]
But it doesn't work:
INDEX ON STR(FIELDGET(mNumFieldTabl),FIELDSIZE(mNumFieldTabl),FIELDDECI(mNumFieldTabl)) TO Mrk_funi

Re: Indexing by field specified by number

Posted: Mon Jul 23, 2018 2:50 pm
by Auge_Ohr
Eugene Lutsenko wrote: But it doesn't work:
INDEX ON STR(FIELDGET(mNumFieldTabl),FIELDSIZE(mNumFieldTabl),FIELDDECI(mNumFieldTabl)) TO Mrk_funi
there is NO FIELDSIZE() or FIELDDECI() in Xbase++

use DbStruct() to get these Information.

Re: Indexing by field specified by number

Posted: Mon Jul 23, 2018 2:51 pm
by rdonnay
Try this:

Code: Select all

LOCAL cPointer, cIndex

cPointer := Alltrim(Str(mNumFieldTab1))

cIndex := 'Str(FieldGet('+cPointer+'),FieldSize('+cPointer+'),FieldDeci('+cPointer+'))'

INDEX ON &cIndex TO Mrk_Funi

Re: Indexing by field specified by number

Posted: Mon Jul 23, 2018 3:09 pm
by Auge_Ohr
Auge_Ohr wrote:there is NO FIELDSIZE() or FIELDDECI() in Xbase++
ok,sorry found FieldSize() / FieldDeci() in XbTools

Re: Indexing by field specified by number

Posted: Mon Jul 23, 2018 10:31 pm
by Eugene Lutsenko
rdonnay wrote:Try this:

Code: Select all

LOCAL cPointer, cIndex

cPointer := Alltrim(Str(mNumFieldTab1))

cIndex := 'Str(FieldGet('+cPointer+'),FieldSize('+cPointer+'),FieldDeci('+cPointer+'))'

INDEX ON &cIndex TO Mrk_Funi
Hi Roger!

Thank you for your help. Using your approach, I did this:

Code: Select all

    cPointer := Alltrim(Str(mNumFieldTabl))
    DO CASE
       CASE FIELDTYPE(mNumFieldTabl) = 'N'
            cIndex := 'Str(FieldGet('+cPointer+'),FieldSize('+cPointer+'),FieldDeci('+cPointer+'))'
       CASE FIELDTYPE(mNumFieldTabl) = 'C'
            cIndex := 'FieldGet('+cPointer+')'
       CASE FIELDTYPE(mNumFieldTabl) = 'D'
            cIndex := 'DTOC(FieldGet('+cPointer+')'
    ENDCASE
    INDEX ON &cIndex TO Mrk_Funi
but unfortunately, the same error occurs when trying to create an index file as before. By the way, what do the pluses in this design mean: FieldGet('+cPointer+')?

I feel intuitively that the cause of the problem may not be what I'm asking.

Re: Indexing by field specified by number

Posted: Tue Jul 24, 2018 6:07 am
by rdonnay
I tested this and it worked just fine for me:

Put a WTF cIndex in your code so I can see what is failing:

Code: Select all

 WTF cIndex
 INDEX ON &cIndex TO Mrk_Funi

Re: Indexing by field specified by number

Posted: Thu Jul 26, 2018 10:59 pm
by Eugene Lutsenko
Hi Roger!

Did as you said. The image at the bottom. There's a loop on the physical tables of the logical multi-table. In the first table, the first text field. The error occurs on the first field of the second table. It also gives me something to think about. I'll try to understand.

Code: Select all

FOR ff=1 TO mNFieldsALL

    mNumTabl      = 1+INT((ff-1)/mNFieldsTabl)                           // Номер таблицы
    mInpData      = 'Inp_data'+STRTRAN(STR(mNumTabl,3),' ','0')          // Наименование таблицы
    mNumFieldTabl = ff-(mNumTabl-1)*mNFieldsTabl                         // Номер поля в таблице

    SELECT(mInpData)

    cPointer := Alltrim(Str(mNumFieldTabl))
    DO CASE
       CASE FIELDTYPE(mNumFieldTabl) = 'N'
            cIndex := 'Str(FieldGet('+cPointer+'),FieldSize('+cPointer+'),FieldDeci('+cPointer+'))'
       CASE FIELDTYPE(mNumFieldTabl) = 'C'
            cIndex := 'FieldGet('+cPointer+')'
       CASE FIELDTYPE(mNumFieldTabl) = 'D'
            cIndex := 'DTOC(FieldGet('+cPointer+')'
    ENDCASE
    WTF cIndex
    INDEX ON &cIndex TO Mrk_Funi

    DBGOTOP()   ;F_MinSH = FieldGet(mNumFieldTabl)
    DBGOBOTTOM();F_MaxSH = FieldGet(mNumFieldTabl)
    
    IF F_MaxSH <> F_MinSH
       aErrorNum[ff] = .T.
    ENDIF

NEXT
[/size]

Re: Indexing by field specified by number

Posted: Fri Jul 27, 2018 12:31 am
by Eugene Lutsenko
Thank you, Roger, for helping me figure it out! As soon as I did so:INDEX ON &cIndex TO (mInpData), immediately all earned. The index file creation error occurred when I tried to create an index file with the same name for another database. All databases and index files were open all the time. As soon as I began to create for each database the index file separately at once everything worked.