Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
4
Erster Beitrag:
vor 1 Jahr, 8 Monaten
Letzter Beitrag:
vor 1 Jahr, 8 Monaten
Beteiligte Autoren:
Mark Crichton, Mike H

Field names from fic file

Startbeitrag von Mark Crichton am 05.06.2016 10:06

HI
Can anyone help with extracting a list of the field names from a table into an array.
I tried FiletoArray(), but that seems to be the contents of a field...

I want to populate one table from another extracted via HExecutesqlquery.
I have a number of tables to do, so want to create by code rather than the following longhand...

Customers.CardIdentification = myQuery.CardIdentification
Customers.Name = myQuery.Name
Customers.LastName = myQuery.LastName

rather do something like

// Step 1 - get array of table field names
myArray is array of 1 strings



// Step 2 - scan array and populate all the fields in the table
sString is string
sFile = "customers"
nbDim is int
nbDim = ArrayInfo(myArray, tiNumberRows)
nRow is int = 1
FOR nRow = 1 TO nbDim
sString = sFile + "." + myArray[nRow,1] + " = myQuery." + myArray[nRow,1]
executecode(sString)
hAdd...
hModify...
xSeek = myArray[nRow,1]
end

Any Help Appreciated.
Thanks
Mark

Antworten:

Hi, Mark

HListItem returns a character string list of items in a specified file. Item names are separated by CR

It should then be easy to move them into an array

Hope this helps.

- Mike H

von Mike H - am 05.06.2016 11:33
Thanks Mike H
Just what I was looking for … Windev Rocks!

Here's part of my code which does a query on a remote database and update the data file on my application.
I have 80 odd tables to get data from, so this will save me many hours of work
My application has additional fields so will trap with " exception in "


// Step 5 - Scan and process the records
nRecid1 is int = 0
Result1 is int = -1
x is int = 1

sFile is string = "customers"
sHList is string = HListItem(sFile)
myArray is array of [0,1] string
StringToArray(sHList,myArray)

HReadFirst(myQuery)
WHILE NOT HOut()
// 5.1 Lookup the customer and add if not found
nRecid = myQuery.CardRecordID
Result1 = HReadSeekFirst(Customers,CardRecordID,nRecid)

// 5.2 - Prepare Add/Insert record
HReset(Customers)

// 5.3 - scan array and populate all the fields in the table
nbDim is int
nbDim = ArrayInfo(myArray, tiNumberRows)
nRow is int = 1
FOR nRow = 1 TO nbDim
sString = sFile + "." + myArray[nRow,1] + " = myQuery." + myArray[nRow,1]
// add extra code here for exception in
ExecuteCode(sString)
END

IF Result1 < 1 THEN
HAdd(Customers)
ELSE
// don't try update the primary keys
Customers.CustomerID = Null // I (4),;
Customers.CardRecordID = Null // I (4),
HModify(Customers,hCurrentRecNum)
END

// increment my counter to display later
x ++

HReadNext(myQuery)
END

von Mark Crichton - am 05.06.2016 20:07
Note about the code above.

It turned out to be very slow when processing a dataFile with 71000 rows. Went from 1 minute to 3 hours… So back to old code on large tables.
The script is also good for extracting the fields and writing to a text file to copy into class methods.

von Mark Crichton - am 06.06.2016 20:47
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.