1. Matt - More ADO/EuCom questions

Matt,

Sorry to keep coming back, but since few EuCom examples exist using ADO,
I don't know where else to turn...

<dramatic scene>
Matt: Jonas, I'm going to recommend you be removed from the program.
Jonas: No, you can't do that!  I aint got nowhere else to go!
Jonas sobs, sitting in the puddle of mud.
</dramatic scene>

My ADO program is working SO FAR and now I'm trying to actually get data
from one of the columns in a record set.  The problem I'm running into 
is trying to retrieve the a Field object from the Fields object.  The 
following code generates the following message when trying to get 
a Field_p_Item property from ado_fields:

80020009: Exception occurred.
Exception Source: ADODB.Fields
Exception Description: Item cannot be found in the collection corresponding to t
he requested name or ordinal.

I noticed that the ordinal for Fields_p_Item property in msado27.ew is 0?

Thanks again for your help!

with trace
without warning

include eucom.ew
include msado27.ew

atom ado_connect, void, conn_str, cmd_str, ado_rcdset, rtn_val, 
	ado_fields, ado_field, ado_variant
sequence text

com_err_out(1)
ado_connect = create_com_object(Connection_clsid_ix)
--ado_rcdset = create_com_object(Recordset_clsid_ix)

-- Event functions for ConnectionEvents
procedure ConnectionEvents_InfoMessage_proc( atom this, atom pError, atom
adStatus, atom pConnection )
	puts(1,"InfoMessage\n")
end procedure
com_event_routine( ado_connect, ConnectionEvents_InfoMessage, 
	routine_id("ConnectionEvents_InfoMessage_proc" ))
	
procedure ConnectionEvents_BeginTransComplete_proc( atom this, atom
TransactionLevel, atom pError, atom adStatus, atom pConnection )
	puts(1,"BeginTransComplete\n")
end procedure
com_event_routine( ado_connect, ConnectionEvents_BeginTransComplete, 
	routine_id("ConnectionEvents_BeginTransComplete_proc" ))
	
procedure ConnectionEvents_CommitTransComplete_proc( atom this, atom pError,
atom adStatus, atom pConnection )
	puts(1,"CommitTransComplete\n")
end procedure
com_event_routine( ado_connect, ConnectionEvents_CommitTransComplete, 
	routine_id("ConnectionEvents_CommitTransComplete_proc" ))
	
procedure ConnectionEvents_RollbackTransComplete_proc( atom this, atom pError,
atom adStatus, atom pConnection )
	puts(1,"RollbackTransComplete\n")
end procedure
com_event_routine( ado_connect, ConnectionEvents_RollbackTransComplete, 
	routine_id("ConnectionEvents_RollbackTransComplete_proc" ))
	
procedure ConnectionEvents_WillExecute_proc( atom this, atom Source, atom
CursorType, atom LockType, atom Options, atom adStatus, atom pCommand, atom
pRecordset, atom pConnection )
	puts(1,"WillExecute\n")
end procedure
com_event_routine( ado_connect, ConnectionEvents_WillExecute, 
	routine_id("ConnectionEvents_WillExecute_proc" ))
	
procedure ConnectionEvents_ExecuteComplete_proc( atom this, atom
RecordsAffected, atom pError, atom adStatus, atom pCommand, atom pRecordset, atom
pConnection
)
	puts(1,"ExecuteComplete\n")
end procedure
com_event_routine( ado_connect, ConnectionEvents_WillConnect, 
	routine_id("ConnectionEvents_ExecuteComplete_proc" ))
	
procedure ConnectionEvents_WillConnect_proc( atom this, atom ConnectionString,
atom UserID, atom Password, atom Options, atom adStatus, atom pConnection
)
	puts(1,"WillConnect\n")
end procedure
com_event_routine( ado_connect, ConnectionEvents_WillConnect, 
	routine_id("ConnectionEvents_WillConnect_proc" ))

procedure ConnectionEvents_ConnectComplete_proc( atom this, atom pError, atom
adStatus, atom pConnection )
	puts(1,"ConnectComplete\n")
