links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
SqueakDBX - Retrieving and processing results
Last updated at 8:23 pm UTC on 26 September 2009

Retrieving results

As we explain in SqueakDBX - Execute any SQL query the method execute of DBXConnection returns a DBXResultSet if it was a select statement and a DBXResult in case the query was an update, delete, insert, create, drop or any other DML query. Or, in case of a multistatement query, it will return a DBXMultiStatementResultSetIterator.

DBXResult: You can ask to it the number of affected rows. This value depends on the type of query:


    | conn result |

result := conn execute: 'delete from materia where nombre = ''TADP'''.

Transcript show: 'They were affected ' , result rowsAffected asString, ' rows';.

result := conn execute: 'update materia set observaciones = ''something'' where codigo = 60'.    

Transcript show: 'They were affected ' , result rowsAffected asString, ' rows';.

DBXResultSet: this class has several useful methods:

Here are some examples:

    | conn result aRow columnDescription columnCount|

result := conn execute: 'SELECT nombre FROM materia'.

columnDescription := result columnDescriptionAt: 1.

columnDescription := result columnDescriptionWithName: 'nombre'.

Transcript show: columnDescription dbxType, columnDescription name, columnDescription size, columnDescription type.

columnCount := result columnCount.

aRow := result nextRow.

DBXMultiStatementResultSetIterator: This is the return object when the query is multistatement.

insert := 'INSERT INTO materia(codigo, nombre, observaciones, id_alumno) VALUES (11, ''Something'', ''Nothing'', 2)'.
select := 'SELECT * FROM alumno'.
iterator := conn executeMultiStatement: (select, '; ', insert).

"the first result must be the one of the select"
sqlResult := iterator next.
self assert: sqlResult class = DBXResultSet.
self shouldnt: [ sqlResult nextRow ] raise: DBXError.
[ aRow := sqlResult nextRow ] doWhileTrue: [ aRow notNil ].
self assert: aRow isNil.

"the second result must be the one of the select"	
dmlResult := iterator next.
self assert: dmlResult class = DBXResult.
self assert: dmlResult rowsAffected = 1.

"There are no more results, so it must be nil"
self assert: iterator next isNil.


Processing results

As you read above, using nextRow or rowsDo you are able to obtain and do something with a row. You have retrieve the results, so now you are able to process it. In order to do this, you may use some of the following classes:

DBXRow: Represents a row of a resultset. It has these useful messages:

DBXColumnDescription: Represents a description of a column. It has these useful messages:

Unit Tests

For more examples, information and usage, you can see the tests we have related with this. These tests are: DBXQueryTest, DBXDescriptionTest, DBXMultiStatementTest and DBXRowTest.