update - Update databases.
update(( [db:pointer,] tables:string, wantarray:true|false, count:integer, fields:context, snc:bool, user:integer, join:string, having:string, selectby:string, orderby:string, groupby:string, limit:string, args:string, uid:integer, page:integer, prefix:true|false, countperpage:integer);
This function is used to update elements in tables.
Since the database does not support page, limit, groupby having, join. A select is perform to get the list of uid and than an update is perform on this list. As a consequence, the field uid must be present in the table.
This function return an has array with thw following elements:
.
Note: In the followings examples, the _ between the { should be removed to make it work.
res={_{ update(tables:"sn_test1",selectby:"table_name = '?'",args:["sn_test1"],fields:{"table_name":"sn_test3"}); a=sql("drop table IF EXISTS ? ;","sn_test1"); a=sql("drop table IF EXISTS ? ;","sn_test2"); a=sql("create table sn_test1 (uid int, firstname varchar(255), lastname varchar(255"); a=sql("create table sn_test2 (uid int, uid_sn_test_1 int, firstname varchar(255), lastname varchar(255))"); for(i=1;i<=5;++i) a=sql("insert into sn_test1 values('?', '?', '?');",i, "f" .+ i,"l" .+ i ); for(j=1;j<=5;++j) a=sql("insert into sn_test2 values('?', '?', '?', '?');",i,j,"g" .+ i .+ j,"h" .+ i .+ j); endfor endfor }}. return res=. res={_{ update(); }}. return .*tables must be specify.* res={_{ update(tables:"sn_test1"); }}. return .*fields must be specify.* res={_{ update(tables:"sn_test1",fields:"aaaa",page:5,limit:"abc"); }}. return .*Parameter fields is not a context.* res={_{ a=select(tables:"sn_test1",uid:1); a.rows; a=update(tables:"sn_test1",uid:1,fields:{firstname:"laplante"}); a.error; a=select(tables:"sn_test1",uid:1); a.rows; }}. return res=\[{"uid":"1","lastname":"l1","firstname":"f1"}\]false\[{"uid":"1","lastname":"l1","firstname":"laplante"}\]. res={_{ a=select(tables:"sn_test1"); a.rows; a=update(tables:"sn_test1",page:1,countperpage:2,fields:{firstname:"laplante"}); a.error; a=select(tables:"sn_test1"); a.rows; }}. return res=\[{"uid":"1","lastname":"l1","firstname":"laplante"},{"uid":"2","lastname":"l2","firstname":"f2"},{"uid":"3","lastname":"l3","firstname":"f3"},{"uid":"4","lastname":"l4","firstname":"f4"},{"uid":"5","lastname":"l5","firstname":"f5"}\]false\[{"uid":"1","lastname":"l1","firstname":"laplante"},{"uid":"2","lastname":"l2","firstname":"laplante"},{"uid":"3","lastname":"l3","firstname":"f3"},{"uid":"4","lastname":"l4","firstname":"f4"},{"uid":"5","lastname":"l5","firstname":"f5"}\]. res={_{ a=update(tables:"sn_test1",uid:1,fields:{frstname:"laplante"}); a.error; a.sqlerr; }}.return res=trueUnknown column 'frstname' in 'field list'.
Written by Pierre Laplante, <laplante@sednove.com>
Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin commodo. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis.
1.0 2014-09-09 21:24:14 laplante@sednove.com