Navigation:  Programming Cookbook > Database Connectivity > Preparing SQL for Later Execution >

Preparation

Previous pageReturn to chapter overviewNext page

Let's prepare a typical insert statement:

ps := c prepare: 'insert into Suppliers (CompanyName, HomePage) values (?, ?)'. "Display it"

 

As you can see, this answers an instance of DBParameterizedStatement. This is very much like a DBStatement, except that it has not yet been executed and it has placeholders for the parameter substitutions it requires before it can be run. However, there is one more thing that we must do before the statement can be considered to be fully prepared. It is necessary to configure it with the information regarding the types and sizes of each of the parameters substitutions. This is done using the #paramCols: message, which takes as its parameter an array of DBColAttr objects, each one describing the missing columns in the statement. The best place to get this information is by querying it from the database catalogue.

pcols := (c columns: 'Suppliers') select: [:col |

       col name='CompanyName' or: [col name='HomePage']].

pcols. "Display it"

ps paramCols: pcols.