end procedure
com_event_routine( ado_connect, ConnectionEvents_ConnectComplete, 
	routine_id("ConnectionEvents_ConnectComplete_proc" ))
	
procedure ConnectionEvents_Disconnect_proc( atom this, atom adStatus, atom
pConnection )
puts(1,"Disconnect\n")
end procedure
com_event_routine( ado_connect, ConnectionEvents_Disconnect, 
	routine_id("ConnectionEvents_Disconnect_proc" ))

-- Start of real code

conn_str = alloc_bstr("Provider=IBMDA400;Data Source=66.140.221.246")

-- This connect approach works
--void = invoke( ado_connect, {Connection_p_ConnectionString}, {conn_str},
{VT_BSTR}, DISPATCH_PROPERTYPUT )
--void = invoke(ado_connect, {"Open"},{},{},DISPATCH_METHOD)
-- So does this one
void = invoke(ado_connect,
{Connection_m_Open},{conn_str},{VT_BSTR},DISPATCH_METHOD)

-- Print the connected state, should be a 1
? invoke(ado_connect, {"State"}, {},{}, DISPATCH_PROPERTYGET )

void = wait_key()

-- Now try just executing a command
cmd_str = alloc_bstr("{CALL QSYS.QCMDEXC('SNDMSG MSG(''TEST FROM ADO'')
TOUSR(JONAS)',0000000040.00000)}")
void = invoke(ado_connect, 
{Connection_m_Execute},{cmd_str},{VT_BSTR},DISPATCH_METHOD)
free(cmd_str)

-- Now we'll try retrieving some records
cmd_str = alloc_bstr("select * from qgpl.qauoopt")
rtn_val = invoke(ado_connect,
{Connection_m_Execute},{cmd_str},{VT_BSTR},DISPATCH_METHOD)
ado_rcdset = ref_com_object(Recordset_clsid_ix,rtn_val)
? invoke(ado_rcdset,{Recordset_p_RecordCount},{},{},DISPATCH_PROPERTYGET )

-- Maybe print the first record?
rtn_val = invoke(ado_rcdset,{Recordset_p_Fields},{},{},DISPATCH_PROPERTYGET )
ado_fields = ref_com_object(Fields_clsid_ix,rtn_val)
trace(1)
? invoke(ado_fields,{Fields_p_Count},{},{},DISPATCH_PROPERTYGET )
rtn_val =
invoke(ado_fields,{Fields_p_Item},{0},{VT_VARIANT},DISPATCH_PROPERTYGET )
ado_field = ref_com_object(Field_clsid_ix,rtn_val)
rtn_val = invoke(ado_fields,{Field_p_Value},{},{},DISPATCH_PROPERTYGET )
text = get_variant(rtn_val)
? text
void = invoke(ado_rcdset, {Recordset_m_Close},{},{},DISPATCH_METHOD)
free(cmd_str)

-- close the connection
void = invoke(ado_connect, {Connection_m_Close},{},{},DISPATCH_METHOD)
free(conn_str)

void = wait_key()
release_com()



Jonas Temple
http://www.yhti.net/~jktemple

new topic     » topic index » view message » categorize

2. Re: Matt - More ADO/EuCom questions

Jonas Temple wrote:
> 
> My ADO program is working SO FAR and now I'm trying to actually get data
> from one of the columns in a record set.  The problem I'm running into 
> is trying to retrieve the a Field object from the Fields object.  The 
> following code generates the following message when trying to get 
> a Field_p_Item property from ado_fields:

Try changing:
rtn_val =
invoke(ado_fields,{Fields_p_Item},{0},{VT_VARIANT},DISPATCH_PROPERTYGET )
-- to
rtn_val = invoke(ado_fields,{Fields_p_Item},{0},{VT_I4},DISPATCH_PROPERTYGET )
-- or
rtn_val = invoke(ado_fields,{"Item"},{0},{VT_I4},DISPATCH_PROPERTYGET )


I think your problem may be that you're not really passing a variant.
When you pass a variant, you really need to have it allocated already
(make_variant).  You're just passing an integer.

If that's not the problem, try the second suggestion.  Then invoke() will 
call GetDispId.  If this works, trace through to that call and get the 
correct Id.  I don't know why that would be wrong.

If that doesn't work, then you ARE kicked off.  :P

Matt Lewis

new topic     » goto parent     » topic index » view message » categorize

3. Re: Matt - More ADO/EuCom questions

Matt Lewis wrote:
> 
> Try changing:
> }}}
<eucode>
> rtn_val =
> invoke(ado_fields,{Fields_p_Item},{0},{VT_VARIANT},DISPATCH_PROPERTYGET )
> -- to
> rtn_val = invoke(ado_fields,{Fields_p_Item},{0},{VT_I4},DISPATCH_PROPERTYGET )
> -- or
> rtn_val = invoke(ado_fields,{"Item"},{0},{VT_I4},DISPATCH_PROPERTYGET )
> </eucode>
{{{


Both suggestions worked.  I think I used VT_VARIANT because that's what
was in msado27.ew.  

> 
> If that doesn't work, then you ARE kicked off.  :P
> 

Whew!  That was close...  :/

Now how about this...if I run the following code snippet with trace then 
rtn_val for the second field is returned as an atom.  Without trace it's
returned as
a sequence.  Hence the need to test and peek_string.  Oddly enough, both
work!

-- Maybe print the first record?
rtn_val = invoke(ado_rcdset,{Recordset_p_Fields},{},{},DISPATCH_PROPERTYGET )
ado_fields = ref_com_object(Fields_clsid_ix,rtn_val)
? invoke(ado_fields,{Fields_p_Count},{},{},DISPATCH_PROPERTYGET )

--rtn_val =
invoke(ado_fields,{Fields_p_Item},{0},{VT_VARIANT},DISPATCH_PROPERTYGET )
rtn_val = invoke(ado_fields,{Fields_p_Item},{0},{VT_I4},DISPATCH_PROPERTYGET )
--rtn_val = invoke(ado_fields,{"Item"},{0},{VT_I4},DISPATCH_PROPERTYGET )
ado_field = ref_com_object(Field_clsid_ix,rtn_val)
rtn_val = invoke(ado_field,{"Value"},{},{},DISPATCH_PROPERTYGET )
text = peek_bstr(rtn_val)
puts(1, text & "\t")

rtn_val = invoke(ado_fields,{Fields_p_Item},{1},{VT_I4},DISPATCH_PROPERTYGET )
--rtn_val = invoke(ado_fields,{"Item"},{0},{VT_I4},DISPATCH_PROPERTYGET )
ado_field = ref_com_object(Field_clsid_ix,rtn_val)
rtn_val = invoke(ado_field,{"Value"},{},{},DISPATCH_PROPERTYGET )
if atom(rtn_val) then
	text = peek_bstr(rtn_val)
else
	text = rtn_val
end if
puts(1, text & "\n")


Jonas Temple
http://www.yhti.net/~jktemple

new topic     » goto parent     » topic index » view message » categorize

4. Re: Matt - More ADO/EuCom questions

Jonas Temple wrote:
> 
> Now how about this...if I run the following code snippet with trace then 
> rtn_val for the second field is returned as an atom.  Without trace it's 
> returned as a sequence.  Hence the need to test and peek_string.  Oddly 
> enough, both work!

That's really odd, and I can't imagine why that happens.  There's a global
variable called return_true_variant.  If it's 0, then invoke() will try
to convert the variant (pointer) to a real value via get_variant().

What happens at the end of invoke?  The only thing I can think of is that
for some reason, the variant was set up as a VT_I4 rather than a 
VT_BSTR (even though it's really a pointer to the string).  If that's
what's going on, then it sounds like something happening on the ADO side
of things.  Either way, I have no clue why tracing would make any 
difference.

Matt Lewis

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu