• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

CFQUERY always returns the same value

Contributor ,
Jun 11, 2012 Jun 11, 2012

Copy link to clipboard

Copied

<cfquery name="qryGetMAXID" datasource="#Request.DSN#">

        SELECT

            MAX(FLEET_CON_ID)+1 as MaxFleetId

        FROM

            CONFIGURATION

    </cfquery>

    <cfset intFLEET_CON_ID = #qryGetMAXID.MaxFleetId#/>

    <cfquery name="qryAddOperator" datasource="#Request.DSN#" result="testing">

        INSERT INTO

            CONFIGURATION

        (FLEET_CON_ID,

        COL2,

        COL3,

        COL4)

        VALUES

        (#intFLEET_CON_ID#,

        "ADD OPERATOR",

        '#strCode#',

        '#strName#')

    </cfquery>

the Query qryGETMAXID always returns the same value as 18703. I inserted some values into the database directly. the Query should return 18705. When I run the same query in SQL Developer it returns the correct value. I have not cached the query.

Please help me out.

Thanks in advance

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Contributor , Jun 11, 2012 Jun 11, 2012

Dan and Wolfshade,

Thanks for the problem.

I figured out the problem, while I insert into the database, I did not commit it. so it was returning the same value.

sorry..

Votes

Translate

Translate
LEGEND ,
Jun 11, 2012 Jun 11, 2012

Copy link to clipboard

Copied

My suggestion is to let the database determine the value of the id field.  The way to do that depends on what type of database you are using.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 11, 2012 Jun 11, 2012

Copy link to clipboard

Copied

This can happen if the queries are being cached.  If you don't have the "cachedwithin" parameter in your CFQUERY tag, check the CFAdmin to see if queries are being cached, there.

@Dan: Sometimes, rarely, there is a reason for manual incrementing.

^_^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 11, 2012 Jun 11, 2012

Copy link to clipboard

Copied

Dan and Wolfshade,

Thanks for the problem.

I figured out the problem, while I insert into the database, I did not commit it. so it was returning the same value.

sorry..

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jun 11, 2012 Jun 11, 2012

Copy link to clipboard

Copied

LATEST

SELECT  MAX(FLEET_CON_ID)+1 as MaxFleetId

Unless you are using locking, a serializable transaction (not the default), etcetera two threads can still obtain the same "MaxFleetId" value. If that will cause a problem in your application, you should consider letting the database determine the next available id as Dan suggested.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation