ADO+D5 first try

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

ADO+D5 first try

Costas
Hi,

The ADO code below works. However the only questionmark is the getFld
and setFld block, which allows access to  field names' values in the
recordset. I could not find a method in the recordset that accesses a
field so I made my own (I could have added my own methods to
ADODB_Recordet). I guess I am surprised that these very important
field access methods are missing. Any comments are appreciated.

Costas

"***  Connect to table"
con:=ADODB_Connection new connectionString: 'testdbf'; open; yourself.
"***  Open recordset"
rs:=(ADODB_Recordset new) open:  'select * from test'
  activeConnection: con
  cursorType: (ADODBConstants at: #adOpenDynamic )
  lockType: (ADODBConstants at: #adLockOptimistic )
  options: (ADODBConstants at: #adCmdUnspecified);
  yourself.
"***  Get field value code block"
getFld:=[:fldName |   (rs fields detect: [:fld | fld name = fldName])
value].
getFld value: 'name'.
"*** Set field value code block"
setFld:=[:fldName :fldValue |  (rs fields detect: [:fld | fld name =
fldName]) value: fldValue].
setFld value: 'name' value: 'austin'.
"*** Update record"
rs update.
rs Close.
con close.


Reply | Threaded
Open this post in threaded view
|

Re: ADO+D5 first try

Blair McGlashan
"Costas" <[hidden email]> wrote in message
news:[hidden email]...
> Hi,
>
> The ADO code below works. However the only questionmark is the getFld
> and setFld block, which allows access to  field names' values in the
> recordset. I could not find a method in the recordset that accesses a
> field so I made my own (I could have added my own methods to
> ADODB_Recordet). I guess I am surprised that these very important
> field access methods are missing. Any comments are appreciated.

The fields collection of the recordset is exposed as a type of
SequenceableCollection which means that the fields are accessed by column
index, which is much the most efficient way. You can however access the
underlying ADODBFields object from it by using the public #interface acessor
and then use its #item: method to access the columns by name, for example
using the Northwind sample database:

r := ADODB_Recordset new.
r open: 'select * from products' activeConnection: 'DSN=NWind'.
r fields interface item: 'ProductName'.

I take your point, however, that there should be a way to access the fields
by name (without having to break Demeter's law), and so we'll add a #item:
method to ADOCollection as an enhancement in the first patch level, rather
along the lines of the attached.

Regards

Blair
-------------------

!ADOCollection methodsFor!

item: keyObject
 "Access the element of the receiver with the specified key.
 The permissible types and values for the key will depend on the
 underlying type of the collection - for example in the case of
 an ADO Fields collection the key can be either an integer column
 number or a string column name."

 ^interface item: keyObject! !
!ADOCollection categoriesFor: #item:!accessing!public! !

!ADOCollection methodsFor!

at: index
 "Answer the element of the receiver at the specified index. If the index
 is out of bounds, raise an exception.
 Implementation Note: Assume the underlying collection uses zero based
indices."

 ^self item: index - 1! !
!ADOCollection categoriesFor: #at:!accessing!public! !


Reply | Threaded
Open this post in threaded view
|

Re: ADO+D5 first try

Costas Menico
<....>
>I take your point, however, that there should be a way to access the fields
>by name (without having to break Demeter's law), and so we'll add a #item:
>method to ADOCollection as an enhancement in the first patch level, rather
>along the lines of the attached.
>

Blair,

In addition to #item:, don't forget #item:value: or something like
that to set the value of the field.

Suggestion: Why not use the #field instead of #item (since you already
have #fields) and add it to ADODB_Recordset

E.g.

amt := rs field: 'AMOUNT'.
rs field: ' AMOUNT' value: amt.
rs update


Regards,

Costas