PageRenderTime 30ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/wheels/tests/model/sql/whereclause.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 57 lines | 49 code | 8 blank | 0 comment | 0 complexity | 13cfce8471f484eab0aff412d8aa83d9 MD5 | raw file
Possible License(s): Apache-2.0, CPL-1.0
  1. <cfcomponent extends="wheelsMapping.Test">
  2. <cffunction name="test_numeric_operators">
  3. <cfset operators = "=,<>,!=,<,<=,!<,>,>=,!>">
  4. <cfloop list="#operators#" index="i">
  5. <cfset check = "Len(result[2]) IS (11+#Len(i)#) AND ArrayLen(result) IS 3 AND result[3].type IS 'cf_sql_integer' AND Right(result[2], #Len(i)#) IS '#i#'">
  6. <cfset result = model("author").$whereClause(where="id#i#0")>
  7. <cfset assert(check)>
  8. <cfset result = model("author").$whereClause(where="id#i# 11")>
  9. <cfset assert(check)>
  10. <cfset result = model("author").$whereClause(where="id #i#999")>
  11. <cfset assert(check)>
  12. </cfloop>
  13. </cffunction>
  14. <cffunction name="test_in_like_operators">
  15. <cfset result = model("author").$whereClause(where="id IN (1,2,3)")>
  16. <cfset assert("Right(result[2], 2) IS 'IN'")>
  17. <cfset result = model("author").$whereClause(where="id NOT IN (1,2,3)")>
  18. <cfset assert("Right(result[2], 6) IS 'NOT IN'")>
  19. <cfset result = model("author").$whereClause(where="lastName LIKE 'Djurner'")>
  20. <cfset assert("Right(result[2], 4) IS 'LIKE'")>
  21. <cfset result = model("author").$whereClause(where="lastName NOT LIKE 'Djurner'")>
  22. <cfset assert("Right(result[2], 8) IS 'NOT LIKE'")>
  23. </cffunction>
  24. <cffunction name="test_floats">
  25. <cfset result = model("post").$whereClause(where="averagerating IN(3.6,3.2)")>
  26. <cfset assert('arraylen(result) gte 4')>
  27. <cfset assert('isstruct(result[4])')>
  28. <cfset assert('result[4].datatype eq "float" OR result[4].datatype eq "float8" OR result[4].datatype eq "double" OR result[4].datatype eq "number"')>
  29. <cfset result = model("post").$whereClause(where="averagerating NOT IN(3.6,3.2)")>
  30. <cfset assert('arraylen(result) gte 4')>
  31. <cfset assert('isstruct(result[4])')>
  32. <cfset assert('result[4].datatype eq "float" OR result[4].datatype eq "float8" OR result[4].datatype eq "double" OR result[4].datatype eq "number"')>
  33. <cfset result = model("post").$whereClause(where="averagerating = 3.6")>
  34. <cfset assert('arraylen(result) gte 4')>
  35. <cfset assert('isstruct(result[4])')>
  36. <cfset assert('result[4].datatype eq "float" OR result[4].datatype eq "float8" OR result[4].datatype eq "double" OR result[4].datatype eq "number"')>
  37. </cffunction>
  38. <cffunction name="test_is_null">
  39. <cfset result = model("post").$whereClause(where="averagerating IS NULL")>
  40. <cfset assert('arraylen(result) gte 4')>
  41. <cfset assert('isstruct(result[4])')>
  42. <cfset result = model("post").$whereClause(where="averagerating IS NOT NULL")>
  43. <cfset assert('arraylen(result) gte 4')>
  44. <cfset assert('isstruct(result[4])')>
  45. <cfset assert('result[4].datatype eq "float" OR result[4].datatype eq "float8" OR result[4].datatype eq "double" OR result[4].datatype eq "number"')>
  46. </cffunction>
  47. <cffunction name="test_should_allow">
  48. </cffunction>
  49. </cfcomponent>