Re: Is there a better way to prepare an Insert?
Posted in 1998
Daniel Wright wrote: > > Unless I'm missing something, you have to include a question mark for > every field in the table > (e.g. "INSERT INTO <table_name> VALUES (?, ?, ?, ?, ?)" in order to put > the SQL statement into a string in order > to prepare it.). > > I would like to avoid this...the big reason for wanting to avoid this is > that, if we add (or drop one) a column to the table, the > program with this PREPARE will be broken. (The other, related reason, > is that it is a pain to have to make the number of > question marks equal to the number of fields.). Why don't you use the syntax: INSERT INTO <table_name>(<col_name1>, <col_name2>, <col_name3>) VALUES (?, ?, ?) ? In vi just count the fields and say <N>i?, <ESC> where <N> is the number of fields. Cheers, -- Mark. +----------------------------------------------------------+-----------+ |Mark D. Stock - Informix SA http://www.informix.com |//////// /| |mailto:mdstock@informix.com FAQ http://www.iiug.org |///// / //| | +-----------------------------------+//// / ///| | Tel: +27 11 807 0313 |If it's slow, the users complain. |/// / ////| | Fax: +27 11 807 2594 |If it's fast, the users keep quiet.|// / /////| |Cell: +27 83 250 2325 |Therefore, "No news: travels fast"!|/ ////////| +----------------------+-----------------------------------+-----------+