Indexing by field specified by number

This forum is for eXpress++ general support.
Post Reply
Message
Author
User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Indexing by field specified by number

#1 Post 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
Attachments
Безымянный.jpg
Безымянный.jpg (65.62 KiB) Viewed 12604 times

User avatar
Auge_Ohr
Posts: 1428
Joined: Wed Feb 24, 2010 3:44 pm

Re: Indexing by field specified by number

#2 Post 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.
greetings by OHR
Jimmy

User avatar
rdonnay
Site Admin
Posts: 4813
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Indexing by field specified by number

#3 Post 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
The eXpress train is coming - and it has more cars.

User avatar
Auge_Ohr
Posts: 1428
Joined: Wed Feb 24, 2010 3:44 pm

Re: Indexing by field specified by number

#4 Post by Auge_Ohr »

Auge_Ohr wrote:there is NO FIELDSIZE() or FIELDDECI() in Xbase++
ok,sorry found FieldSize() / FieldDeci() in XbTools
greetings by OHR
Jimmy

User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Re: Indexing by field specified by number

#5 Post 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.
Attachments
Безымянный.jpg
Безымянный.jpg (65.61 KiB) Viewed 12585 times

User avatar
rdonnay
Site Admin
Posts: 4813
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Indexing by field specified by number

#6 Post 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
The eXpress train is coming - and it has more cars.

User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Re: Indexing by field specified by number

#7 Post 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]
Attachments
Безымянный.jpg
Безымянный.jpg (167.01 KiB) Viewed 12538 times

User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Re: Indexing by field specified by number

#8 Post 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.

Post Reply