PageRenderTime 10ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/wheels/model/adapters/MySQL.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 78 lines | 70 code | 8 blank | 0 comment | 0 complexity | 8db1c79d8e8ce7cb03e5b64e4c34d6e1 MD5 | raw file
 1<cfcomponent extends="Base" output="false">
 2
 3	<cffunction name="init" access="public" returntype="any" output="false">
 4		<cfreturn super.init(argumentCollection=arguments)>
 5	</cffunction>
 6
 7	<cffunction name="$generatedKey" returntype="string" access="public" output="false">
 8		<cfreturn "generated_key">
 9	</cffunction>
10	
11	<cffunction name="$randomOrder" returntype="string" access="public" output="false">
12		<cfreturn "RAND()">
13	</cffunction>
14	
15	<cffunction name="$getType" returntype="string" access="public" output="false">
16		<cfargument name="type" type="string" required="true">
17		<cfscript>
18			var loc = {};
19			switch(arguments.type)
20			{
21				case "bigint": {loc.returnValue = "cf_sql_bigint"; break;}
22				case "binary": {loc.returnValue = "cf_sql_binary"; break;}
23				case "bit": case "bool": {loc.returnValue = "cf_sql_bit";	break;}
24				case "blob": case "tinyblob": case "mediumblob": case "longblob": {loc.returnValue = "cf_sql_blob";	break;}
25				case "char": {loc.returnValue = "cf_sql_char"; break;}
26				case "date": {loc.returnValue = "cf_sql_date"; break;}
27				case "decimal": {loc.returnValue = "cf_sql_decimal"; break;}
28				case "double": {loc.returnValue = "cf_sql_double"; break;}
29				case "float": {loc.returnValue = "cf_sql_float"; break;}
30				case "int": case "mediumint": {loc.returnValue = "cf_sql_integer"; break;}
31				case "smallint": case "year": {loc.returnValue = "cf_sql_smallint"; break;}
32				case "time": {loc.returnValue = "cf_sql_time"; break;}
33				case "datetime": case "timestamp": {loc.returnValue = "cf_sql_timestamp"; break;}
34				case "tinyint": {loc.returnValue = "cf_sql_tinyint"; break;}
35				case "varbinary": {loc.returnValue = "cf_sql_varbinary"; break;}
36				case "varchar": case "text": case "mediumtext": case "longtext": case "tinytext": case "enum": case "set": {loc.returnValue = "cf_sql_varchar"; break;}
37			}
38		</cfscript>
39		<cfreturn loc.returnValue>
40	</cffunction>
41	
42	<cffunction name="$query" returntype="struct" access="public" output="false">
43		<cfargument name="sql" type="array" required="true">
44		<cfargument name="limit" type="numeric" required="false" default=0>
45		<cfargument name="offset" type="numeric" required="false" default=0>
46		<cfargument name="parameterize" type="boolean" required="true">
47		<cfargument name="$primaryKey" type="string" required="false" default="">
48		<cfscript>
49			var loc = {};
50			arguments.sql = $removeColumnAliasesInOrderClause(arguments.sql);
51			loc.returnValue = $performQuery(argumentCollection=arguments);
52		</cfscript>
53		<cfreturn loc.returnValue>
54	</cffunction>
55	
56	<cffunction name="$identitySelect" returntype="any" access="public" output="false">
57		<cfargument name="queryAttributes" type="struct" required="true">
58		<cfargument name="result" type="struct" required="true">
59		<cfargument name="primaryKey" type="string" required="true">
60		<cfset var loc = {}>
61		<cfset var query = {}>
62		<cfset loc.sql = Trim(arguments.result.sql)>
63		<cfif Left(loc.sql, 11) IS "INSERT INTO" AND NOT StructKeyExists(arguments.result, $generatedKey())>
64			<cfset loc.startPar = Find("(", loc.sql) + 1>
65			<cfset loc.endPar = Find(")", loc.sql)>
66			<cfset loc.columnList = ReplaceList(Mid(loc.sql, loc.startPar, (loc.endPar-loc.startPar)), "#Chr(10)#,#Chr(13)#, ", ",,")>
67			<cfif NOT ListFindNoCase(loc.columnList, ListFirst(arguments.primaryKey))>
68				<cfset loc.returnValue = {}>
69				<cfquery attributeCollection="#arguments.queryAttributes#">SELECT LAST_INSERT_ID() AS lastId</cfquery>
70				<cfset loc.returnValue[$generatedKey()] = query.name.lastId>
71				<cfreturn loc.returnValue>
72			</cfif>
73		</cfif>
74	</cffunction>
75
76	<cfinclude template="../../plugins/injection.cfm">
77
78</cfcomponent>