Results 1 to 4 of 4

Thread: lock row

  1. #1
    Join Date
    Dec 2002
    Location
    Madrid - Spain
    Posts
    422
    Provided Answers: 1

    Wink Unanswered: lock row

    Hi.

    I am using INFORMIX-IDS 7.31 and need working whit transaction but I how can lock a row, the program when to do a cursor for update show me the followind error.



    Date: 10/16/2003 Time: 13:58:19
    Program error at "pfgrafoc.4gl", line number 63.
    SQL statement error number -255.
    Not in transaction.
    Date: 10/16/2003 Time: 15:33:28
    Program error at "pfgrafoc.4gl", line number 68.
    SQL statement error number -290.
    Cursor not declared with FOR UPDATE clause.
    Date: 10/16/2003 Time: 15:35:24
    Program error at "pfgrafoc.4gl", line number 464.
    SQL statement error number -400.
    Fetch attempted on unopen cursor.

  2. #2
    Join Date
    Sep 2003
    Posts
    22
    hello,

    use this syntax to lock the table.

    lock table table_name in exclusive mode;

    Also, when you prepare a statement or declare a cursor use FOR UPDATE clause at the end. This will lock the row automatically.

    Additionally, no error checking is done in your program, check sql error code at every level. sqlca.sqlcode should be zero ( this indicates correct execution)

    -PD

  3. #3
    Join Date
    Dec 2002
    Location
    Madrid - Spain
    Posts
    422
    Provided Answers: 1
    Hi.


    Thank you for you answer, but i need lock a row in my program when i find a record.

    Thank you.

  4. #4
    Join Date
    Dec 2002
    Location
    Madrid - Spain
    Posts
    422
    Provided Answers: 1
    send a fucntion where a find a number of docuemnt.

    function incrementa_contador(centro,cod_cont,valor_inicio)

    define
    centro like ffcontad.cen_con,
    cod_cont like ffcontad.cod_con,
    valor_inicio like ffcontad.con_con

    let p_contador.cod_con = cod_cont


    if in_transacciones = 1 and not enable_trans then
    begin work
    let enable_trans = true
    end if

    set lock mode to wait

    let p_contador.con_con = null

    if p_contador.emp_con is null then
    let p_contador.emp_con = p_empresa.cod_emp
    end if
    let p_contador.cen_con = centro

    declare inc_count cursor for
    select * from ffcontad
    where
    emp_con = p_contador.emp_con and
    cen_con = p_contador.cen_con and
    cod_con = p_contador.cod_con and
    any_con = year(fecha_hoy)
    for update

    foreach inc_count into p_contador.*
    update ffcontad
    set con_con = con_con + 1
    where
    current of inc_count
    end foreach

    let p_contador.any_con = year(fecha_hoy)

    if p_contador.con_con is null then
    if p_contador.cod_con = "ngra" then
    select max(con_con) into valor_inicio
    from ffcontad
    where
    cod_con = "ngra" and
    any_con = p_contador.any_con
    if valor_inicio is null then
    let valor_inicio = 10000
    end if
    let valor_inicio = valor_inicio + 100000
    end if
    let valor_inicio = valor_inicio + 1
    insert into ffcontad
    values
    (p_contador.emp_con,
    p_contador.any_con,
    p_contador.cod_con,
    p_contador.cen_con,
    p_contador.des_con,
    valor_inicio)
    let p_contador.con_con = valor_inicio -
    end if


    return(p_contador.con_con)

    end function

Posting Permissions

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