FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Nesting in ADS 10.1
Posts: 117
Joined: Tue Jan 03, 2006 06:18 PM
Nesting in ADS 10.1
Posted: Fri Feb 17, 2012 05:39 AM
Dear All,

I need help.
which way is better when we save the data on advantage database server 10.1.0.028
Code (fw): Select all Collapse
// ads without nesting
function save()
    use x new share .....
    use y new share .....
    use z new share .....

    Try
        AdsBeginTransaction()
        select x
        if rlock()
            replace  field1 with 'abc'
        endif   
            
        replace_y() 
        
        select z
        if rlock()
            replace field with 'fff'
        endif   
        AdsCommitTransaction()

    catch
        AdsRollback()
    end

    dbcommitall()
        
return nil

    
        
static function replace_y()     
    local colddbf :=select()
    
    select y
    if rlock()
        replace field1 with '123'
    endif

    dbselectarea(colddbf)
return nil



second way

Code (fw): Select all Collapse
// second way using nesting

function save()
    use x new share .....
    use y new share .....
    use z new share .....

    Try
        AdsBeginTransaction()
            try 
                AdsBeginTransaction()
                select x
                if rlock()
                    replace  field1 with 'abc'
                endif   
                AdsCommitTransaction()
            catch
                AdsRollback()
            end
    
            try 
                AdsBeginTransaction()
                replace_y() 
                AdsCommitTransaction()
            catch
                AdsRollback()
            end 

            try
                AdsBeginTransaction()
                select z
                if rlock()
                    replace field with 'fff'
                endif   
                AdsCommitTransaction()
            catch
                AdsRollback()
            end
    
        AdsCommitTransaction()

    catch
        AdsRollback()
    end
    dbcommitall()
    
return nil  
        
        
static function replace_y()     
    local colddbf :=select()
    
    select y
    if rlock()
        replace field1 with '123'
    endif

    dbselectarea(colddbf)
return nil


third

Code (fw): Select all Collapse
// third way using nesting

function save()
    use x new share .....
    use y new share .....
    use z new share .....

    Try
        AdsBeginTransaction()
            try 
                AdsBeginTransaction()
                select x
                if rlock()
                    replace  field1 with 'abc'
                endif   
                AdsCommitTransaction()
            catch
                AdsRollback()   
            end

        
            replace_y() 

            try
                AdsBeginTransaction()
                select z
                if rlock()
                    replace field with 'fff'
                endif   
                AdsCommitTransaction()
            catch
                AdsRollback()
            end
    
        AdsCommitTransaction()
    catch
        AdsRollback()
    end
    dbcommitall()
    
return nil  
        
        
        
static function replace_y()     
    local colddbf :=select()
    
    try
        AdsBeginTransaction()
        select y
        if rlock()
            replace field1 with '123'
        endif
        AdsCommitTransaction()
    catch
        AdsRollback()
    end 

    dbselectarea(colddbf)
return nil



thanks
kok
Posts: 811
Joined: Tue May 06, 2008 04:28 AM
Re: Nesting in ADS 10.1
Posted: Sat Feb 18, 2012 12:21 AM

Dear Kok,

I strongly suggest you use SQL MERGE to save data.. INSERT or UPDATE also fine.
Please refer to ADS documentation for the SQL syntax..

Kind Regards,

Frances



Fivewin for xHarbour v18.07

xHarbour v1.2.3.x

BCC 7.3 + PellesC8 ( Resource Compiler only)

ADS 10.1 / MariaDB

Crystal Reports 8.5/9.23 DE

xMate v1.15
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: Nesting in ADS 10.1
Posted: Sat Feb 18, 2012 04:36 AM

hi, i think what catch code is never used, no runtime error for user the error code. :-(

rlock o flock not trigger RTE Error.

salu2
carlos vargas

Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)
Posts: 117
Joined: Tue Jan 03, 2006 06:18 PM
Re: Nesting in ADS 10.1
Posted: Sat Feb 18, 2012 07:01 AM

HI,

Thanks Fraxzi, I will try it.

Carlos, rlock or flock alway return true or false, so in my code I write :

if rlock()
replace xxxx with yyy
else
break
endif

so, when one of database fail, all database will rollback, and it run perfect in my code.

thank

Kok

Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: Nesting in ADS 10.1
Posted: Sun Feb 19, 2012 01:34 AM

sorry, i dont see the break instruction.

salu2
carlos vargas

:-)

Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)
Posts: 117
Joined: Tue Jan 03, 2006 06:18 PM
Re: Nesting in ADS 10.1
Posted: Sun Feb 19, 2012 08:42 AM

Hi Carlos,

yes, I don't write in sample, sorry.

Did you ever try to compare speeds ads using sql with normal way?

thanks

regards,

kok

Continue the discussion