Nesting in ADS 10.1

Nesting in ADS 10.1

Postby kok joek hoa » Fri Feb 17, 2012 5: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: Select all  Expand view

// 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: Select all  Expand view

// 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: Select all  Expand view


// 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
kok joek hoa
 
Posts: 117
Joined: Tue Jan 03, 2006 6:18 pm

Re: Nesting in ADS 10.1

Postby fraxzi » 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
User avatar
fraxzi
 
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines

Re: Nesting in ADS 10.1

Postby carlos vargas » Sat Feb 18, 2012 4: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)
User avatar
carlos vargas
 
Posts: 1707
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: Nesting in ADS 10.1

Postby kok joek hoa » Sat Feb 18, 2012 7: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
kok joek hoa
 
Posts: 117
Joined: Tue Jan 03, 2006 6:18 pm

Re: Nesting in ADS 10.1

Postby carlos vargas » Sun Feb 19, 2012 1:34 am

sorry, i dont see the break instruction.
:-)


salu2
carlos vargas
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1707
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: Nesting in ADS 10.1

Postby kok joek hoa » Sun Feb 19, 2012 8: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
kok joek hoa
 
Posts: 117
Joined: Tue Jan 03, 2006 6:18 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 48 guests