Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 06-26-2014, 07:22 AM
ShaunVW ShaunVW is offline
Member
 
Join Date: Feb 2012
Posts: 47
Default How to use getrows function

Hello everyone
Can someone please assist me with the correct usage of the 'getrows' function for TADOQuery?
It involves the use of variants, and most of the info I find is for VB.

Code:
var
 query : String;
 TQuery : TADOQuery;
 V: OleVariant;
begin
 CoInitialize(nil); 
 query := 'SELECT * FROM pdc_production.tooling_detail';
 TQuery := TADOQuery.Create(nil);
 TQuery.ConnectionString := 'FILE NAME=MySQLMaster.udl';
 TQuery.SQL.Clear;
 TQuery.SQL.Add(query);
 V := TQuery.Recordset.GetRows(-1, 0, VarArrayOf(['tool_no','tool_name']);
This is the code I have so far. Instead of using a loop to iterate through the result set, I am instead wanting to retrieve the full result set in one shot, load it into an array, and then instead iterate through the array. The reason is that it is quite a large result set, and I want to then load this result set into combo-boxes. The current way I do it right now is through iteration of the result set, I want to optimise it. (Also, now that I have come across this 'getrows' function, I'd like to get it figured out if it can improve retrieval time)
Reply With Quote
  #2  
Old 06-26-2014, 07:30 AM
kolbasz kolbasz is offline
Senior Member
 
Join Date: Nov 2013
Posts: 840
Default

Hi ShaunVW,

Take a look at this:

http://stackoverflow.com/questions/8...019573#8019573

regards
Reply With Quote
  #3  
Old 06-26-2014, 08:11 AM
ShaunVW ShaunVW is offline
Member
 
Join Date: Feb 2012
Posts: 47
Default

I have seen that thread and is how I got to the point where I am now.
However, I need to do more than one field (as in my code).
I am getting an access violation on the line

Code:
V := TQuery.Recordset.GetRows(-1, 0, VarArrayOf(['tool_no','tool_name']));
Quote:
...exe raised exception class EAccessViolation with message 'Access violation at address 006C71A6 in module...... Read of address 00000000'
Reply With Quote
  #4  
Old 06-26-2014, 12:32 PM
kolbasz kolbasz is offline
Senior Member
 
Join Date: Nov 2013
Posts: 840
Default

I don't have ADO component installed, so I cannot test your code. However judging by the access violation,
your program it is trying to read memory at address 00000000, that means accessing some pointer/reference
to an object that is nil.
Reply With Quote
  #5  
Old 06-26-2014, 01:25 PM
ShaunVW ShaunVW is offline
Member
 
Join Date: Feb 2012
Posts: 47
Default

Yes, I think so. It is (I believe) something to do with the variant array, how I initialised it, wrote to it, or something, except I don't know how to fix it!
Reply With Quote
  #6  
Old 06-26-2014, 03:02 PM
major major is offline
Senior Member
 
Join Date: Jun 2011
Posts: 150
Default

I'm reading on how to use GetRows here, and it explains that the 2nd parameter of GetRows should be:

"A String value or Variant that evaluates to the bookmark for the record from which the GetRows operation should begin."

You are passing in 0, which is neither a string nor variant so the assignment to V is possibly never happening, leading to an access violation when accessing V. The answer at SO that kolbasz linked to shows "EmptyParam" being passed in for the 2nd parameter. If you need to start at a specific location in your dataset, then you're going to have to create a bookmark.
Reply With Quote
  #7  
Old 06-26-2014, 04:24 PM
ShaunVW ShaunVW is offline
Member
 
Join Date: Feb 2012
Posts: 47
Default

I'm not sure what bookmarks are. I will look them up tomorrow.
I did try the EmptyParam parameter, I can't remember the error I got.
I will try again tomorrow at work, and feedback.
Thanks for the help so far.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 10:05 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2018, vBulletin Solutions, Inc.