Reply to topic
Intermittent NULL Error
rkochanowski


Joined: 24 Nov 2004
Posts: 4
Location: Agawam, MA
Reply with quote
Hello all,

I have a dilema that I have not been able to rectify and am requesting your help. Following are the code snippets involved.

_rtbar.cfm is the file that initiates calls to the cfc's.
quoteData.cfc is the data interface
rtbarRotate.cfc is the mechanism that randomly rotates through the data

This code is very closely duplicated from WACK CF7, modified from the film example for my application of using quotations. Yet, whenever an update is made to the site (it seems) an error occurs that states that nulls are being passed and and the error points to quoteData.GetQuoteData (as indicated with a remark below.)

Now, as soon as I begin to pursue this I am no longer getting the errors. At any rate I am submitting this. Should you wish to look at the site it is at http://www.bethany-ag.org/pg_stewardship/

Thanks for any help that you can offer! And please forgive the length of this post.

Code:
<!---
    Filename: _rtbar.cfm
    Author: Ron Kochanowski 8/22/2007
    Purpose: handles the right sidebar information
--->

<div id="rtbar">

   <!---    
      if an instance of the Quote Rotator component hasn't been created
      yet, create a fresh instance and store it in the APPLICATION scope.
   --->
    <cfif not isDefined("APPLICATION.quoteRotator")>
       <cfobject component="stewCFCH47005.rtbarRotate" name="APPLICATION.quoteRotator">
   </cfif>
   
    <!---
      invoke the GetCurrentQuoteID() method of the quoteRotator object
   --->
    <cfinvoke component="#APPLICATION.quoteRotator#" method="getCurrentQuoteID" returnvariable="featuredQuoteID">
   
    <!---
      call the display method of the component
      the closing tag for cfinvoke is required here. if not present the argument is not passed to the compnent.
   --->
   
   <cfinvoke component="stewCFCH47005.quoteData" method="produceQuoteHTML">
      <cfinvokeargument name="rndQuoteID" value="#featuredQuoteID#"/>
    </cfinvoke>

</div>



Code:
<!---
    Filename: quoteData.cfc
    Author: Nate Weiss (NMW), modified by Ron Kochanowski 8/22/2007
    Purpose: Creates the quoteData ColdFusion Component, which provides
    search and data retrieval services for quotations in the BAG database.
--->

