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

An alternative method for describing columns

Previous pageReturn to chapter overviewNext page

So far, we have been using the database cataloguing features of a DBConnection to obtain the descriptions of various columns for use with the #paramCols: message when configuring the parameter slots. It is also possible to do this in a simpler way, providing you don't mind executing a SELECT statement to obtain the array of DBColAttr specifications. Using the previous example of inserting a row into the Suppliers table, let us see how this might be done:

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

ps paramCols: (c query: 'select CompanyName, HomePage from Suppliers) describeCols.

 

As you can see, this is somewhat more straightforward than the previous method, especially in cases where you are describing the columns for a prepared statement which requires many parameters.