Last active
March 16, 2016 00:03
-
-
Save roryl/0b45eb21342466f5243d to your computer and use it in GitHub Desktop.
Lucee Query Object Examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
myQuery = queryNew("col1,col2,col3"); | |
myQuery.addColumn("col4", ["foo","bar","baz"]); | |
dump(myQuery); | |
</cfscript> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
myQuery = queryNew("col1,col2,col3"); | |
myQuery.addRow(["foo","bar","baz"]); | |
dump(myQuery); | |
</cfscript> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
myQuery = queryNew(columns="col1,col2,col3", | |
data=[ | |
["one","two","three"], | |
["foo","bar","baz"], | |
["i","am","query"] | |
]); | |
dump(myQuery.columnData("col1")); | |
</cfscript> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
myQuery = queryNew(columns="col1,col2,col3", | |
data=[ | |
["one","two","three"], | |
["foo","bar","baz"], | |
["i","am","query"] | |
]); | |
dump(myQuery); | |
</cfscript> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
myQuery = queryNew("col1,col2,col3"); | |
dump(myQuery); | |
</cfscript> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
myQuery = queryNew(columns="col1,col2,col3", | |
data=[ | |
["one","two","three"], | |
["foo","bar","baz"], | |
["i","am","query"] | |
]); | |
for(row in myQuery){ | |
writeDump(row); //Dumps a structure representing the row | |
echo(row.col1); //output the col1 value of this row | |
echo(row.col2); //output the col2 value of this row | |
echo(row.col3) //output the col3 value of this row | |
} | |
</cfscript> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
myQuery = queryNew(columns="col1,col2,col3", | |
data=[ | |
["one","two","three"], | |
["foo","bar","baz"], | |
["i","am","query"] | |
]); | |
for(i = 1; i <= myQuery.recordCount(); i++){ | |
echo(myQuery.col1[i]); //output the col1 value of this row | |
echo(myQuery.col2[i]); //output the col2 value of this row | |
echo(myQuery.col3[i]) //output the col3 value of this row | |
} | |
</cfscript> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
myQuery = queryNew(columns="col1,col2,col3", | |
data=[ | |
["one","two","three"], | |
["foo","bar","baz"], | |
["i","am","query"] | |
]); | |
loop query="myQuery" index="i"{ | |
echo(col1); //output the col1 value of this row | |
echo(col2); //output the col2 value of this row | |
echo(col3) //output the col3 value of this row | |
} | |
</cfscript> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
myQuery = queryNew(columns="col1,col2,col3", | |
data=[ | |
["one","two","three"], | |
["foo","bar","baz"], | |
["ford","chevy","kia"], | |
["hyundai","vw","toyota"], | |
["banana","berry","apple"], | |
["coffee","water","soda"] | |
]); | |
loop query="myQuery" startrow="2" maxrows="2"{ | |
echo(col1 & " | "); //output the col1 value of this row | |
echo(col2 & " | "); //output the col2 value of this row | |
echo(col3 & " | "); //output the col3 value of this row | |
echo("<br />"); | |
} | |
</cfscript> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
myQuery = queryNew(columns="col1,col2,col3", | |
data=[ | |
["one","two","three"], | |
["foo","bar","baz"], | |
["i","am","query"] | |
]); | |
query name="filterQuery" dbtype="query" { | |
echo("Select col2 from myQuery"); | |
} | |
writeDump(filterQuery); | |
query name="filterQuery" dbtype="query" { | |
echo("Select * from myQuery where col2 = 'am'"); | |
} | |
writeDump(filterQuery); | |
</cfscript> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
myQuery = queryNew(columns="col1,col2,col3", | |
data=[ | |
["one","two","three"], | |
["foo","bar","baz"], | |
["i","am","query"] | |
]); | |
echo(myQuery.col2[3]); //outputs col2 row 3, "am" | |
echo(myQuery.col1[2]); //outputs col1 row 2, "foo" | |
</cfscript> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
myQuery = queryNew(columns="col1,col2,col3", | |
data=[ | |
["one","two","three"], | |
["foo","bar","baz"], | |
["i","am","query"] | |
]); | |
dump(myQuery.rowData(2)); | |
</cfscript> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
myQuery = queryNew(columns="col1,col2,col3", | |
data=[ | |
["one","two","three"], | |
["foo","bar","baz"], | |
["i","am","query"] | |
]); | |
myQuery.setCell("col2", "hello"); //sets the last row of this column | |
myQuery.setCell("col2", "there", 2); //Sets the specific row of this column | |
dump(myQuery); | |
</cfscript> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* My xUnit Test | |
*/ | |
component extends="testbox.system.BaseSpec"{ | |
/*********************************** LIFE CYCLE Methods ***********************************/ | |
// executes before all test cases | |
function beforeTests(){ | |
} | |
// executes after all test cases | |
function afterTests(){ | |
} | |
// executes before every test case | |
function setup( currentMethod ){ | |
} | |
// executes after every test case | |
function teardown( currentMethod ){ | |
} | |
/*********************************** TEST CASES BELOW ***********************************/ | |
// Remember that test cases MUST start or end with the keyword 'test' | |
function checkAllSyntaxTest(){ | |
var files = directoryList(""); | |
for(file IN files){ | |
if(file CONTAINS ".cfm"){ | |
include template="#getFileFromPath(file)#"; | |
} | |
} | |
} | |
function queryLoopTest(){ | |
include template="query_loop.cfm"; | |
} | |
function queryLoopAttributesTest(){ | |
include template="query_loop_attributes.cfm"; | |
} | |
function queryOfQueriesTest(){ | |
include template="query_of_queries.cfm"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment