Re:Looping through a list, setting each listItem to a column
Thanks a lot Craig for your timely help. I'm using the code you posted, this was exactly what I was after, thanks again. Also thank you Peter for your help Best Regards Allan >This works, > >it's a bit of a fudge, but it does the job. > > > > > > > > QuerySetCell(qTmp,"DateTime", listGetAt(fileLine,1)); > QuerySetCell(qTmp,"User", listGetAt(fileLine,2)); > QuerySetCell(qTmp,"Status", listlast(fileLine)); > > x = listLen(fileLine) - 1; > doc = ""; > for ( i = 3 ; i lte x ; i = i + 1 ){ > doc = doc & "," & listGetAt(fileLine,i); > } > > QuerySetCell(qTmp,"Document", doc); > > > > QuerySetCell(qTmp,"DateTime", listGetAt(fileLine,1)); > QuerySetCell(qTmp,"User", listGetAt(fileLine,2)); > QuerySetCell(qTmp,"Document", listGetAt(fileLine,3)); > QuerySetCell(qTmp,"Status", listGetAt(fileLine,4)); > > > > > > -Original Message- > From: ColdFusion Programmer [mailto:[EMAIL PROTECTED] > > Sent: 09 October 2003 10:43 > To: CF-Talk > Subject: Re:Looping through a list, setting each listItem to a >column > > > I'm afraid it does not work. I replaced my script with yours and >it did'nt work. There is one column which contains commas in it, I want >to escape the comma, I have made an effort, but I can't get my head >round it which is why I'm asking for other people's help. Here is an >example > > 2003/09/09 14:49:05, "TestUser1", >"/Doc/News/Budgeting,Forecasting & Reporting.doc", "OK" > > As you can see the string "/Doc/News/Budgeting,Forecasting & >Reporting.doc" has a comma in it, I want to escape it. > > Thanks for your help > > >The script wasn't meant to give you a regexp to replace the >commas. It > >does the entire job of creating the query and takes the " as a > >qualifier into consideration. Replace your script by mine and >it > >should work. > > > > -Oorspronkelijk bericht- > > Van: ColdFusion Programmer >[mailto:[EMAIL PROTECTED] > > Verzonden: wo 8/10/2003 17:32 > > Aan: CF-Talk > > CC: > > Onderwerp: Re:Looping through a list, setting each listItem to >a > >column > > > > > > I've tried that and it does not work. Here is my code > > > > > > myList = '2003/09/09 14:49:05, "TestUser1", >"/Doc/News/Budgeting, > >Forecasting & Reporting.doc", "OK"'; > > myList = REReplace(myList, '^[[:space:]]*([^, > >]*|"([^"]|"")*")[[:space:]]*(,|$)',''); > > > > #myList# > > > > >This should do it in CF using regexp. > > >There are probably custom tags that will read logs more >efficiently > > > > >though. > > > > > _ > > [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
Re:Looping through a list, setting each listItem to a column
It does'nt work for me, I don't know what I'm doing wrong, I am doing exactly the same thing as you are, can't understand why it works for you and not me. The output from the dump looks like this DATETIME DOCUMENT STATUS USER 1 09-Oct-03 test2" [empty string] "test" 2 2003/09/09 14:49:05 "/Doc/News/Budgeting Forecasting & Reporting.doc" "TestUser1" >The script works for me. I am not escaping anything, just extracting the >correct info from the csv (log). See code below. The only thing I >changed is to take blank lines into consideration (it hanged my cf if >there was a blank line at the end). Also: as I said before, there are >custom tags that will read csv's more efficiently > >Date User Webpage Status >#DateFormat(Now())#, "test", "test2" >2003/09/09 14:49:05, "TestUser1", "/Doc/News/Budgeting,Forecasting & >Reporting.doc", "OK" > > >columns = "DateTime,User,Document,Status"; >qTmp = QueryNew(columns); >pattern = '^[[:space:]]*([^,]*|"([^"]|"")*")[[:space:]]*(,|$)'; >matchStruct = structNew(); >for(i=2;i LE ListLen(fOutput,chr(10));i=i+1){ > line = ListGetAt(fOutput,i,chr(10)); > if(Len(line)){ > QueryAddRow(qTmp,1); > exit = false; > j = 1; > while(NOT exit){ > // find matching pattern > matchStruct = REFindNoCase(pattern,line,1,true); > if(matchStruct.pos[1] AND j LE ListLen(columns)){ > field = Mid(line,matchStruct.pos[2],matchStruct.len[2]); > WriteOutput("#i#.#j#:|#field#|"); > QuerySetCell(qTmp,ListGetAt(columns,j),field); > if(matchStruct.len[1]) > line = RemoveChars(line,1,matchStruct.len[1]); > j = j + 1; > } > else exit = true; > } > } >} > >Log > >#fOutput# > > > > >Pascal Peters >Certified ColdFusion MX Advanced Developer >Macromedia Certified Instructor >LR Technologies >Av. E. De Mot, 19 >1000 BRUSSELS, BELGIUM >Tel: +32 2 639 68 70 >Fax: +32 2 639 68 99 >Email: [EMAIL PROTECTED] >Web: www.lrt.be > >-Original Message- >From: ColdFusion Programmer [mailto:[EMAIL PROTECTED] >Sent: donderdag 9 oktober 2003 11:43 >To: CF-Talk >Subject: Re:Looping through a list, setting each listItem to a column > > >I'm afraid it does not work. I replaced my script with yours and it >did'nt work. There is one column which contains commas in it, I want to >escape the comma, I have made an effort, but I can't get my head round >it which is why I'm asking for other people's help. Here is an example > >2003/09/09 14:49:05, "TestUser1", "/Doc/News/Budgeting,Forecasting & >Reporting.doc", "OK" > >As you can see the string "/Doc/News/Budgeting,Forecasting & >Reporting.doc" has a comma in it, I want to escape it. > >Thanks for your help > >>The script wasn't meant to give you a regexp to replace the commas. It >>does the entire job of creating the query and takes the " as a >>qualifier into consideration. Replace your script by mine and it >>should work. >> > > [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
Re:Looping through a list, setting each listItem to a column
I'm afraid it does not work. I replaced my script with yours and it did'nt work. There is one column which contains commas in it, I want to escape the comma, I have made an effort, but I can't get my head round it which is why I'm asking for other people's help. Here is an example 2003/09/09 14:49:05, "TestUser1", "/Doc/News/Budgeting,Forecasting & Reporting.doc", "OK" As you can see the string "/Doc/News/Budgeting,Forecasting & Reporting.doc" has a comma in it, I want to escape it. Thanks for your help >The script wasn't meant to give you a regexp to replace the commas. It >does the entire job of creating the query and takes the " as a >qualifier into consideration. Replace your script by mine and it >should work. > > -Oorspronkelijk bericht- > Van: ColdFusion Programmer [mailto:[EMAIL PROTECTED] > Verzonden: wo 8/10/2003 17:32 > Aan: CF-Talk > CC: > Onderwerp: Re:Looping through a list, setting each listItem to a >column > > > I've tried that and it does not work. Here is my code > > > myList = '2003/09/09 14:49:05, "TestUser1", "/Doc/News/Budgeting, >Forecasting & Reporting.doc", "OK"'; > myList = REReplace(myList, '^[[:space:]]*([^, >]*|"([^"]|"")*")[[:space:]]*(,|$)',''); > > #myList# > > >This should do it in CF using regexp. > >There are probably custom tags that will read logs more efficiently > > >though. > > [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
Re:Looping through a list, setting each listItem to a column
I've tried that and it does not work. Here is my code myList = '2003/09/09 14:49:05, "TestUser1", "/Doc/News/Budgeting,Forecasting & Reporting.doc", "OK"'; myList = REReplace(myList, '^[[:space:]]*([^,]*|"([^"]|"")*")[[:space:]]*(,|$)',''); #myList# >This should do it in CF using regexp. >There are probably custom tags that will read logs more efficiently >though. > > >columns = "DateTime,User,Document,Status"; >qTmp = QueryNew(columns); >pattern = '^[[:space:]]*([^,]*|"([^"]|"")*")[[:space:]]*(,|$)'; >matchStruct = structNew(); >for(i=2;i LE ListLen(fOutput,chr(10));i=i+1){ >QueryAddRow(qTmp,1); >line = ListGetAt(fOutput,i,chr(10)); >exit = false; >j = 1; >while(NOT exit){ >// find matching pattern >matchStruct = REFindNoCase(pattern,line,1,true); >if(matchStruct.pos[1] AND j LE ListLen(columns)){ >field = Mid(line,matchStruct.pos[2],matchStruct.len[2]); >QuerySetCell(qTmp,ListGetAt(columns,j),field); >if(matchStruct.len[1]) >line = RemoveChars(line,1,matchStruct.len[1]); >j = j + 1; >} >else exit = true; >} >} > > > > -Oorspronkelijk bericht- > Van: ColdFusion Programmer [mailto:[EMAIL PROTECTED] > Verzonden: wo 8/10/2003 15:53 > Aan: CF-Talk > CC: > Onderwerp: Re:Looping through a list, setting each listItem to a >column > > > Have tried but can't crack it. Can you please show me how to do it if >you don't mind, thanks in advance. > > >Yes a regular _expression_ (regex) , what you would want is a regex >that > >finds any commas that are between quotation marks and either >escapes > >them or replaces them. > > [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
Re:Looping through a list, setting each listItem to a column
Have tried but can't crack it. Can you please show me how to do it if you don't mind, thanks in advance. >Yes a regular _expression_ (regex) , what you would want is a regex that >finds any commas that are between quotation marks and either escapes >them or replaces them. > >I'm no regex expert and that would take me quite a while to figure out, >maybe later if youre still stuck. > >Good luck. > > -Original Message- > From: ColdFusion Programmer [mailto:[EMAIL PROTECTED] > > Sent: 08 October 2003 12:55 > To: CF-Talk > Subject: Re:Looping through a list, setting each listItem to a >column > > > thanks Craig, you've really been of great help. I have another >question for you, what I've noticed is a couple of rows are not >displayed because the document column has a documnet name with a comma >in it. Here is an example. > > 2003/09/09 14:49:05, "TestUser1", >"/Doc/News/Budgeting,Forecasting & Reporting.doc", "OK" > > As you can see the document name >"/Doc/News/Budgeting,Forecasting & Reporting.doc" has a comma in it. And >because our delimeter is "," the list finds 4 items. Can you think of >any way of getting round this problem. > > Cheers > Allan > >Had a proper look at it, > > > >you actualy only need 1 loop. > > > > > > >delimiters="#Chr(10)#"> > > > > > > > > tmp=QuerySetCell(qTmp,"DateTime", listGetAt(fileLine,1)); > > tmp=QuerySetCell(qTmp,"User", listGetAt(fileLine,2)); > > tmp=QuerySetCell(qTmp,"Document", listGetAt(fileLine,3)); > > tmp=QuerySetCell(qTmp,"Status", listGetAt(fileLine,4)); > > > > > > > > > >That should ignore any invalid lines too. > > > > -Original Message- > > From: ColdFusion Programmer >[mailto:[EMAIL PROTECTED] > > > > Sent: 08 October 2003 11:52 > > To: CF-Talk > > Subject: Re:Looping through a list, setting each listItem to a > >column > > > > > > Yes it does work now, thanks a ton for your speedy help. > > Cheers > > > > >This works... > > > > > > > > > > > > >delimiters="#Chr(10)#"> > > > > > > > > > > > > tmp=QuerySetCell(qTmp,"DateTime", listGetAt(lIndex,1)); > > > tmp=QuerySetCell(qTmp,"User", listGetAt(lIndex,2)); > > > tmp=QuerySetCell(qTmp,"Document", listGetAt(lIndex,3)); > > > tmp=QuerySetCell(qTmp,"Status", listGetAt(lIndex,4)); > > > > > > > > > > > > > > > -Original Message- > > > From: ColdFusion Programmer > >[mailto:[EMAIL PROTECTED] > > > > > > Sent: 08 October 2003 11:32 > > > To: CF-Talk > > > Subject: Re:Looping through a list, setting each listItem to >a > > >column > > > > > > > > > Craig, I tried running your code and get this error, > > > > > > Invalid list index 2. > > > In function ListGetAt(list, index [, delimiters]), the value > >of > > >index, 2, is not a valid as the first argument (this list has >1 > > >elements). Valid indexes are in the range 1 through the >number > >of > > >elements in the list. > > > > > > Any ideas? > > > > > > >Try this.. > > > > > > > > > > > > > >delimiters="#Chr(10)#"> > > > > > > > > > > > > > > > > >delimiters=","> > > > > > > > > tmp=QuerySetCell(qTmp,"DateTime", listGetAt(innerList,1)); > > > > tmp=QuerySetCell(qTmp,"User", listGetAt(innerList,2)); > > > > tmp=QuerySetCell(qTmp,"Document", listGetAt(innerList,3)); > > > > tmp=QuerySetCell(qTmp,"Status", listGetAt(innerList,4)); > > > > > > > > > > > > > > > > > > > > > > > > > > > >The listgetat function inside your inner loop is the only > > >change i've > > > >made > > > > > > > > -Original Message- > > > > From: Allan Clarke [mailto:[EMAIL PROTECTED] > > > > Sent: 08 October 2003 11:16 > > > > To: CF-Talk > > > > Subject: Looping through a list, setting each listItem to >a > > > >column > > > > > > > > >
Re:Looping through a list, setting each listItem to a column
thanks Craig, you've really been of great help. I have another question for you, what I've noticed is a couple of rows are not displayed because the document column has a documnet name with a comma in it. Here is an example. 2003/09/09 14:49:05, "TestUser1", "/Doc/News/Budgeting,Forecasting & Reporting.doc", "OK" As you can see the document name "/Doc/News/Budgeting,Forecasting & Reporting.doc" has a comma in it. And because our delimeter is "," the list finds 4 items. Can you think of any way of getting round this problem. Cheers Allan >Had a proper look at it, > >you actualy only need 1 loop. > > > > > > > tmp=QuerySetCell(qTmp,"DateTime", listGetAt(fileLine,1)); > tmp=QuerySetCell(qTmp,"User", listGetAt(fileLine,2)); > tmp=QuerySetCell(qTmp,"Document", listGetAt(fileLine,3)); > tmp=QuerySetCell(qTmp,"Status", listGetAt(fileLine,4)); > > > > >That should ignore any invalid lines too. > > -Original Message----- > From: ColdFusion Programmer [mailto:[EMAIL PROTECTED] > > Sent: 08 October 2003 11:52 > To: CF-Talk > Subject: Re:Looping through a list, setting each listItem to a >column > > > Yes it does work now, thanks a ton for your speedy help. > Cheers > > >This works... > > > > > > > > > > > > > > > > tmp=QuerySetCell(qTmp,"DateTime", listGetAt(lIndex,1)); > > tmp=QuerySetCell(qTmp,"User", listGetAt(lIndex,2)); > > tmp=QuerySetCell(qTmp,"Document", listGetAt(lIndex,3)); > > tmp=QuerySetCell(qTmp,"Status", listGetAt(lIndex,4)); > > > > > > > > > > -Original Message- > > From: ColdFusion Programmer >[mailto:[EMAIL PROTECTED] > > > > Sent: 08 October 2003 11:32 > > To: CF-Talk > > Subject: Re:Looping through a list, setting each listItem to a > >column > > > > > > Craig, I tried running your code and get this error, > > > > Invalid list index 2. > > In function ListGetAt(list, index [, delimiters]), the value >of > >index, 2, is not a valid as the first argument (this list has 1 > >elements). Valid indexes are in the range 1 through the number >of > >elements in the list. > > > > Any ideas? > > > > >Try this.. > > > > > > > > > >delimiters="#Chr(10)#"> > > > > > > > > > > > > > > > > > > tmp=QuerySetCell(qTmp,"DateTime", listGetAt(innerList,1)); > > > tmp=QuerySetCell(qTmp,"User", listGetAt(innerList,2)); > > > tmp=QuerySetCell(qTmp,"Document", listGetAt(innerList,3)); > > > tmp=QuerySetCell(qTmp,"Status", listGetAt(innerList,4)); > > > > > > > > > > > > > > > > > > > > >The listgetat function inside your inner loop is the only > >change i've > > >made > > > > > > -Original Message- > > > From: Allan Clarke [mailto:[EMAIL PROTECTED] > > > Sent: 08 October 2003 11:16 > > > To: CF-Talk > > > Subject: Looping through a list, setting each listItem to a > > >column > > > > > > > > > Hello Everybody, > > > > > > I am trying to read a log file and display the results > > > on a webpage. > > > Here is what the log file looks. > > > > > > DateTime User Webpage Visited Status > > > 2003/09/01 11:52:15, "User\testUser1", > > > "/wwwroot/code/article_1.shtml", "OK" > > > 2003/09/01 11:53:35, "User\testUser2", > > > "/wwwroot/code/article_2.shtml", "OK" > > > 2003/09/01 12:04:55, "User\testUser3", > > > "/wwwroot/code/article_3.shtml", "OK" > > > 2003/09/01 12:04:58, "User\testUser4", > > > "/wwwroot/code/article_4.shtml", "OK" > > > 2003/09/01 12:05:11, "User\testUser5", > > > "/wwwroot/code/article_5.shtml", "OK" > > > > > > Here is the code to read the log file > > > > > > action=""> > > > file="C:\myLogFile.log" > > > variable="fOutput"> > > > > > > Take a look at the code below. As you can see I am > > > looping through the list, finding the Carriage Return > > > character. > > > This is all fine, what I
Re:Looping through a list, setting each listItem to a column
Yes it does work now, thanks a ton for your speedy help. Cheers >This works... > > > > > > > > tmp=QuerySetCell(qTmp,"DateTime", listGetAt(lIndex,1)); > tmp=QuerySetCell(qTmp,"User", listGetAt(lIndex,2)); > tmp=QuerySetCell(qTmp,"Document", listGetAt(lIndex,3)); > tmp=QuerySetCell(qTmp,"Status", listGetAt(lIndex,4)); > > > > > -Original Message- > From: ColdFusion Programmer [mailto:[EMAIL PROTECTED] > > Sent: 08 October 2003 11:32 > To: CF-Talk > Subject: Re:Looping through a list, setting each listItem to a >column > > > Craig, I tried running your code and get this error, > > Invalid list index 2. > In function ListGetAt(list, index [, delimiters]), the value of >index, 2, is not a valid as the first argument (this list has 1 >elements). Valid indexes are in the range 1 through the number of >elements in the list. > > Any ideas? > > >Try this.. > > > > > > > > > > > > > > > > > > tmp=QuerySetCell(qTmp,"DateTime", listGetAt(innerList,1)); > > tmp=QuerySetCell(qTmp,"User", listGetAt(innerList,2)); > > tmp=QuerySetCell(qTmp,"Document", listGetAt(innerList,3)); > > tmp=QuerySetCell(qTmp,"Status", listGetAt(innerList,4)); > > > > > > > > > > > > > >The listgetat function inside your inner loop is the only >change i've > >made > > > > -Original Message- > > From: Allan Clarke [mailto:[EMAIL PROTECTED] > > Sent: 08 October 2003 11:16 > > To: CF-Talk > > Subject: Looping through a list, setting each listItem to a > >column > > > > > > Hello Everybody, > > > > I am trying to read a log file and display the results > > on a webpage. > > Here is what the log file looks. > > > > DateTime User Webpage Visited Status > > 2003/09/01 11:52:15, "User\testUser1", > > "/wwwroot/code/article_1.shtml", "OK" > > 2003/09/01 11:53:35, "User\testUser2", > > "/wwwroot/code/article_2.shtml", "OK" > > 2003/09/01 12:04:55, "User\testUser3", > > "/wwwroot/code/article_3.shtml", "OK" > > 2003/09/01 12:04:58, "User\testUser4", > > "/wwwroot/code/article_4.shtml", "OK" > > 2003/09/01 12:05:11, "User\testUser5", > > "/wwwroot/code/article_5.shtml", "OK" > > > > Here is the code to read the log file > > > > action=""> > > file="C:\myLogFile.log" > > variable="fOutput"> > > > > Take a look at the code below. As you can see I am > > looping through the list, finding the Carriage Return > > character. > > This is all fine, what I want to be able to do is loop > > through each individual row which is again a comma > > seprated list > > > > (2003/09/01 11:52:15, "User\testUser1", > > "/wwwroot/code/article_1.shtml", "OK") append each > > list item in a temp table column. > > > > > > > > delimiters="#Chr(10)#"> > > > > > > > > > > delimiters=","> > > > > tmp=QuerySetCell(qTmp,"DateTime", innerList); > > tmp=QuerySetCell(qTmp,"User", innerList); > > tmp=QuerySetCell(qTmp,"Document", innerList); > > tmp=QuerySetCell(qTmp,"Status", innerList); > > > > > > > > > > > > > > SELECT DISTINCT * > > FROM qTmp > > > > > > The code above is not right, and I've tried hard to > > figure out how to loop through the inner comma > > separated list and assign the value to the query > > column. Can somebody > > please show me how to do this. I know my explaination > > is not very clear but I hope you know what I'm trying > > to do. > > If you think there is an easier way to do this then > > please let me know. Please can somebody help > > Regards > > John > > > > __ > > Do you Yahoo!? > > The New Yahoo! Shopping - with improved product search > > http://shopping.yahoo.com > > _ > > > > > _ > > [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
Re:Looping through a list, setting each listItem to a column
Craig, I tried running your code and get this error, Invalid list index 2. In function ListGetAt(list, index [, delimiters]), the value of index, 2, is not a valid as the first argument (this list has 1 elements). Valid indexes are in the range 1 through the number of elements in the list. Any ideas? >Try this.. > > > > > > > > > tmp=QuerySetCell(qTmp,"DateTime", listGetAt(innerList,1)); > tmp=QuerySetCell(qTmp,"User", listGetAt(innerList,2)); > tmp=QuerySetCell(qTmp,"Document", listGetAt(innerList,3)); > tmp=QuerySetCell(qTmp,"Status", listGetAt(innerList,4)); > > > > > > >The listgetat function inside your inner loop is the only change i've >made > > -Original Message- > From: Allan Clarke [mailto:[EMAIL PROTECTED] > Sent: 08 October 2003 11:16 > To: CF-Talk > Subject: Looping through a list, setting each listItem to a >column > > > Hello Everybody, > > I am trying to read a log file and display the results > on a webpage. > Here is what the log file looks. > > DateTime User Webpage Visited Status > 2003/09/01 11:52:15, "User\testUser1", > "/wwwroot/code/article_1.shtml", "OK" > 2003/09/01 11:53:35, "User\testUser2", > "/wwwroot/code/article_2.shtml", "OK" > 2003/09/01 12:04:55, "User\testUser3", > "/wwwroot/code/article_3.shtml", "OK" > 2003/09/01 12:04:58, "User\testUser4", > "/wwwroot/code/article_4.shtml", "OK" > 2003/09/01 12:05:11, "User\testUser5", > "/wwwroot/code/article_5.shtml", "OK" > > Here is the code to read the log file > > action=""> > file="C:\myLogFile.log" > variable="fOutput"> > > Take a look at the code below. As you can see I am > looping through the list, finding the Carriage Return > character. > This is all fine, what I want to be able to do is loop > through each individual row which is again a comma > seprated list > > (2003/09/01 11:52:15, "User\testUser1", > "/wwwroot/code/article_1.shtml", "OK") append each > list item in a temp table column. > > > > delimiters="#Chr(10)#"> > > > > > delimiters=","> > > tmp=QuerySetCell(qTmp,"DateTime", innerList); > tmp=QuerySetCell(qTmp,"User", innerList); > tmp=QuerySetCell(qTmp,"Document", innerList); > tmp=QuerySetCell(qTmp,"Status", innerList); > > > > > > > SELECT DISTINCT * > FROM qTmp > > > The code above is not right, and I've tried hard to > figure out how to loop through the inner comma > separated list and assign the value to the query > column. Can somebody > please show me how to do this. I know my explaination > is not very clear but I hope you know what I'm trying > to do. > If you think there is an easier way to do this then > please let me know. Please can somebody help > Regards > John > > __ > Do you Yahoo!? > The New Yahoo! Shopping - with improved product search > http://shopping.yahoo.com > _ > > [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]