| Allegro CL version 9.0 The object described on this page has been modified in the 9.0 release; see the Release Notes. 8.2 version |
Arguments: cols-and-vals &key table db showsql on-dup-key
insert-db is a macro that creates an sql statement to insert a row into a table.
db should be a mysql
object returned
by connect. The value
of *mysql*
is a
suitable value (and the default).
table specifies the table in the database into which the new row will be inserted. There is no meaningful default: you must specify a string naming a table as the value.
If showsql is specified true, the generated sql statement will be printed.
cols-and-vals specifies the columns and values. It looks like a let binding list:
The value of on-dup-key has the same form as cols-and-vals and specifies which columns should be set to which values if the insert tries to insert a row with the same values in key columns as an existing row. Using this argument will save you the trouble of checking if a row exists and then either doing an insert or an update based on what you found.
cl-user(62): (insert-db ((val 20) (sq 400)) :table "square" :showsql t) sql: (format nil "insert into square(val,sq) values(~a,~a)" 20 400) nil cl-user(63):
If you are inserting a string or blob value you should specify a third
value of :text
in the
cols-and-vals list.
cl-user(63): (sql "create table atext(ttt text)") nil cl-user(64): (insert-db ((ttt "foo" :text)) :table "atext") nil
If you do not specify :text
and and the value to be
stored in the column is a string then the string is put in the sql
statement verbatim. This is useful to store the value of mysql
built-in functions.
cl-user(67): (insert-db ((val "now()") (sq "now()*now()")) :table "square") nil cl-user(68):
See mysql.htm for information on the Allegro MySQL facility.
Copyright (c) 1998-2019, Franz Inc. Oakland, CA., USA. All rights reserved.
This page was not revised from the 8.2 page.
Created 2012.5.30.
| Allegro CL version 9.0 The object described on this page has been modified in the 9.0 release; see the Release Notes. 8.2 version |