|
FORUMS PROFESSIONNELS WINDEV, WEBDEV et WINDEV Mobile |
| | | | | |
Débuté par John Marrone, 02 juil. 2004 14:51 - 7 réponses |
| |
| | | |
|
| |
Posté le 02 juillet 2004 - 14:51 |
I can not get this view to work. The RaceID field is a string 18 characters in the table DEMO_TestData. Here is the code: Rac is a Data Source vcTemp is a string vnResult is a int vnResult = HOpen(DEMO_Testdata) HReadFirst(DEMO_Testdata) WHILE True vcTemp = DEMO_Testdata.RaceID HCreateView(Rac,"select * from DEMO_Testdata where RaceID = {vcTemp}") HExecuteView(Rac) Info(Rac.RaceID) HReadNext(DEMO_Testdata,RaceID) IF HOut(DEMO_Testdata) THEN BREAK END END This is test code to learn how to use these views. Can it be the curly brackets I am using for text subsition? Can anybody help?? John Marrone |
| |
| |
| | | |
|
| | |
| |
Posté le 02 juillet 2004 - 14:56 |
G'day John Just allow the view wizard to write your code and you will see how it should be done. Just type in hcreateview( then let the wizard take over Regards Al |
| |
| |
| | | |
|
| | |
| |
Posté le 02 juillet 2004 - 15:14 |
G'day John Here is an alternative method for the rest of the code in your sample HReadFirst(DEMO_Testdata) WHILE not hout() if hcreateview(Rac,fieldlist,sort,conditions) Hreadfirst(Rac) While not hout() Info(Rac.RaceID) hreadnext(Rac) end //while rac end //hcreateview HReadNext(DEMO_Testdata,RaceID) END //while demo Regards Al |
| |
| |
| | | |
|
| | |
| |
Posté le 02 juillet 2004 - 15:37 |
Hello John, why do you try to use indirection in a string? Use simple: HCreateView(Rac,"select * from DEMO_Testdata where RaceID = " + vcTemp) HTH Raimund
I can not get this view to work. The RaceID field is a string 18 characters in the table DEMO_TestData. Here is the code: Rac is a Data Source vcTemp is a string vnResult is a int vnResult = HOpen(DEMO_Testdata) HReadFirst(DEMO_Testdata) WHILE True vcTemp = DEMO_Testdata.RaceID HCreateView(Rac,"select * from DEMO_Testdata where RaceID = {vcTemp}") HExecuteView(Rac) Info(Rac.RaceID) HReadNext(DEMO_Testdata,RaceID) IF HOut(DEMO_Testdata) THEN BREAK END END This is test code to learn how to use these views. Can it be the curly brackets I am using for text subsition? Can anybody help?? John Marrone
http://www.invitec.com |
| |
| |
| | | |
|
| | |
| |
Posté le 02 juillet 2004 - 16:38 |
G'day John Why would you use a select() inside a view ? Surely the view will do all the work quite efficiently on its own HCreateView(Rac,"select * from DEMO_Testdata where RaceID = " + vcTemp) HCreateView(Rac,DEMO_Testdata,"*","","RaceID = " + vcTemp) In any case, the only field being displayed in the info() message is raceID so its the only field that needs retrieving HCreateView(Rac,DEMO_Testdata,"RaceId","","RaceID = " + vcTemp) And you know what it is anyway because it equals vctemp. I am curious as to what you are trying to achieve in the example. If the aim of the exercide is to build a list of occurrences for each value of raceid then it might be better to just read through the Demo_TestData file and build a memory table to hold the results. Re another item in the example >vnResult = HOpen(DEMO_Testdata) The concept behind testing the hopen() result is to see if the file was actually opened so this should be vnResult = HOpen(DEMO_Testdata) If vnResult = true or If HOpen(DEMO_Testdata)
Regards Al |
| |
| |
| | | |
|
| | |
| |
Posté le 02 juillet 2004 - 17:36 |
Hi Al I want to get a subset of records from a table based on the value of RaceID. I deal with horse racing. In my races table I will have 1 race record for each race. But in my entries table I will have that same raceid several times, depending on how many horses were in the race. So I want a recordset or in WinDev a view with just those records in the view. Then I need to sort on a field and then add a value to an other field and then write it back to the table. A RaceID = vcTemp will not do. [< I need sql so I can order on a field decs so the subrecords will be in the order I want them in and I can rank the horses 1 , 2, 3rd best in this factor and write the new information back to the entries table. >] What ever I use I have to be able to reflect any changes back to the table. I just seen there is a function called HViewToFile. This is supossed to let be write back to the table. Any suggestions?? Thanks John Marrone
G'day John Why would you use a select() inside a view ? Surely the view will do all the work quite efficiently on its own HCreateView(Rac,"select * from DEMO_Testdata where RaceID = " + vcTemp) HCreateView(Rac,DEMO_Testdata,"*","","RaceID = " + vcTemp) In any case, the only field being displayed in the info() message is raceID so its the only field that needs retrieving HCreateView(Rac,DEMO_Testdata,"RaceId","","RaceID = " + vcTemp) And you know what it is anyway because it equals vctemp. I am curious as to what you are trying to achieve in the example. If the aim of the exercide is to build a list of occurrences for each value of raceid then it might be better to just read through the Demo_TestData file and build a memory table to hold the results. Re another item in the example vnResult = HOpen(DEMO_Testdata) The concept behind testing the hopen() result is to see if the file was actually opened so this should be vnResult = HOpen(DEMO_Testdata) If vnResult = true or If HOpen(DEMO_Testdata) Regards Al |
| |
| |
| | | |
|
| | |
| |
Posté le 02 juillet 2004 - 18:13 |
G'day John As you have probably guessed I am more at home with files and views than with SQL and in Windev the views are very fast. The following may work for you. This more psuedo code than actual code Condition = ViewEntries.RaceId = Races.RaceID Hcreateview(ViewEntries,EntriesTable,FieldList,SortOrder,Condition,hviewlocking) //At this point if you know what you want to change then you can process the view in a loop Hreadfirst(ViewEntries) While not hout() ViewEntries.Field = newvalue Hmodify(ViewEntries) Hreadnext(ViewEntries) End //while Hviewtofile(ViewEntries)
If you need to change the values interactively then the following may work, but I have not tried this - just a theory Hcreateview(ViewEntries,EntriesTable,FieldList,SortOrder,Condition,hviewlocking) HviewToMemoryTable(Table,ViewEntries) //put the memory table up on a window and edit the fields manually and as you exit each row //ViewEntries.field = Table.field //hmodify(ViewEntries) //When you exit the memory table, run a HviewToFile(ViewEntries) back to the table These methods will lock the entries table for the duration of the process. Another way would be to include the entries file primary key in the view, then Hviewtomemorytable , edit the memory table and on the row exit directly update the entries table by hreadseek(entries,primarykeyindex,table.primarykeyvalue) and then write the table values directly into the entries table. Regards Al |
| |
| |
| | | |
|
| | |
| |
Posté le 02 juillet 2004 - 22:45 |
Rac is a Data Source vcTemp is a string vnResult is a int vnResult = HOpen(DEMO_Testdata) HReadFirst(DEMO_Testdata) WHILE True vcTemp = DEMO_Testdata.RaceID HCreateView(Rac,"select * from DEMO_Testdata where RaceID = {vcTemp}") HExecuteView(Rac) Info(Rac.RaceID) HReadNext(DEMO_Testdata,RaceID) IF HOut(DEMO_Testdata) THEN BREAK END END Hi John. I have a couple of suggestions. First, note that you are calling HCreateView each time you go through your loop. It should be called only once, before the loop. While inside the loop you call HExecuteView with your new selection condition. Then you should destroy the view when you are done and out of the loop. I agree with Al that the SQL SELECT is nonstandard (at least, I've never seen it used with a view), and should be replaced with his code. I would simplify things at first so that the learning curve is manageable: Forget the WHILE loop - just create the view and display it in a table or step through the view with reads and use Info()or Trace to see what's going on. Then you can add HExecutes and other complications. Good luck. |
| |
| |
| | | |
|
| | | | |
| | |
| | |
| |
|
|
|