PageRenderTime 40ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/wheels/model/adapters/H2.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 102 lines | 90 code | 10 blank | 2 comment | 4 complexity | f19f2f2fd2ff8b919c575e886c8df9f7 MD5 | raw file
Possible License(s): Apache-2.0, CPL-1.0
  1. <cfcomponent extends="Base" output="false">
  2. <cffunction name="$generatedKey" returntype="string" access="public" output="false">
  3. <cfreturn "generated_key">
  4. </cffunction>
  5. <cffunction name="$randomOrder" returntype="string" access="public" output="false">
  6. <cfreturn "RAND()">
  7. </cffunction>
  8. <cffunction name="$getType" returntype="string" access="public" output="false">
  9. <cfargument name="type" type="string" required="true">
  10. <cfscript>
  11. var loc = {};
  12. switch(arguments.type)
  13. {
  14. case "bigint": case "int8": {loc.returnValue = "cf_sql_bigint"; break;}
  15. case "binary": case "bytea": case "raw": {loc.returnValue = "cf_sql_binary"; break;}
  16. case "bit": case "bool": case "boolean": {loc.returnValue = "cf_sql_bit"; break;}
  17. case "blob": case "tinyblob": case "mediumblob": case "longblob": case "image": case "oid": {loc.returnValue = "cf_sql_blob"; break;}
  18. case "char": case "character": case "nchar": {loc.returnValue = "cf_sql_char"; break;}
  19. case "date": {loc.returnValue = "cf_sql_date"; break;}
  20. case "dec": case "decimal": case "number": case "numeric": {loc.returnValue = "cf_sql_decimal"; break;}
  21. case "double": {loc.returnValue = "cf_sql_double"; break;}
  22. case "float": case "float4": case "float8": case "real": {loc.returnValue = "cf_sql_float"; break;}
  23. case "int": case "int4": case "integer": case "mediumint": case "signed": {loc.returnValue = "cf_sql_integer"; break;}
  24. case "int2": case "smallint": case "year": {loc.returnValue = "cf_sql_smallint"; break;}
  25. case "time": {loc.returnValue = "cf_sql_time"; break;}
  26. case "datetime": case "smalldatetime": case "timestamp": {loc.returnValue = "cf_sql_timestamp"; break;}
  27. case "tinyint": {loc.returnValue = "cf_sql_tinyint"; break;}
  28. case "varbinary": case "longvarbinary": {loc.returnValue = "cf_sql_varbinary"; break;}
  29. case "varchar": case "varchar2": case "longvarchar": case "varchar_ignorecase": case "nvarchar": case "nvarchar2": case "clob": case "nclob": case "text": case "tinytext": case "mediumtext": case "longtext": case "ntext": {loc.returnValue = "cf_sql_varchar"; break;}
  30. }
  31. </cfscript>
  32. <cfreturn loc.returnValue>
  33. </cffunction>
  34. <cffunction name="$query" returntype="struct" access="public" output="false">
  35. <cfargument name="sql" type="array" required="true">
  36. <cfargument name="limit" type="numeric" required="false" default=0>
  37. <cfargument name="offset" type="numeric" required="false" default=0>
  38. <cfargument name="parameterize" type="boolean" required="true">
  39. <cfargument name="$primaryKey" type="string" required="false" default="">
  40. <cfscript>
  41. var loc = {};
  42. arguments.sql = $removeColumnAliasesInOrderClause(arguments.sql);
  43. arguments.sql = $addColumnsToSelectAndGroupBy(arguments.sql);
  44. loc.returnValue = $performQuery(argumentCollection=arguments);
  45. </cfscript>
  46. <cfreturn loc.returnValue>
  47. </cffunction>
  48. <cffunction name="$identitySelect" returntype="any" access="public" output="false">
  49. <cfargument name="queryAttributes" type="struct" required="true">
  50. <cfargument name="result" type="struct" required="true">
  51. <cfargument name="primaryKey" type="string" required="true">
  52. <cfset var loc = {}>
  53. <cfset var query = {}>
  54. <cfset loc.sql = Trim(arguments.result.sql)>
  55. <cfif Left(loc.sql, 11) IS "INSERT INTO" AND NOT StructKeyExists(arguments.result, $generatedKey())>
  56. <cfset loc.startPar = Find("(", loc.sql) + 1>
  57. <cfset loc.endPar = Find(")", loc.sql)>
  58. <cfset loc.columnList = ReplaceList(Mid(loc.sql, loc.startPar, (loc.endPar-loc.startPar)), "#Chr(10)#,#Chr(13)#, ", ",,")>
  59. <cfif NOT ListFindNoCase(loc.columnList, ListFirst(arguments.primaryKey))>
  60. <cfset loc.returnValue = {}>
  61. <cfquery attributeCollection="#arguments.queryAttributes#">SELECT LAST_INSERT_ID() AS lastId</cfquery>
  62. <cfset loc.returnValue[$generatedKey()] = query.name.lastId>
  63. <cfreturn loc.returnValue>
  64. </cfif>
  65. </cfif>
  66. </cffunction>
  67. <cffunction name="$getColumns" returntype="query" access="public" output="false">
  68. <cfscript>
  69. var loc = {};
  70. // get column details using cfdbinfo in the base adapter
  71. loc.columns = super.$getColumns(argumentCollection=arguments);
  72. // since cfdbinfo incorrectly returns information_schema tables we need to create a new query result that excludes these tables
  73. loc.returnValue = QueryNew(loc.columns.columnList);
  74. loc.iEnd = loc.columns.recordCount;
  75. for (loc.i=1; loc.i <= loc.iEnd; loc.i++)
  76. {
  77. if (loc.columns["table_schem"][loc.i] != "information_schema")
  78. {
  79. QueryAddRow(loc.returnValue);
  80. loc.jEnd = ListLen(loc.columns.columnList);
  81. for (loc.j=1; loc.j <= loc.jEnd; loc.j++)
  82. {
  83. loc.columnName = ListGetAt(loc.columns.columnList, loc.j);
  84. QuerySetCell(loc.returnValue, loc.columnName, loc.columns[loc.columnName][loc.i]);
  85. }
  86. }
  87. }
  88. return loc.returnValue;
  89. </cfscript>
  90. </cffunction>
  91. <cfinclude template="../../plugins/injection.cfm">
  92. </cfcomponent>