Ask a Question related to Coldfusion - Getting Started, Design and Development.

  1. #1

    Default rollback or commit?

    I have the index.cfm page that contain the delete and insert statement. Every
    time I run this page, It's delete all the old records and insert the new
    records in to the database. My code is working fine, howver, I just noticed
    that what happend if my insert statement is faild and the delete stament is
    work then I lost all the records. Is there the way to do the rollback or
    commit the records back again?
    thanks
    ==============

    <cfquery name="getlog" datasource="#db#">
    select u_user, aff
    from log
    where u_user <> ''
    </cfquery>
    <cfoutput>
    <cfquery name="del" datasource="#db#">
    delete from test
    </cfquery>
    <cfloop query="getlog">
    <cfquery name="insert" datasource="#db#">
    insert into test(u_user, aff)
    values('#u_user#', '#aff#')
    </cfquery>
    </cfloop>
    </cfoutput>

    kt03 Guest

  2. Similar Questions and Discussions

    1. database commit
      When is a database insert committed? Immediately or is it committed at the end of a transaction, and if so, what are transaction end points? Terry...
    2. Commit ... Rollback in Access
      Hi All I know I keep going on about this, but could somebody post the routine to do commit .. rollback ASP transactions with an Access DB. I...
    3. Commit on closing connection?
      Hi there, using a Java program on OS390 and DB2 version 7, we have the following problem: After creating a connection using...
    4. Commit Control
      My company is porting some software that we have running on Oracle and DB2 to SQL Server. For our big batch programs(Microfocus COBOL) we have a...
    5. Commit inner transaction rollback outer
      If you nest transaction you are stuck with this, but have you considered using savepoints (SAVE TRANSACTION)? Kresimir Radosevic,SQL MVP ...
  3. #2

    Default Re: rollback or commit?

    Wrap your queries in a <cftransaction>

    <cftransaction>
    <cfquery name="del" datasource="#db#">
    delete from test
    </cfquery>
    <cfloop query="getlog">
    <cfquery name="insert" datasource="#db#">
    insert into test(u_user, aff)
    values('#u_user#', '#aff#')
    </cfquery>
    </cfloop>
    </cftransaction>

    [url]http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/tags-c15.htm#wp1104164[/url]

    Kronin555 Guest

  4. #3

    Default Re: rollback or commit?

    But how do you do the rollback? what happend if your insert staement fis failed?
    kt03 Guest

  5. #4

    Default Re: rollback or commit?

    In CFMX 6.1, if an error is thrown inside a <cftransaction> block, the
    transaction is rolled back.

    If the end of the <cftransaction> block is reached without an error being
    thrown, the transaction is committed.

    Note that your database has to support transactions for this tag to work
    correctly.

    Read here:

    [url]http://livedocs.macromedia.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/[/url]
    wwhelp.htm?context=ColdFusion_Documentation&file=p art_cfm.htm

    "If you do not specify a value for the action attribute, automatic transaction
    processing proceeds as follows:

    * If the cfquery operations within the transaction block complete without
    an error, the transaction is committed.
    * If a cfquery tag generates an error within a cftransaction block, all
    cfquery operations in the transaction roll back."

    Also, if this is homework, I suggest you take the erroneous <cfoutput> out, as
    it's a total giveaway that the code is copied.

    Kronin555 Guest

  6. #5

    Default Re: rollback or commit?

    I can't open the link?
    thanks
    kt03 Guest

  7. #6

    Default Re: rollback or commit?

    You need Flash installed to view the online CF7 documentation.
    Kronin555 Guest

  8. #7

    Default Re: rollback or commit?

    I was able to view the document at this url:
    [url]http://jsc-web-dev7.jsc.nasa.gov/cfdocs/htmldocs/wwhelp/wwhimpl/js/html/wwhelp.htm[/url]

    kt03 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139