Skip to main content
Inspiring
October 30, 2008
Question

Handle dbase error with default data (xml) ???

  • October 30, 2008
  • 4 replies
  • 352 views
I had MySQL decide to lose data and structure on me ( http://forums.mysql.com/read.php?22,58270,122989#msg-122989 fwiw) and thus had my dev site inoperable.

Consequently I am looking at putting <cfcatch> and <cftry> checks into all my cfc's <cfreturn> (whereby if error then return default array).

I don't know whether to do this by referencing an XML list (of default values) OR by creating an array in the <cfcatch>.

I'm pretty sure it can be done either way but what I guess I'm really asking is what the code would look like (I'm newbie beyond my level of obsession) as I haven't worked with either strategy as yet. Here is code to this point

<cftry> <!--- Return filenames from dbase --->
<cfreturn "#Filenames#"> <!--- If OK return array --->
<cfcatch type="any"> <!--- If ANY error --->

get XML and/or create array here ?????

<cfreturn "#Filenames#" > <!--- Return defaults --->
</cfcatch>
</cftry>

Thanks in advance
    This topic has been closed for replies.

    4 replies

    Inspiring
    October 31, 2008
    >
    > Thanks (again) in advance
    >

    You would use ColdFusion XML functions (xmlParse(), etc) to read the data.

    You would use ColdFusion Query functions (queryNew(), queryAddRow(),
    querySetCell(), etc.) to build a record set with the XML data.

    I would probably take a quick look at sources such as cflib.org to see
    if anybody has already built this.

    Inspiring
    October 30, 2008
    k, making some progress but am pretty perplexed re:

    XML to <cfquery>

    My dbase admin program can output a single row (resultset) as XML file:

    <data>
    <row>
    <CountryCode>CA</CountryCode>
    <floor>Warmth.jpg</floor>
    <wall>Chicago.jpg</wall>
    </row>
    </data>

    How do I get this into a cfquery result to send back (ie the xml file is to be saved on the cf server and accessed cfif the dbase is unavailable).

    Thanks (again) in advance
    Inspiring
    October 30, 2008
    <cfreturn Filenames4Grpahics>

    NOT

    <cfreturn "#FileName4Grphics#">
    <this tries to resolve FlieName4Graphics and return that value>
    Inspiring
    October 30, 2008
    . . . bump . . . . ;)

    Also though, I have tried creating an array for the default condition

    <cfset Filenames4Graphics=ArrayNew(1)>
    <cfset Filenames4Graphics[1]="Coleman">
    <cfset Filenames4Graphics[2]="Charlie">
    <cfset Filenames4Graphics[3]="Dexter">
    <cfreturn "#Filenames4Graphics#"> <!--- Return defaults --->

    but then am told (by the cfm page error) that:

    "The value returned from the ip2Country2Graphics function is not of type query" -- so to get a query result do I have to <cfquery> an XML list

    (though I did not mention it explicitly above, the idea being the xml list is saved somewhere on the cf server vs data coming from the dbase)