insert - Inserts into the database.
insert (( [db:pointer,] table:string, snc:bool, user: integer, fields:string);
This function is used to insert values in a table.
This function return an array with the following elements:
Note: In the followings examples, the _ between the { should be removed to make it work.
res={_{ a=sql("drop table IF EXISTS ? ;","sn_test1"); a=sql("create table sn_test1 (uid int NOT NULL , firstname varchar(255), lastname varchar(255), PRIMARY KEY (uid"); a=insert(table:"sn_test1",fields:{firstname:'pierre',lastname:'laplante'}); a.uid; a=select(tables:"sn_test1"); stringnify(sort:true,a.rows); }}. return res=0\[{"firstname":"pierre","lastname":"laplante","uid":"0"}\]. res={_{ a=sql("drop table IF EXISTS ? ;","sn_test1"); a=sql("create table sn_test1 (uid int NOT NULL AUTO_INCREMENT, firstname varchar(255), lastname varchar(255), PRIMARY KEY (uid"); a=insert(table:"sn_test1",fields:{firstname:'pierre',lastname:'laplante'}); a.uid; a=insert(table:"sn_test1",fields:{firstname:'chantal',lastname:'bilodeau'}); a.uid; a=select(tables:"sn_test1"); stringnify(sort:true,a.rows); }}. return res=12\[{"firstname":"pierre","lastname":"laplante","uid":"1"},{"firstname":"chantal","lastname":"bilodeau","uid":"2"}\]. res={_{ a=sql("drop table IF EXISTS ? ;","sn_test1"); a=sql("create table sn_test1 (uid int NOT NULL AUTO_INCREMENT, firstname varchar(255), lastname varchar(255), PRIMARY KEY (uid"); a=insert(table:"sn_test1",fields:{sfirstname:'pierre',lastname:'laplante'}); a.sqlerr; }}. return res=Unknown column 'sfirstname' in 'field list'. res={_{ a=sql("drop table IF EXISTS ? ;","sn_test1"); a=sql("create table sn_test1 (uid int NOT NULL AUTO_INCREMENT, firstname varchar(255), lastname varchar(255), PRIMARY KEY (uid"); b="l'ile"; a=insert(table:"sn_test1",fields:{firstname:b,lastname:b}); a.sqlerr; a=select(tables:"sn_test1"); stringnify(sort:true,a.rows); }}. return res=\[{"firstname":"l'ile","lastname":"l'ile","uid":"1"}\].
Written by Pierre Laplante and Caroline 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