Jochem

this the Max_ID CustomTag code (really simplest):
<!--- required attributes --->
<cfparam name="attributes.datasource">
<cfparam name="attributes.tablename">
<cfparam name="attributes.primarykey">

<cfquery name="getmaxID" datasource="#attributes.datasource#">
select max(#attributes.PrimaryKEY#) as Max_ID
from #attributes.tablename#
</cfquery>

<cfif len(getmaxID.Max_ID)>
<cfset caller.Max_ID = getmaxID.Max_ID + 1>
<cfelse>
<cfset caller.Max_ID = "1">
</cfif>

--------------------------
Barney

why don't use AUTONUMBER? Please see:

This tag is used as a "application side autonumber" In other words, instead of using the
"autonumber" A.K.A. "identity key" as your primary key datatype in your database, you would
use a simple number datatype.

Why the hell would you want to do this?

Because autonumber datatypes are not easily transferable from database to database.  They are also
a pain in the neck to develop with, because once the record has been created that number can never
be used again.  This technique is not 100% necessary for Fusebox applications, but after
you play with autonumbers and try and move data from one database to another you'll thank me.

But my query still very slowwwwww....

Do you have another option to Max_ID????


----- Original Message -----
From: "Barney Boisvert" <[EMAIL PROTECTED]>
Date: Tue, 6 Jan 2004 09:39:34 -0800
To: CF-Talk <[EMAIL PROTECTED]>
Subject: RE: CF_MAX_ID - MySQL slowww

Last time I checked, CF_MAX_ID simply did a SELECT MAX() on the table, and
added one to the result.

If you haven't already, make sure that you have an unique index (key) on the
intNewsID column.  If it's your primary key, then why aren't you using
MySQL's AUTO_INCREMENT column type?  It will automatically handle making
unique primary keys for you.

Create table tblNews (
  intNewsID int unsigned not null auto_increment,
  ...,
  primary key (intNewsID)
);

Cheers,
barneyb

> -----Original Message-----
> From: Jochem van Dieten [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, January 06, 2004 8:21 AM
> To: CF-Talk
> Subject: Re: CF_MAX_ID - MySQL slowww
>
> Spectrum WebDesign said:
> >
> > <!---get MaxID form DB--->
> > <cfloop condition="true">
> > <cftry>
> > <cftransaction>
> > <cf_max_ID
> > datasource="#dsn#"
> > tablename="tblNews"
> > primarykey="intNewsID">
>
> It would help if we had the code for cf_max_id and if you placed some
> timers for the different sections.
>
> Jochem
>
>
>
>
>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to