<!--- The <CFCOMPONENT> block defines the CFC --->
<!--- The filename of this file determines the CFC's name --->
<cfcomponent output="false"
   hint="Provides a simple interface for searching for and getting detailed
   information about quotes in the Bethany Assembly of God database.">

   <!--- ListQuotes() method --->
    <cffunction name="listQuotes" returnType="query"
       hint="Returns a query object containing quote information." output="false">
   
      <!--- Optional SearchString argument --->
        <cfargument name="searchString" type="string" required="No"
           hint="Optional search criteria; if not given, all quotes are returned.">
       
        <!--- var scope variables --->
        <cfset var getQuotes = "">
       
        <!--- Run the query --->
        <cfquery name="getQuotes" datasource="#REQUEST.dsn#">
           SELECT quoteID, subject, author, item
            FROM bagStewQuotes
           WHERE 0=0
           <!--- If a search string has been specified --->
           <cfif isDefined("ARGUMENTS.searchString")>
              AND (item LIKE '%#ARGUMENTS.searchString#%'
              OR subject LIKE '%#ARGUMENTS.searchString#%')
           </cfif>
        </cfquery>
       
        <!--- Return the query results --->
        <cfreturn getQuotes>
    </cffunction>
   
   
    <!--- GetQuoteData() method --->
    <cffunction name="getQuoteData" returnType="struct" output="false"
       hint="Returns structured information about the specified quote.">
   
      <!--- quoteID argument --->
        <cfargument name="rndQuoteID" type="numeric" required="Yes"
           hint="The quote that you want information about.">
       
        <!--- This is what this method originally returns --->
        <!--- The var keyword makes it local to the method --->
        <cfset var quoteData = structNew()>
        <cfset var getQuote = "">
       
        <cfset quoteData.quoteID = trim(ARGUMENTS.rndQuoteID)>
       
        <!--- Select data about the quote from the database --->
        <cfquery name="getQuote" datasource="#REQUEST.dsn#">
           SELECT subject, item, author
            FROM bagStewQuotes
           WHERE quoteID = #ARGUMENTS.rndQuoteID#      <!---the error continues to point here.  is a blank id being passed?--->
        </cfquery>
       
        <!--- Populate the QuoteData structure with quote info --->
        <cfset quoteData.subject = trim(getQuote.subject)>
        <cfset quoteData.item = trim(getQuote.item)>
        <cfset quoteData.author = trim(getQuote.author)>
       
        <!--- Return the final structure --->
        <cfreturn QuoteData>
    </cffunction>
   
   
    <!--- ProduceQuoteHTML() method --->
    <cffunction name="produceQuoteHTML" access="remote" output="true" returntype="void"
       hint="Produces a simple HTML display">
   
      <!--- QuoteID argument --->
        <cfargument name="rndQuoteID" type="numeric" required="Yes" hint="The ID number of the quote to display information about">
       
        <!--- Call the GetQuoteData() method to get basic quote information --->
        <cfset var quoteData = getQuoteData(#ARGUMENTS.rndQuoteID#)>
       
        <!--- Produce the simple quotation display --->
        <cfoutput>
         <cfif #quoteData.subject# NEQ "">
               <h2>#quoteData.subject#</h2>
            </cfif>
            <p>#quoteData.item#</p>
            <cfif #quoteData.author# NEQ "">
               <h4>#quoteData.author#</h4>
            </cfif>
        </cfoutput>
       
    </cffunction>

</cfcomponent>


Code:
<!---
 Filename: rtbarRotate.cfc
 Author: Nate Weiss (NMW), adjusted by Ron Kochanowski
 Purpose: Creates rtbarRotate, a ColdFusion Component that rotates through quotes
--->

<cfcomponent output="false">

   <!--- *** begin initialization code *** --->
    <cfset THIS.quoteList = randomizedQuoteList()>
    <cfset THIS.currentListPos = 1>
    <cfset THIS.rotationInterval = 5>
    <cfset THIS.currentUntil = dateAdd("s", THIS.rotationInterval, now())>
    <!--- *** end initialization code *** --->
   
   
<!--- Private function: RandomizedQuoteList() --->
    <cffunction name="randomizedQuoteList" returnType="string" access="private" output="false"
       hint="For internal use. Returns a list of all Quote IDs, in random order.">

      <!--- This variable is for this function's use only --->
        <cfset var getQuoteIDs = "">
       
        <!--- Retrieve list of current quotes from database --->
        <cfquery name="getQuoteIDs" datasource="#REQUEST.dsn#" cachedwithin="#CreateTimeSpan(0,1,0,0)#">
         SELECT quoteID
            FROM bagStewQuotes
      </cfquery>

      <!--- Return the list of quotes, in random order --->
        <cfreturn listRandomize(valueList(getQuoteIDs.quoteID))>
   </cffunction>

<!--- Private utility function: ListRandomize() --->
   <cffunction name="listRandomize" returnType="string" output="false"
      hint="Randomizes the order of the items in any comma-separated list.">

      <!--- List argument --->
      <cfargument name="list" type="string" required="Yes" hint="The string that you want to randomize.">

      <!--- These variables are for this function's use only --->
        <cfset var result = "">
        <cfset var randPos = "">
   
      <!--- While there are items left in the original list... --->
        <cfloop condition="listLen(ARGUMENTS.list) gt 0">
            <!--- Select a list position at random --->
            <cfset randPos = randRange(1, listLen(ARGUMENTS.list))>
            <!--- Add the item at the selected position to the Result list --->
            <cfset result = listAppend(result, listGetAt(ARGUMENTS.list, randPos))>
            <!--- Remove the item from selected position of the original list --->
            <cfset ARGUMENTS.list = listDeleteAt(ARGUMENTS.list, randPos)>
        </cfloop>

      <!--- Return the reordered list --->
        <cfreturn result>
   </cffunction>

<!--- Private method: IsQuoteNeedingRotation() --->
    <cffunction name="isQuoteNeedingRotation" access="private" returnType="boolean" output="false"
       hint="For internal use. Returns TRUE if the quote should be rotated now.">
   
      <!--- Compare the current time to the THIS.CurrentUntil time --->
        <!--- If the quote is still current, DateCompare() will return 1 --->
        <cfset var dateComparison = dateCompare(THIS.currentUntil, now())>
       
        <!--- Return TRUE if the quote is still current, FALSE otherwise --->
        <cfreturn dateComparison neq 1>
    </cffunction>
   
<!--- Private method: RotateQuote() --->
    <cffunction name="rotateQuote" access="private" returnType="void" output="false"
       hint="For internal use. Advances the current quotation.">
   
      <!--- If the quote needs to be rotated at this time... --->
        <cfif isQuoteNeedingRotation()>
         <!--- Advance the instance-level THIS.CurrentListPos value by one --->
            <cfset THIS.currentListPos = THIS.currentListPos + 1>
           
            <!--- If THIS.CurrentListPos is now more than the number of quotes, --->
            <!--- Start over again at the beginning (the first quote) --->
            <cfif THIS.currentListPos gt listLen(THIS.QuoteList)>
            <cfset THIS.currentListPos = 1>
            </cfif>
               
            <!--- Set the time that the next rotation will be due --->
            <cfset THIS.currentUntil = dateAdd("s", THIS.rotationInterval, now())>
        </cfif>
    </cffunction>
   
<!--- Private method: CurrentQuoteID() --->
    <cffunction name="currentQuoteID" access="private" returnType="numeric" output="false"
       hint="For internal use. Returns the ID of the current quote in rotation.">
   
      <!--- Return the QuoteID from the current row of the GetQuoteIDs query --->
        <cfreturn listGetAt(THIS.quoteList, THIS.currentListPos)>
    </cffunction>
   
<!--- Public method: GetCurrentQuoteID() --->
    <cffunction name="getCurrentQuoteID" access="public" returnType="numeric" output="false"
        hint="Returns the ID number of the currently 'featured' quote.">
        <!--- First, rotate the current quote --->
        <cfset rotateQuote()>
       
        <!--- Return the ID of the current quote --->
        <cfreturn currentQuoteID()>
    </cffunction>
   
<!--- Public method: GetCurrentQuoteData() --->
    <cffunction name="getCurrentQuoteData" access="remote" returnType="struct" output="false"
       hint="Returns structured data about the currently 'featured' quote.">
   
      <!--- This variable is local just to this function --->
        <cfset var currentQuoteData = "">
       
        <!--- Invoke the GetCurrentQuoteID() method (in separate component) --->
        <!--- Returns a structure with quote's subject, author, and text --->
        <cfinvoke component="quoteData" method="getQuoteData"
           quoteID="#getCurrentQuoteID()#" returnVariable="currentQuoteData">
       
        <!--- Return the structure --->
        <cfreturn currentQuoteData>
    </cffunction>

</cfcomponent>
Code:
nathacof


Joined: 24 Oct 2006
Posts: 93
Location: Bear, DE
Reply with quote
Are you using MySQL on ColdFusion 8?

If so are any of your column types TIMESTAMPS?

If so we can add a connection string option to your DSN to convert empty timestamps to null which normally clears up these issues.
rkochanowski


Joined: 24 Nov 2004
Posts: 4
Location: Agawam, MA
Reply with quote
Nathan,

Thanks for looking into this. No TIMESTAMP fields, I do have a DATE field set with a default of '0000-00-00'.

Ron
nathacof


Joined: 24 Oct 2006
Posts: 93
Location: Bear, DE
Reply with quote
I think it's time to investigate your DSN. File a support request and let them know your symptoms and we should be able to straighten things out.

This has been affecting a large number of our customers since the CF8 upgrades.
Intermittent NULL Error
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic