How about a table with two columns 'name', and 'counter', used to generate
sequential numbers for each name.  Wrap it with a one-method CFC (untested
example code below), and then use getNextNumber(tableName) in your INSERT
queries.  Little more work, but it'll make for much nicer URLs, and better
front-size performance as well.

<cffunction name="getNextNumber">
  <cfargument name="counter" />
  <cfset var get = "" />
  <cftransaction isolation="serializable">
    <cfquery datasource="#variables.my.dsn#">
      UPDATE counter SET
        counter = counter + 1
      WHERE name = <cfqueryparam cfsqltype="cf_sql_varchar"
value="#counter#" />
    </cfquery>
    <cfquery datasource="#variables.my.dsn#" name="get">
      SELECT counter
      FROM counter
      WHERE name = <cfqueryparam cfsqltype="cf_sql_varchar"
value="#counter#" />
    </cfquery>
  </cftransaction>
  <cfif get.recordCount EQ 0>
    <cfquery datasource="#variables.my.dsn#">
      INSERT INTO counter
        (name, counter)
      VALUES
        (<cfqueryparam cfsqltype="cf_sql_varchar" value="#counter#" />, 0)
    </cfquery>
    <cfreturn getNextNumber(counter) />
  </cfif>
  <cfreturn get.counter />
</cffunction>

Cheers,
barneyb

> -----Original Message-----
> From: Raymond Camden [mailto:[EMAIL PROTECTED]
> Sent: Monday, June 28, 2004 3:04 PM
> To: CF-Talk
> Subject: Re: Raymond's Blog for Bluedragon
>
> Heh, can't help it. It was my easy way of handling PKs for
> multiple DBs
> using the simplest set of code. :) For some reason the blog
> has gotten
> lot of coverage over the last week and I've gotten a lot of good
> feedback on it. I'm going to try to get together a new release in the
> next month. Specifically I want to add support for N blogs
> per DSN and N
> authors per blog.
>
> -Ray (still trying to recover from a week on the road)
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to