virtix / cfcrypto

cipher stuff for coldfusion

cfcrypto / querysim.cfm
100644 88 lines (69 sloc) 2.285 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
 
<!--------------------------------------------------------------------
Original QuerySim.cfm by hal.helms@TeamAllaire.com
Update by bill s. - 04.09.2009
 
This will only work in ColdFusion 8 and later due to conditional
syntax usage - && in lieu of AND, and i++, etc.
 
This decouples string parsing logic into a somewhat testable function.
For some reason, the orginal was throwing a list parsing exception on
what appeared to be normal text. So, it was dissasembled and i decided
to use java's String.split(regex) instead.
 
Note, one possibly major omission from the original is the lack of
reading querysim info from a profile file; ie, .ini. This was omitted
because 'i' don't use that.
--------------------------------------------------------------------->
 
<cfsetting enablecfoutputonly="yes">
<cfscript>
 local.queryName = '';
 local.raw = '';
 local.q = chr(0);
 
 if (thistag.HasEndTag and thistag.ExecutionMode is 'start'){
//no worries
 }
 
 else if (thistag.HasEndTag and thistag.ExecutionMode is 'end'){
   local.raw = trim( Thistag.generatedContent );
thistag.generatedContent = '';
   local.q = parse(local.raw);
   setVariable( 'caller.' & local.queryName, local.q );
 }
 
 
function parse(input){
   var s = trim(input);
   var lines = s.split('\n');
   var line = '';
   var i = 1;
   var j = 1;
   var columnListLine = -1;
   var queryName = '';
   var columnList = '';
   var q = '';
   var row = '';
 
  for(i; i <= arrayLen(lines); i ++ ){
     line = lines[i];
 
     //to do: simply ignore blank lines or lines with only whitespace.
     //if ( refind ( line, '^[[:space:]]*$' ) ) continue;
 
     if(line != '' && queryName == '') {
         queryName = lines[i];
         setQueryName(queryName);
         columnListLine = i+1;
         continue;
     }
 
     if(i == columnListLine) {
       columnList = lines[i];
       q = queryNew(columnList);
       continue;
     }
 
     if(line != ''){
      row = line.split("\|");
queryAddRow(q);
for(j=1; j <= arrayLen(row); j++){
if(j <= listLen(columnList)) querySetCell(q, listGetAt(columnList,j) ,row[j]);
}
       continue;
     }
 
   }//end for()
 
   return q;
  } //end parse()
 
 
  function setQueryName(qName){
    local.queryName = qName;
  }
 
</cfscript>
<cfsetting enablecfoutputonly="No">