1. edbi throwing error for update query

I am not sure what happened but recently my update query stopped working. Edbi works with select but not update.

Here is my code.

include db.e 
 
integer dbh = open_db("TM") 
sequence sql 
sequence row 
 
sql = "UPDATE STREET SET NAME = '5TH' WHERE ID = 560302;" 
--sql = "select * from STREET WHERE ID = 560302;" 
 
row = edbi:query_rows(sql) 
close_db() 

upon running

ant@anthill:/var/www/cgi$ eui update_test.ex 
 
/usr/share/euphoria/include/std/../../edbi/edbi/edbi.e:483 in function query()  
A machine-level exception occurred during execution of this statement  
 
... called from /usr/share/euphoria/include/std/../../edbi/edbi/edbi.e:566 in function query_rows()   
 
... called from /var/www/cgi/update_test.ex:14  
 
--> See ex.err  
 

at the end of ex.err it states:

 /var/www/cgi/update_test.ex: 
    dbh = 1 
    sql = {85'U',80'P',68'D',65'A',84'T',69'E',32' ',83'S',84'T',82'R',69'E', 
69'E',84'T',32' ',83'S',69'E',84'T',32' ',78'N',65'A',77'M',69'E',32' ', 
61'=',32' ',39''',53'5',84'T',72'H',39''',32' ',87'W',72'H',69'E',82'R', 
69'E',32' ',73'I',68'D',32' ',61'=',32' ',53'5',54'6',48'0',51'3',48'0', 
50'2',59';'} 
    row = <no value>    
 

When I follow through trace this is what happens:

472:  public function query(sequence sql, sequence data={}, db_handle h = 0) 
473:      sequence m_seq = get_seq(h) 
474:      atom m_q = eumem:malloc()   
475:        
476:      sequence m_q_seq = repeat(0, Q_END)     
477:      m_q_seq[Q_DB] = m_seq 
478:        
479:      object tmp   
480:      if m_seq[T_DLL_H] = NOT_A_DLL then      
481:          tmp = call_func(m_seq[T_DQUERY], { m_seq[T_DB_H], sprintf_sql(sql, data) })        
482:      else         
483==>        tmp = c_func(m_seq[T_DQUERY], { m_seq[T_DB_H], sprintf_sql(sql, data) })           
484:      end if  
 
182:  function sprintf_sql(sequence sql, object values)  
183:      sequence ns 
184:      integer in_fmt, idx, ch 
185: 
186:      if atom(values) or length(values) = 0 then 
187==>        return sql 
188:      end if 

So at line 187 'return sql' the error is thrown.

I KNOW that update statements worked in the recent past. Is this user error, a recent package update, permissions or something else????

Thanks.

new topic     » topic index » view message » categorize

2. Re: edbi throwing error for update query

I found out that it does actually run the update query but IT STILL THROWS AN ERROR. Could this have something to do with no rows being returned from update?

new topic     » goto parent     » topic index » view message » categorize

3. Re: edbi throwing error for update query

Anthill said...

I found out that it does actually run the update query but IT STILL THROWS AN ERROR. Could this have something to do with no rows being returned from update?

Looking at an example (and based on experience from using other DB libraries), you need to use execute() instead of query_rows() for DML queries.

Matt

new topic     » goto parent     » topic index » view message » categorize

4. Re: edbi throwing error for update query

Awesome Matt, edbi:execute(sql) worked!

Thanks.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu