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