As to executing a query within cfscript
Know you can't --- but you can fudge it
create a function (or CFC that issues the query based on a string
passed to it. The string contains the SQL statements).
within the script tag invoke the function which returns the record set
Howie Hamlin had a thread on this earlier today.
BTW, It is generally thought to be a good idea to generalize this
approach and put all your db calls into CFCs ( code reusability). I
have even seen recommendations that you write these CFCs like like OOP
objects with getters and setters for each field in the db. I don't
know if that level of implementation is warranted on most projects.
But I do find it useful to gather all my queries into a CFC (or CFCs)
where a function has a default columnlist and action that can be
overridden when the function is called.
Dick
On Aug 18, 2004, at 2:03 PM, Ray Champagne wrote:
> So, I have a question after playing around with this (wow is it much
> faster
> than the easycfm way!):
>
> I read up a little on cfscript, is it really true that there is no
> way to
> use SQL queries inside a cfscript block?��I am VERY new to cfscript,
> but I
> thought that there was a way that has been mentioned in here
> before.��This
> method is not going to do me much good if I can't parse out and put
> vals in
> the DB...
>
> Thanks Dick, this is pretty cool...
>
> Ray
>
> At 03:50 PM 8/18/2004, you wrote:
> >Ray, here's the line reader that Joe Rinehart suggested (with a
> slight
> >mod).
> >
> >Enjoy!
> >
> >Dick
> >
> >���Hey Joe
> >
> >���Your No Class Reader Works Great!
> >
> >���much faster than the other! (almost as fast as a cffile read of
> >���the
> >���entire file).
> >
> >���I simplified the EOF test so I could use a While loop.
> >
> >���Thanks
> >
> >���Dick
> >
> >���Here's the revised code:
> >
> >���<cfsetting enableCFOutputOnly="yes" />
> >���<cfset lineCount = 0 />
> >
> >���<cfset timer = GetTickCount() />
> >
> >���<cfscript>
> >������filename = "/Users/Richard/Music/iTunes/iTunes Music
> Library.xml";
> >������fileReader = createObject("java", "java.io.FileReader");
> >������fileReader = fileReader.init(filename);
> >������lineReader = createObject("java","java.io.LineNumberReader");
> >������lineReader = lineReader.init(fileReader);
> >
> >������thisLine = true;
> >������while (isDefined("thisLine")) {
> >��������thisLine = lineReader.readLine();
> >��������lineCount = LineCount + 1; // do any processing of the line
> here
> >������}
> >
> >���</cfscript>
> >
> >���<cfoutput>
> >���<br>count = #lineCount# | #GetTickCount() - timer#
> >���</cfoutput>
> >���<cfsetting enableCFOutputOnly="no" />
> >
> >���I always forget to kill blank lines��on this sort of thing --
> >���very
> >���important
> >
> >���On Jun 16, 2004, at 6:28 AM, Joe Rinehart wrote:
> >
> >���> Hey Dick,
> >���>
> >���>��I've done a similar thing, but didn't create the external
> >���>��CFBufferedReader class. Do you see any reason why the
> >���following
> >���> wouldn't
> >���>��provide the same?
> >���>
> >���>��<cfscript>
> >���>��� filename = "c:\cfusionmx\wwwroot\lineNumberReader.cfm";
> >���>��fileReader = createObject("java", "java.io.FileReader");
> >���>��fileReader = fileReader.init(filename);
> >���>��lineReader = createObject("java","java.io.LineNumberReader");
> >���>��lineReader = lineReader.init(fileReader);
> >���>��</cfscript>
> >���>
> >���>��<cfset eof = false>
> >���>��<cfloop condition="not eof">
> >���>��� <cfset thisLine = lineReader.readLine()>
> >���>��� <cfif not isDefined("thisLine")>
> >���>������<cfset eof = true>
> >���>��� <cfelse>
> >���>������<cfoutput>#htmlEditFormat(thisLine)#<br></cfoutput>
> >���>��� </cfif>
> >���>��</cfloop>
> >���>
> >���>��(when��lineReader instance hits the end of the file,
> >���readLine()
> >���> returns
> >���>��a result that causes thisLine to become undefined in the eyes
> >���of��CF)
> >���>
> >���>��-joe
> >���>
> >�����_____
> >
> >
> >
>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

