|
| Field names from fic file |
| Iniciado por guest, 05,jun. 2016 12:06 - 3 respuestas |
| |
| | | |
|
| |
| Publicado el 05,junio 2016 - 12: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 |
| |
| |
| | | |
|
| | |
| |
| Publicado el 05,junio 2016 - 13:33 |
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 |
| |
| |
| | | |
|
| | |
| |
| Publicado el 05,junio 2016 - 22:07 |
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 |
| |
| |
| | | |
|
| | |
| |
| Publicado el 06,junio 2016 - 22:47 |
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. |
| |
| |
| | | |
|
| | | | |
| | |
|